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 game_loop(): state = hangman.start_game() while not state.is_finished: print_state(state) guess = prompt_for_guess() state = hangman.take_turn(state, guess) print_was_guess_correct(state) return state
def test_guess_cannot_be_empty_string(self): with self.assertRaises(ValueError): hangman.take_turn(hangman.start_game(), "")
def setUp(self): self.result = hangman.start_game()
def test_guess_cannot_be_multiple_characters(self): with self.assertRaises(ValueError): hangman.take_turn(hangman.start_game(), "hi")
def test_guess_cannot_be_none(self): with self.assertRaises(ValueError): hangman.take_turn(hangman.start_game(), None)
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 start_game(): state = hangman.start_game() dict_state = _prepare_game_state(state) return jsonify(dict_state)