-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame_logic.py
More file actions
120 lines (103 loc) · 4.21 KB
/
Copy pathgame_logic.py
File metadata and controls
120 lines (103 loc) · 4.21 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
112
113
114
115
116
117
118
119
120
import random
BOLD = "\033[1m"
CYAN = "\033[96m"
YELLOW = "\033[93m"
GREEN = "\033[92m"
MAGENTA = "\033[95m"
BLUE = "\033[94m"
RED = "\033[91m"
rock = 'Rock'
paper = 'Paper'
scissors = 'Scissors'
lizard = 'Lizard'
spock = 'Spock'
total_games_played = 0
win_counter = 0
draw_counter = 0
lose_counter = 0
troll_counter = 0
print(f'\n{BOLD}{BLUE}Hello and welcome to "Fun with ROCK, PAPER, SCISSORS, LIZARD or SPOCK!"\n'
f'\nHere are the game rules:'
f'\n\nScissors cuts Paper'
f'\nPaper covers Rock'
f'\nRock crushes Lizard'
f'\nLizard poisons Spock'
f'\nSpock smashes Scissors'
f'\nScissors decapitates Lizard'
f'\nLizard eats Paper'
f'\nPaper disproves Spock'
f'\nSpock vaporizes Rock'
f'\n(and as it always has) Rock crushes Scissors\n')
input('Press ENTER to continue and have fun! ')
game_mode = input(f'\n{MAGENTA}Would you like to play against the computer or another human? Type "COMPUTER" or "HUMAN" ').lower()
if game_mode == 'human':
print()
print(f'{YELLOW}This feature is currently under development. Please stay tuned for further updates!'
f'\n\nIn this demo version, you can only play against the computer.')
while True:
player_move = input(f'\n{BOLD}{MAGENTA}Please choose between ROCK, PAPER, SCISSORS, LIZARD or SPOCK: ').lower()
if player_move == "rock":
player_move = rock
elif player_move == "paper":
player_move = paper
elif player_move == "scissors":
player_move = scissors
elif player_move == 'lizard':
player_move = lizard
elif player_move == 'spock':
player_move = spock
else:
troll_counter += 1
if troll_counter <= 3:
print(f'\n{RED}Please be nice, follow the rules of the game. Try again...')
elif 3 < troll_counter <= 5:
print(f'\n{RED}Please stop! Be nice!')
elif 5 < troll_counter <= 7:
print(f'\n{RED}Stop that! You are making me sad!')
elif 7 < troll_counter <= 9:
print(f'\n{RED}I AM STARTING TO GET MAD! Play the game properly or else!')
elif 9 < troll_counter:
print(f'\n{RED}THAT\'S IT! I AM NOW SAD AND ANGRY! YOU DON\'T GET TO HAVE FUN! GOODBYE!')
exit()
continue
print(f'\n{CYAN}You choose {player_move}!')
input(f'\n{MAGENTA}What does the computer choose? ... Press ENTER to find out! ')
computer_random_number = random.randint(1, 5)
computer_move = ""
if computer_random_number == 1:
computer_move = rock
elif computer_random_number == 2:
computer_move = paper
elif computer_random_number == 3:
computer_move = scissors
elif computer_random_number == 4:
computer_move = lizard
elif computer_random_number == 5:
computer_move = spock
print(f'\n{CYAN}The computer chooses {computer_move}.')
if ((player_move == rock and (computer_move == scissors or computer_move == lizard)) or
(player_move == paper and (computer_move == rock or computer_move == spock)) or
(player_move == scissors and (computer_move == paper or computer_move == lizard)) or
(player_move == lizard and (computer_move == paper or computer_move == spock)) or
(player_move == spock and (computer_move == scissors or computer_move == rock))):
print(f'\n{BOLD}{GREEN}You win this round!')
win_counter +=1
elif player_move == computer_move:
print(f'\n{BOLD}{YELLOW}BAZINGA! Draw! ...')
draw_counter += 1
else:
print(f'\n{BOLD}{RED}Loser!')
lose_counter += 1
total_games_played += 1
answer = input(f'\n{MAGENTA}Would you like to play another game? Type "Yes" or "No"! ').lower()
if answer == 'no':
break
elif answer == 'yes':
continue
win_percentage = win_counter / total_games_played * 100
draw_percentage = draw_counter / total_games_played * 100
lose_percentage = lose_counter / total_games_played * 100
print(f'\n{CYAN}You have just had the most fun of your life! Here are your results:')
print(f'\nWins: {win_counter}. Win percentage: {win_percentage:.2f}%')
print(f'Draws: {draw_counter}. Draw percentage: {draw_percentage:.2f}%')
print(f'Losses: {lose_counter}. Lose percentage: {lose_percentage:.2f}%')