class RockPaperTest(unittest.TestCase): def setUp(self): self.player1 = Player("Rocky", "Rock") self.player2 = Player("Snippy", "Scissors") self.player3 = Player("Marty", "Rock") self.player4 = Player("Ben", "Potato") self.game = RockPaper(self.player1, self.player2) def test_game_exists(self): self.assertEqual("Rocky", self.game.player_1.name) def test_player1_wins_over_player2(self): self.assertEqual(self.player1, self.game.check_winner(self.player1, self.player2)) def test_player1_wins_over_player2__reversed(self): self.assertEqual(self.player1, self.game.check_winner(self.player2, self.player1)) def test_draw_returns_none(self): self.assertEqual(None, self.game.check_winner(self.player1, self.player3)) def test_bad_choice_returns_invaild_choice(self): self.assertEqual("Not a valid choice", self.game.check_winner(self.player1, self.player4))
def play_computer(): player_1_name_input = request.form['player_1_name'] player_1_choice_input = request.form['player_1_choice'] player_1 = Player(player_1_name_input, player_1_choice_input) game = RockPaper(player_1) player_2 = game.play_computer() choices_list_keys = list(game.win_dict.keys()) result = game.check_winner(player_1, player_2) return render_template('results.html', player_1=player_1, player_2=player_2, game=game, result=result, choices=choices_list_keys, title="Results are in!")
def mvp(player_1_choice, player_2_choice): player_1 = Player("Player 1", player_1_choice) player_2 = Player("Player 2", player_2_choice) game = RockPaper(player_1, player_2) result = game.check_winner(player_1, player_2) if result == "Not a valid choice": return "Not a valid choice" elif result != None: return f"Winner is: {result.name} with {result.choice}" else: return "It is a Draw"
def computer(): game = RockPaper() choices_list_keys = game.win_dict.keys() return render_template('computer.html', title="1 Player", choices=choices_list_keys)
def extension(): game = RockPaper() choices_list_keys = game.win_dict.keys() return render_template('index.html', title="2 Player", choices=choices_list_keys)
def base(): game = RockPaper() return render_template('base.html', title="Rock, Paper, Scissors!")
def setUp(self): self.player1 = Player("Rocky", "Rock") self.player2 = Player("Snippy", "Scissors") self.player3 = Player("Marty", "Rock") self.player4 = Player("Ben", "Potato") self.game = RockPaper(self.player1, self.player2)