stage.set_background("underwater")
score = 0
score_board = codesters.Display(score)
weak_pws = ["password", "password123", "123456", "hello1", "snuffles", "emma2003"]
strong_pws = ["GgbvTa581!@", "@Mjrc0olguy!", "007jmSB0nd!", "108turt!es762", "Avv3SoMe!305"]
all_pws = strong_pws + weak_pws
password = codesters.Text("password", 100, 200, "red")
def interval():
rand_x = random.randint(-225, 225)
rand_y = random.randint(-225, 225)
rand_pw = random.choice(all_pws)
password.set_text(rand_pw)
password.go_to(rand_x, rand_y)
stage.event_interval(interval, 3)
def click(sprite):
global score
pw_text = password.get_text()
if pw_text in weak_pws:
score -= 1
score_board.update(score)
if pw_text in strong_pws:
score += 1
score_board.update(score)
password.event_click(click)
t = codesters.Teacher()
randoms= t.find_function('randint')
ran_choice = t.find_function('choice')
texts = t.find_function('set_text')
gotos = t.find_function('go_to')
try:
tval1 = randoms[2][1]
tval2 = t.get_indent_at_line(randoms[2][0])
tval2a = randoms[2][0]
except:
tval1 = "DNE"
tval2 = "DNE"
tval2a = "DNE"
try:
tval3 = randoms[3][1]
tval4 = t.get_indent_at_line(randoms[3][0])
tval4a = randoms[3][0]
except:
tval3 = "DNE"
tval4 = "DNE"
tval4a = "DNE"
t1 = TestObjective()
t1.add_success(tval2 == 4 and tval4 == 4 and (('rand_x' in tval1 and 'rand_y' in tval3) or ('rand_y' in tval1 and 'rand_x' in tval3)), "Great job!")
t1.add_failure(tval1== "DNE" or tval3 == "DNE", "Did you copy both random integer commands?")
t1.add_failure((('rand_x' not in tval1 and 'rand_x' not in tval3) and ('rand_y' not in tval1 and 'rand_y' in tval3)), "Did you copy a rand_x and a rand_y command from your Interval Event?")
t1.add_failure(tval2 < 4 or tval4 < 4, "Make sure your rand_x and rand_y variables are indented 4 spaces inside your Click Event.")
t1.add_failure(tval2>4 or tval4 > 4, "Make sure your Random Integer commands are outside your if statment, but but 4 spaces inside your Click Event.")
try:
tval5 = ran_choice[1][1]
tval6 = t.get_indent_at_line(ran_choice[1][0])
tval6a = ran_choice[1][0]
except:
tval5 = "DNE"
tval6 = "DNE"
tval6a = "DNE"
t2 = TestObjective()
t2.add_success('rand_pw' in tval5 and '(all_pws)' in tval5 and tval6 == 4, "Great job!")
t2.add_failure(tval5 == "DNE", "Did you copy the Random Choice command?")
t2.add_failure('rand_pw' not in tval5 or '(all_pws)' not in tval5, "Make sure you copied the whole Random choice command from your Interval Event.")
t2.add_failure(tval6 < 4, "Make sure your Random Choice command is indented 4 spaces inside your Click event.")
t2.add_failure(tval6 > 4, "Make sure your Random Choice command is outside your if statment, but 4 spaces inside your Click Event.")
try:
tval7 = texts[1][1]
tval8 = t.get_indent_at_line(texts[1][0])
tval8a = texts[1][0]
except:
tval7 = "DNE"
tval8 = "DNE"
tval8a = "DNE"
t3 = TestObjective()
t3.add_success('password.set_text(rand_pw)' in tval7 and tval8 == 4, "Great job!")
t3.add_failure(tval7 == "DNE", "Did you copy your Set Text command?")
t3.add_failure('password.set_text(rand_pw)' not in tval7, "Make sure you copy your Set Text command from the interval event exactly.")
t3.add_failure(tval8 < 4, "Make sure your Set Text command is indented 4 spaces inside your Click event.")
t3.add_failure(tval8 > 4, "Make sure your Set Text command is outside your if statment, but 4 spaces inside your Click Event.")
try:
tval9 = gotos[1][1]
tval10 = t.get_indent_at_line(gotos[1][0])
tval10a = gotos[1][0]
except:
tval9 = "DNE"
tval10 = "DNE"
tval10a = "DNE"
t4 = TestObjective()
t4.add_success(tval9 == 'password.go_to(rand_x, rand_y)' and tval10 == 4, "Great job!")
t4.add_failure(tval9 == "DNE", "Did you copy your Go To command?")
t4.add_failure('password.go_to(rand_x, rand_y)' not in tval9, "Make sure you copy your Set Text command from the interval event exactly.")
t4.add_failure(tval10 < 4, "Make sure your Go To command is indented 4 spaces inside your Click event.")
t4.add_failure(tval10 > 4, "Make sure your Go To command is outside your if statment, but 4 spaces inside your Click Event.")
try:
tval11a = t.get_indent_at_line(t.find_function('event_click')[0][0])
tval11 = t.find_function('event_click')[0][0]
except:
tval11 = "DNE"
t5 = TestObjective()
t5.add_failure(tval11a >0, "Oops! Make sure you don't indent the last line of the Click Event!")
t5.add_failure(tval11 == "DNE", "Oops! Did you delete the last line of your Click Event?")
t5.add_failure((tval11 < tval10a) or (tval11 < tval8a) or (tval11 < tval6a) or (tval11 < tval4a) or (tval11 < tval2a), "Make sure the last line of your event is the handler! password.event_click(click)")
tester = TestManager()
tester.add_test_list([t1, t2, t3, t4, t5])
tester.run_tests()
tester.display_first_feedback()