-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.py
More file actions
111 lines (97 loc) · 3.4 KB
/
Copy pathgame.py
File metadata and controls
111 lines (97 loc) · 3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import os
import random
options = ["rock", "paper", "scissors"]
print("Rock, Paper, Scissors, Go!")
def start_game():
print("Starting game...")
while(True):
level = select_level()
if(level == "1"):
play_level_1()
elif(level == "2"):
play_level_2()
else:
play_level_3()
def select_level():
while(True):
level = input("Select level (1, 2, 3 or Enter to Exit): ")
if(level == ""):
clear_screen()
exit()
if(level == "1" or level == "2" or level == "3"):
clear_screen()
return level
else:
clear_screen()
print("Invalid level. Please try again.")
def play_level_1():
while(True):
print("Playing level 1...")
com_choice = random.choice(options)
player_choice = user_option()
if(player_choice == ""):
clear_screen()
break
if(player_choice in options):
print(determine_winner(player_choice, com_choice))
else:
clear_screen()
print("Invalid choice. Please try again.")
def play_level_2():
while(True):
print("Playing level 2...")
com_choice = random.choice(options)
player_choice = user_option()
if(player_choice == ""):
clear_screen()
break
if(player_choice in options):
verdict = determine_winner(player_choice, com_choice)
# this level let's the computer choose again if the player wins the first time around
if verdict == "Player Wins!":
print(determine_winner(player_choice, random.choice(options)))
else:
print(verdict)
else:
clear_screen()
print("Invalid choice. Please try again.")
def play_level_3():
while(True):
print("Playing level 3...")
com_choice = random.choice(options)
player_choice = user_option()
if(player_choice == ""):
clear_screen()
break
if(player_choice in options):
verdict = determine_winner(player_choice, com_choice)
# this level let's the computer get 2 turns if the player wins the first two rounds
if verdict == "Player Wins!":
verdict = determine_winner(player_choice, random.choice(options))
if verdict == "Player Wins!":
print(determine_winner(player_choice, random.choice(options)))
else:
print(verdict)
else:
print(verdict)
else:
clear_screen()
print("Invalid choice. Please try again.")
def clear_screen():
if(os.name == "nt"):
os.system("cls")
else:
os.system("clear")
def user_option():
return input("Type in your choice (rock, paper, scissors) or (Press Enter to Return to Select Level) : ").strip().lower()
def determine_winner(player_choice, computer_choice):
if(player_choice == computer_choice):
return "It's a tie!"
else:
outcomes = {
"rock": { "scissors": "Player Wins!", "paper": "Computer Wins!" },
"paper": { "rock": "Player Wins!", "scissors": "Computer Wins!" },
"scissors": { "paper": "Player Wins!", "rock": "Computer Wins!" }
}
return outcomes[player_choice][computer_choice]
start_game()