Advertisement
Guest User

Untitled

a guest
Oct 15th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. class Game:
  2. def __init__(self, p1, p2):
  3. self.p1 = p1
  4. self.p2 = p2
  5. self.p1_score = 0
  6. self.p2_score = 0
  7. self.tie_score = 0
  8. self.num_games = 0
  9. self.num_rounds = 0
  10.  
  11. def play_round(self):
  12. if self.num_games == 0:
  13. self.p1 = RandomPlayer()
  14. self.p2 = RandomPlayer()
  15. if self.num_games == 1:
  16. self.p1 = HumanPlayer()
  17. self.p2 = RandomPlayer()
  18. if self.num_games == 2:
  19. self.p1 = HumanPlayer()
  20. self.p2 = ReflectPlayer()
  21. if self.num_games == 3:
  22. self.p1 = HumanPlayer()
  23. self.p2 = CyclePlayer()
  24. if self.num_games == 4:
  25. self.p1 = HumanPlayer()
  26. self.p2 = Player()
  27.  
  28. move1 = self.p1.move()
  29. move2 = self.p2.move()
  30. print(f"Player 1: {move1} Player 2: {move2}")
  31.  
  32. if beats(move1, move2):
  33. self.p1_score += 1
  34. print("P1 wins!")
  35. print(f"Score: P1 {self.p1_score} P2 {self.p2_score}\n")
  36. elif beats(move2, move1):
  37. self.p2_score += 1
  38. print("P2 wins!")
  39. print(f"Score: P1 {self.p1_score} P2 {self.p2_score}\n")
  40. else:
  41. self.tie_score += 1
  42. print("Tie Score")
  43. print(f"Score: P1 {self.p1_score} P2 {self.p2_score}\n")
  44.  
  45. self.num_games += 1
  46.  
  47. def rounds(self):
  48. num_rounds = ""
  49. while num_rounds == "":
  50. num_rounds = int(input("How many rounds? (from 1-5)?"))
  51. if num_rounds not in range(5):
  52. print("Please enter a new number between 1 and 5:\n")
  53. num_rounds = ""
  54. else:
  55. return num_rounds
  56.  
  57. def play_game(self):
  58. print("Game start!")
  59. for round in range(num_rounds):
  60. print(f"Round {round +1}:")
  61. self.play_round()
  62. print("Game over!")
  63. if self.p1_score > self.p2_score:
  64. print("Player 1 Wins!\n")
  65. print(f"Score: P1 {self.p1_score} P2 {self.p2_score}\n")
  66. elif self.p1_score < self.p2_score:
  67. print("Player 2 Wins!\n")
  68. print(f"Score: P1 {self.p1_score} P2 {self.p2_score}\n")
  69. elif self.p1_score == self.p2_score:
  70. print("Tie Game!\n")
  71. print(f"Score: P1 {self.p1_score} P2 {self.p2_score}\n")
  72.  
  73.  
  74. if __name__ == '__main__':
  75. game = Game(random.choice(playerclass), random.choice(playerclass))
  76. game.play_game()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement