Advertisement
jimMoonrock

rock_paper_scissoer_wth_OOP

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