Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Game:
- def __init__(self, p1, p2):
- self.p1 = p1
- self.p2 = p2
- self.p1_score = 0
- self.p2_score = 0
- self.tie_score = 0
- self.num_games = 0
- self.num_rounds = 0
- def play_round(self):
- if self.num_games == 0:
- self.p1 = RandomPlayer()
- self.p2 = RandomPlayer()
- if self.num_games == 1:
- self.p1 = HumanPlayer()
- self.p2 = RandomPlayer()
- if self.num_games == 2:
- self.p1 = HumanPlayer()
- self.p2 = ReflectPlayer()
- if self.num_games == 3:
- self.p1 = HumanPlayer()
- self.p2 = CyclePlayer()
- if self.num_games == 4:
- self.p1 = HumanPlayer()
- self.p2 = Player()
- move1 = self.p1.move()
- move2 = self.p2.move()
- print(f"Player 1: {move1} Player 2: {move2}")
- if beats(move1, move2):
- self.p1_score += 1
- print("P1 wins!")
- print(f"Score: P1 {self.p1_score} P2 {self.p2_score}\n")
- elif beats(move2, move1):
- self.p2_score += 1
- print("P2 wins!")
- print(f"Score: P1 {self.p1_score} P2 {self.p2_score}\n")
- else:
- self.tie_score += 1
- print("Tie Score")
- print(f"Score: P1 {self.p1_score} P2 {self.p2_score}\n")
- self.num_games += 1
- def rounds(self):
- num_rounds = ""
- while num_rounds == "":
- num_rounds = int(input("How many rounds? (from 1-5)?"))
- if num_rounds not in range(5):
- print("Please enter a new number between 1 and 5:\n")
- num_rounds = ""
- else:
- return num_rounds
- def play_game(self):
- print("Game start!")
- for round in range(num_rounds):
- print(f"Round {round +1}:")
- self.play_round()
- print("Game over!")
- if self.p1_score > self.p2_score:
- print("Player 1 Wins!\n")
- print(f"Score: P1 {self.p1_score} P2 {self.p2_score}\n")
- elif self.p1_score < self.p2_score:
- print("Player 2 Wins!\n")
- print(f"Score: P1 {self.p1_score} P2 {self.p2_score}\n")
- elif self.p1_score == self.p2_score:
- print("Tie Game!\n")
- print(f"Score: P1 {self.p1_score} P2 {self.p2_score}\n")
- if __name__ == '__main__':
- game = Game(random.choice(playerclass), random.choice(playerclass))
- game.play_game()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement