|
| 1 | +import random |
| 2 | + |
| 3 | +all_options = ['rock', 'gun', 'lightning', 'devil', 'dragon', 'water', 'air', |
| 4 | + 'paper', 'sponge', 'wolf', 'tree', 'human', 'snake', 'scissors', 'fire'] |
| 5 | + |
| 6 | +game_mode = True |
| 7 | + |
| 8 | +double_all_options = all_options * 2 |
| 9 | +all_losing_options = {} |
| 10 | +for key in range(len(all_options)): |
| 11 | + all_losing_options[all_options[key]] = double_all_options[key + 1:key + 8] |
| 12 | + |
| 13 | + |
| 14 | +player = str(input("Enter Your name: ")) |
| 15 | +print("Hello, " + player) |
| 16 | + |
| 17 | +file = open("rating.txt", "rt") |
| 18 | +data_read = file.readlines() |
| 19 | +data = [plr.split(" ") for plr in data_read] |
| 20 | +score = 0 |
| 21 | +file.close() |
| 22 | + |
| 23 | +for plr in data: |
| 24 | + if plr[0] == player: |
| 25 | + print("Loaded Score from Last Game") |
| 26 | + score = int(plr[1]) |
| 27 | + break |
| 28 | + |
| 29 | +user_choose = str(input("Press Enter to cont. with default options or give options\n")) |
| 30 | +if user_choose == "": |
| 31 | + values = ["rock", "paper", "scissors"] |
| 32 | +else: |
| 33 | + values = user_choose.split(",") |
| 34 | + |
| 35 | +active_options = {} |
| 36 | +for key in all_losing_options: |
| 37 | + if key in values: |
| 38 | + temp = [] |
| 39 | + for op in all_losing_options[key]: |
| 40 | + if op in values: |
| 41 | + temp.append(op) |
| 42 | + active_options[key] = temp |
| 43 | + |
| 44 | +print("Okay, let's start") |
| 45 | + |
| 46 | + |
| 47 | +def save_in_txt(): |
| 48 | + print(player,score) |
| 49 | + for plr in data: |
| 50 | + if plr[0] == player: |
| 51 | + plr[1] = str(score) |
| 52 | + break |
| 53 | + else: |
| 54 | + data.append([str(player),str(score)]) |
| 55 | + write_data = ["{0} {1}\n".format(x1, x2) for (x1, x2) in data] |
| 56 | + with open('rating.txt', 'w') as out_file: |
| 57 | + out_file.writelines(write_data) |
| 58 | + print("Data Saved") |
| 59 | + |
| 60 | + |
| 61 | +while game_mode: |
| 62 | + try: |
| 63 | + system_choice = values[random.randrange(len(values))] |
| 64 | + user_choice = str(input()) |
| 65 | + if user_choice == system_choice: |
| 66 | + score += 50 |
| 67 | + print("There is a draw " + system_choice) |
| 68 | + elif user_choice == "!exit": |
| 69 | + game_mode = False |
| 70 | + save_in_txt() |
| 71 | + print("Bye!") |
| 72 | + break |
| 73 | + elif user_choice == "!rating": |
| 74 | + print("Your rating: ", score) |
| 75 | + elif system_choice in active_options[user_choice] : |
| 76 | + print("Sorry, but computer chose " + system_choice) |
| 77 | + elif user_choice in active_options[system_choice] : |
| 78 | + score += 100 |
| 79 | + print("Well done. Computer chose " + system_choice + " and failed") |
| 80 | + except KeyError: |
| 81 | + print("Invalid input") |
| 82 | + |
0 commit comments