jimMoonrock

Scissors_Rock_paper(vesrsion3)

Apr 27th, 2021
1,013
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.55 KB | None | 0 0
  1. import random
  2.  
  3. class RockPaperScissors:
  4.     def __init__(self):
  5.         self.choice = "No"
  6.         self.name = ""
  7.         self.users_in_database = {}
  8.         self.user_count = 0
  9.         self.count_for_person_who_out_db = 0
  10.  
  11.     def user_choice(self, choice):
  12.         self.choice = choice
  13.         if self.choice == "I want to play":
  14.             return self.main_func()
  15.         return self.exit_func()
  16.  
  17.     def main_func(self):
  18.         with open("rating.txt", encoding="utf-8") as file:
  19.             for name_and_score in file.readlines():
  20.                 data = name_and_score.strip('\n').split(" ")
  21.                 self.users_in_database[data[0]] = int(data[1])
  22.         return self.func_with_game()
  23.  
  24.     def exit_func(self):
  25.         return "Maybe, next time!"
  26.  
  27.     def func_with_game(self):
  28.         self.name = input("Enter your name: ")
  29.         print(f"Hello, {self.name}")
  30.  
  31.         while True:
  32.             user_try = random.randint(0, 3)
  33.             computer = random.randint(0, 3)
  34.  
  35.             inp = input()
  36.             if inp in ("rock", "paper", "scissors"):
  37.  
  38.                 if user_try > computer:
  39.                     if self.name in self.users_in_database:
  40.                         if inp == "rock":
  41.                             print("Well done. The computer chose scissors and failed")
  42.                             self.users_in_database[self.name] += 100
  43.                         elif inp == "scissors":
  44.                             print("Well done. The computer chose paper and failed")
  45.                             self.users_in_database[self.name] += 100
  46.                         elif inp == "paper":
  47.                             print("Well done. The computer chose rock and failed")
  48.                             self.users_in_database[self.name] += 100
  49.                     else:
  50.                         if inp == "rock":
  51.                             print("Well done. The computer chose scissors and failed")
  52.                             self.count_for_person_who_out_db += 100
  53.                         elif inp == "scissors":
  54.                             print("Well done. The computer chose paper and failed")
  55.                             self.count_for_person_who_out_db += 100
  56.                         elif inp == "paper":
  57.                             print("Well done. The computer chose rock and failed")
  58.                             self.count_for_person_who_out_db += 100
  59.                 elif user_try < computer:
  60.                     if inp == "rock":
  61.                         print("Sorry, but the computer chose paper")
  62.                     elif inp == "scissors":
  63.                         print("Sorry, but the computer chose rock")
  64.                     elif inp == "paper":
  65.                         print("Sorry, but the computer chose scissors")
  66.  
  67.                 elif user_try == computer:
  68.                     if self.name in self.users_in_database:
  69.                         self.users_in_database[self.name] += 50
  70.                     else:
  71.                         self.count_for_person_who_out_db += 50
  72.                     print(f"There is a draw ({inp})")
  73.  
  74.             elif inp == "!rating":
  75.                 if self.name in self.users_in_database:
  76.                     print(f"Your rating: {self.users_in_database[self.name]}")
  77.                 else:
  78.                     print(f"Your rating: {self.count_for_person_who_out_db}")
  79.  
  80.  
  81.             elif inp == "!exit":
  82.                 print("Bye!")
  83.                 break
  84.             else:
  85.                 print("Invalid input")
  86.  
  87.  
  88. ron = RockPaperScissors()
  89. print(ron.user_choice("I want to play"))
  90.  
Advertisement
Add Comment
Please, Sign In to add comment