Exemple #1
0
 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)
Exemple #2
0
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
Exemple #3
0
 def test_guess_cannot_be_empty_string(self):
     with self.assertRaises(ValueError):
         hangman.take_turn(hangman.start_game(), "")
Exemple #4
0
 def setUp(self):
     self.result = hangman.start_game()
Exemple #5
0
 def test_guess_cannot_be_multiple_characters(self):
     with self.assertRaises(ValueError):
         hangman.take_turn(hangman.start_game(), "hi")
Exemple #6
0
 def test_guess_cannot_be_none(self):
     with self.assertRaises(ValueError):
         hangman.take_turn(hangman.start_game(), None)
Exemple #7
0
 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)
Exemple #8
0
 def test_raises_if_game_not_finished(self):
     with self.assertRaises(ValueError):
         hangman.calculate_score(hangman.start_game())
Exemple #9
0
def start_game():
    state = hangman.start_game()
    dict_state = _prepare_game_state(state)
    return jsonify(dict_state)