-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rock_Paper_Scissors 1.2 Windows_Unix - By DirtyRat.py
173 lines (142 loc) · 4.63 KB
/
Rock_Paper_Scissors 1.2 Windows_Unix - By DirtyRat.py
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# os.system('cls') for Windows
# os.system('clear') for Unix
import random, os, csv, time
bot_weapon = ''
player_score = 0
combo_power = 1
rock = 'Rock 🗿'
paper = 'Paper 🧻'
scissor = 'Scissor ✂️'
input_rock = ['Rock', 'r', 'R', 'rock']
input_paper = ["Paper", 'R', 'p', 'paper']
input_scissor = ["Scissor", 'S', 's', 'scissor']
weapons = [rock, paper, scissor]
keep_playing = True
player_name = ''
# ---------------------------------Fucntion---------------------------------
def replay_function():
global keep_playing
yea_or_nae = input()
if yea_or_nae == 'y':
keep_playing = True
os.system('cls')
elif yea_or_nae == 'n':
keep_playing = False
os.system('cls')
else:
print('Please only enter [y/n]')
replay_function()
# Work on the loop incase the user input shit-input
def normalise_input():
global user_weapon
if user_weapon in input_paper:
user_weapon = paper
elif user_weapon in input_scissor:
user_weapon = scissor
elif user_weapon in input_rock:
user_weapon = rock
def divider():
print('----------------------------------------------------')
print()
# global is pass by reference
def random_gen_bot_weapon(weapons):
global bot_weapon
bot_weapon = weapons[random.randint(0,2)]
def input_check_and_route_user_weapon():
global player_status
global user_weapon
print("""What's your weapon?
r or rock for Rock
p or paper for Paper
s scissor for Scissor
""")
user_weapon = input()
if user_weapon in rock + paper + scissor:
normalise_input()
if bot_weapon == rock:
bot_is_rock()
elif bot_weapon == paper:
bot_is_paper()
elif bot_weapon == scissor:
bot_is_scissor()
else:
os.system('cls')
divider()
print("C'mon! Do you know how to play rock paper scissor?")
input_check_and_route_user_weapon()
def enter_or_update_username():
global player_name
print('Please enter your name')
player_name = input()
def display_score():
print()
print('---------------------------------- Score: ' + str(player_score))
def write_score_csv():
with open('player_file.csv', mode='a') as player_file:
player_writer = csv.writer(player_file, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
player_writer.writerow([player_name,player_score])
def read_score_csv():
with open('player_file.csv') as csv_file:
csv_reader = csv.reader(csv_file, delimiter=',')
for row in csv_reader:
print(row)
# ---------------------------------Bot Dependant---------------------------------
# From function input_and_check_user_weapon(), program makes decision here
def bot_is_rock():
global player_status
if user_weapon == paper:
player_status = 'win'
elif user_weapon == scissor:
player_status = 'lose'
elif user_weapon == rock:
player_status = 'draw'
def bot_is_paper():
global player_status
if user_weapon == scissor:
player_status = 'win'
elif user_weapon == rock:
player_status = 'lose'
elif user_weapon == paper:
player_status = 'draw'
def bot_is_scissor():
global player_status
if user_weapon == rock:
player_status = 'win'
elif user_weapon == paper:
player_status = 'lose'
elif user_weapon == scissor:
player_status = 'draw'
# ---------------------------------End-Fucntion---------------------------------
os.system('cls')
print('Rock Paper Scissor Python or RPSP, By DirtyRat')
while keep_playing is True:
display_score()
random_gen_bot_weapon(weapons)
input_check_and_route_user_weapon()
os.system('cls')
divider()
print("Bot's Weapon is " + bot_weapon)
print('Your Weapon is ' + user_weapon)
print('You ' + player_status + '!')
if player_status == 'win':
player_score = player_score + (100 * (2)**combo_power)
combo_power = combo_power + 1
if player_status == 'lose':
time.sleep(0.5)
print('U disaapointment')
time.sleep(0.5)
print('U Lost HAHA')
time.sleep(0.5)
print('U Lost HAHA')
time.sleep(0.5)
print('TM by Tony Xu')
divider()
display_score()
divider()
print('You want to keep playing?')
print('If you lose the game ends')
print('[y/n]')
replay_function()
enter_or_update_username()
write_score_csv()
read_score_csv()