def test_when_game_won_score_is_equal_to_lives_left(self): state = hangman.start_game(["printer"]) state.current_known = list(state.target_word) state.is_finished = True for x in range(1, 6): state.lives_left = x result = hangman.calculate_score(state) self.assertEqual(x, result)
def ending(state): if state.has_won: print("Well done!") score = hangman.calculate_score(state) print(f"You scored {score} points!") if update_high_score(score): print("That's a new high score!!") else: print("Sorry, better luck next time.")
def _prepare_game_state(state): dict_state = { "is_finished": state.is_finished, "target_word": state.target_word, "current_known": state.current_known, "lives_left": state.lives_left, "was_last_guess_correct": state.was_last_guess_correct, "has_won": state.has_won, "printable_known": hangman.format_current_known(state.current_known) } if state.is_finished: score = hangman.calculate_score(state) dict_state["score"] = score dict_state["is_new_high_score"] = _update_high_score(score) dict_state["high_score"] = _read_high_score() return dict_state
def test_lost_game_is_zero_points(self): state = hangman.start_game(["printer"]) state.is_finished = True result = hangman.calculate_score(state) self.assertEqual(0, result)
def test_raises_if_game_not_finished(self): with self.assertRaises(ValueError): hangman.calculate_score(hangman.start_game())
def test_raises_on_none(self): with self.assertRaises(ValueError): hangman.calculate_score(None)