def main(): game_word = word_chooser() game = Game(game_word) player = Player() option = 'y' while option != 'n': while not player.is_dead() and not game.won(): # Next line found at https://stackoverflow.com/questions/2084508/clear-terminal-in-python os.system('cls' if os.name == 'nt' else 'clear') print_logo() print("Tried words:") print(", ".join(game.tried_words)) print("Tried Letters:") print(", ".join(game.tried_letters)) player.display_status() print(f"{game.display}\n") guess = get_guess().strip() if len(guess) == 1: player.guess_letter(game, guess) else: player.guess_word(game, guess) if player.is_dead(): os.system('cls' if os.name == 'nt' else 'clear') print_logo() print("Tried words:") print(", ".join(game.tried_words)) print("Tried Letters:") print(", ".join(game.tried_letters)) player.display_status() print("Game Over!") print(f"The word you were looking for was: {game.solution}") else: os.system('cls' if os.name == 'nt' else 'clear') print_logo() print("Tried words:") print(", ".join(game.tried_words)) print("Tried Letters:") print(", ".join(game.tried_letters)) player.display_status() print(f"{game.display}\n") print("Congratulations! You Won!\n") option = get_option() player.reset() game.reset(word_chooser())
class TestPlayer(unittest.TestCase): def setUp(self): self.player = Player() self.game = Game("primary") def test_state_is_zero(self): self.assertEqual(0, self.player.state) def test_guess_letter(self): self.player.guess_letter(self.game, 'r') self.assertEqual(0, self.player.state) def test_guess_letter_wrong(self): self.player.guess_letter(self.game, 'g') self.assertEqual(1, self.player.state) def test_guess_word(self): self.player.guess_word(self.game, "primary") self.assertEqual(0, self.player.state) def test_guess_word_wrong(self): self.player.guess_word(self.game, "secondary") self.assertEqual(1, self.player.state) def test_is_dead_when_is_not(self): self.assertEqual(False, self.player.is_dead()) def test_is_dead_when_dead(self): for i in range(11): self.player.guess_letter(self.game, 'q') self.assertEqual(True, self.player.is_dead()) def test_reset(self): for i in range(11): self.player.guess_letter(self.game, 'q') self.assertEqual(True, self.player.is_dead()) self.player.reset() self.assertEqual(False, self.player.is_dead()) def test_status_display(self): # Status 0 print("\n") self.player.display_status() self.player.guess_letter(self.game, 'q') # Status 1 self.player.display_status() self.player.guess_letter(self.game, 'q') # Status 2 self.player.display_status() self.player.guess_letter(self.game, 'q') # Status 3 self.player.display_status() self.player.guess_letter(self.game, 'q') # Status 4 self.player.display_status() self.player.guess_letter(self.game, 'q') # Status 5 self.player.display_status() self.player.guess_letter(self.game, 'q') # Status 6 self.player.display_status() self.player.guess_letter(self.game, 'q') # Status 7 self.player.display_status() self.player.guess_letter(self.game, 'q') # Status 8 self.player.display_status() self.player.guess_letter(self.game, 'q') # Status 9 self.player.display_status() self.player.guess_letter(self.game, 'q') # Status 10 self.player.display_status() self.assertEqual(True, True)