def single_play():
    player_1 = Player(request.form["player_1_name"],
                      request.form["player_1_choice"])
    player_2 = Player(None, None)
    game = Game(player_1, player_2)
    final_winner = game.play_rps()
    return redirect(f'/winner/{final_winner}')
Esempio n. 2
0
def check(choice1, choice2):
    game = Game()
    result = game.game(choice1, choice2)
    return render_template('index.html',
                           title='Home',
                           choice1=choice1,
                           choice2=choice2,
                           result=result)
Esempio n. 3
0
def play():
    if request.method == 'POST':
        name = request.form['name']
        # tried to sent 'Player' if name form is empty
        #this didnt work ???find how to???
        #insted learned how to force user to fill name form
        # if name is None:
        #      name = "Player"
        game = Game()
        random_str = random_generator.str_generator()
        result = game.game(request.form['choice7'], random_str)
        return render_template('results.html',
                               result=result,
                               random_str=random_str,
                               name=name)
    else:
        return render_template("tempo.html")
def rps():
    player_1_name = request.form["player_1_name"]
    player_2_name = request.form["player_2_name"]
    player_1_choice = request.form["choice_1"]
    player_2_choice = request.form["choice_2"]
    player_1 = Player(player_1_name, player_1_choice)
    player_2 = Player(player_2_name, player_2_choice)
    game = Game()
    winner = game.play(player_1, player_2)
    # return render_template("index.html", title="work", winner=winner)
    if winner:
        return render_template(
            "index.html",
            title="Play the Game",
            result=f"The Winner is {winner.name} with {winner.choice}")
    else:
        return render_template("index.html",
                               title="Play the Game",
                               result="Draw")
def rps():
    player_1_name = request.form["player_1_name"]
    player_2_name = request.form["player_2_name"]
    player_1_choice = request.form["choice_1"]
    player_2_choice = request.form["choice_2"]
    player_1 = Player(player_1_name, player_1_choice)
    player_2 = Player(player_2_name, player_2_choice)
    game = Game()
    winner = game.play(player_1, player_2)
    if winner:
        return render_template(
            "index.html",
            title="Play the Game",
            result=f"The winner is {winner.name} with {winner.choice}!")
    else:
        return render_template("index.html",
                               title="Play the Game",
                               result="It was a draw!")
    return redirect("/play")
Esempio n. 6
0
class TestGame(unittest.TestCase):
    def setUp(self):
        self.game = Game()
        self.player_r = Player("Jim", "rock")
        self.player_p = Player("Jim", "paper")
        self.player_s = Player("Jim", "scissors")

    def test_choices_empty_dict(self):
        expected = {}
        actual = self.game.choices
        self.assertEqual(expected, actual)

    def test_valid_choices(self):
        expected = "paper"
        actual = self.game.valid_choices[1]
        self.assertEqual(expected, actual)

    def test_play_round_paper_beats_rock(self):
        expected = self.player_p
        actual = self.game.play_round(self.player_p, self.player_r)
        self.assertEqual(expected, actual)

    def test_play_round_paper_beats_rock__players_switched(self):
        expected = self.player_p
        actual = self.game.play_round(self.player_r, self.player_p)
        self.assertEqual(expected, actual)

    def test_play_round_paper_loses_scissors(self):
        expected = self.player_s
        actual = self.game.play_round(self.player_p, self.player_s)
        self.assertEqual(expected, actual)

    def test_play_round_paper_loses_scissors__players_switched(self):
        expected = self.player_s
        actual = self.game.play_round(self.player_s, self.player_p)
        self.assertEqual(expected, actual)

    def test_play_round_rock_beats_scissors(self):
        expected = self.player_r
        actual = self.game.play_round(self.player_r, self.player_s)
        self.assertEqual(expected, actual)

    def test_play_round_rock_beats_scissors__players_switched(self):
        expected = self.player_r
        actual = self.game.play_round(self.player_s, self.player_r)
        self.assertEqual(expected, actual)

    def test_play_round_draw(self):
        actual = self.game.play_round(self.player_r, self.player_r)
        self.assertIsNone(actual)
Esempio n. 7
0
 def setUp(self):
     self.game = Game()
     self.player_r = Player("Jim", "rock")
     self.player_p = Player("Jim", "paper")
     self.player_s = Player("Jim", "scissors")
def play_rps(choice_1, choice_2):
    player_1 = Player("Player 1", choice_1)
    player_2 = Player("Player 2", choice_2)
    game = Game(player_1, player_2)
    winner = game.play_rps()
    return f'{winner}'
from app.modules.game import Game
from app.modules.player import Player

game = Game()
player_name = "Player"
player = Player(player_name, "rock")
cpu = Player("Computer", "rock")


def sort_scores():
    sorted_scores = []
    if player.score >= cpu.score:
        sorted_scores.append(player)
        sorted_scores.append(cpu)
    else:
        sorted_scores.append(cpu)
        sorted_scores.append(player)
    return sorted_scores
Esempio n. 10
0
import pygame
from app.modules.game import Game

WIDTH, HEIGHT = 1200, 800
FPS = 60
SCALE = 25

pygame.init()

screen = pygame.display.set_mode((WIDTH, HEIGHT))
clock = pygame.time.Clock()

game = Game(screen, SCALE)

running = True

while running:
    delta_time = clock.get_time() / 1000

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

        game.update_inputs(event)

    screen.fill((0, 0, 0))

    game.update(delta_time)

    pygame.display.flip()