1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
#!/usr/bin/env python3
import random
moves = ['rock', 'paper', 'scissors']
class Player:
def move(self):
return random.choice(moves)
def beats(one, two):
if one == two:
return "** GAME TIE **"
if ((one == 'rock' and two == 'scissors') or
(one == 'scissors' and two == 'paper') or
(one == 'paper' and two == 'rock')):
return "** PLAYER ONE WINS **"
return "** PLAYER TWO WINS **"
class HumanPlayer(Player):
def __init__(self):
super().__init__()
self.choice = None
def HumanChoice(self):
choice = ""
while choice not in moves:
choice = input("Rock, Paper, Scissors ? ").lower()
self.choice = choice
#If input correct display it
return (f"You played : {self.choice}.")
class Game(HumanPlayer):
def __init__(self, p1, p2):
super().__init__()
self.p1 = p1
self.p2 = p2
def score(self, HumChoice, CompChoice):
return beats(HumChoice, CompChoice)
def play_game(self):
print("Game start!\n")
for round in range(1, 4):
print(f"Round {round}:")
print(self.HumanChoice())
print(self.score(self.choice, self.move()))
print("Game over!")
if __name__ == '__main__':
game = Game(Player(), Player())
game.play_game() |
Partager