-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rock_Paper_Scissors 1.4 - LeaderBoard - By DirtyRat (1).py
299 lines (262 loc) · 8.74 KB
/
Rock_Paper_Scissors 1.4 - LeaderBoard - By DirtyRat (1).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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
import random
import os
import csv
import time
import pandas as pd
from os import path
from sys import platform
if platform == ('linux', 'linux2', 'darwin'):
clear = 'clear'
platform = 'Unix'
elif platform == 'win32':
clear = 'cls'
platform = 'Windows'
# -------------------------------ASCII-HANDS--------------------------------
rps_hozontal_ascii_art = ('''
Rock Paper Scissor
_______ _______ _____
----' ____) ----' ____)___ ----' ___)______
(_____) ______) ________)
(______) ________) ___________)
(_____) _______) (____)
----.__(___) ----._ _______) ----.__(___)
''')
ascii_player_rock = ('''
_______
----' ____)
(_____)
(______)
(_____)
----.__(___)
Player''')
ascii_player_paper = ('''
_______
----' ____)___
______)
________)
_______)
----._ ________)
Player''')
ascii_player_scissor = ('''
_____
----' ___)______
________)
___________)
(____)
----.__(___)
Player''')
ascii_bot_rock = ('''
_______
(____ '----
(_____)
(______)
(_____)
(___)__.----
Bot''')
ascii_bot_paper = ('''
_______
___(____ '----
(______
(________
(_______
(_______ _.----
Bot''')
ascii_bot_scissor = ('''
_____
______(___ '----
(________
(___________
(____)
(___)__.----
Bot''')
# -------------------------------VARIABLES--------------------------------
bot_weapon = ''
player_score = 0
combo_power = 1
losing_power = 1
player_rock = 'Rock' + ascii_player_rock
player_paper = 'Paper' + ascii_player_paper
player_scissor = 'Scissor' + ascii_player_scissor
bot_rock = 'Rock' + ascii_bot_rock
bot_paper = 'Paper' + ascii_bot_paper
bot_scissor = 'Scissor' + ascii_bot_scissor
input_rock = ['Rock', 'r', 'R', 'rock']
input_paper = ["Paper", 'R', 'p', 'paper']
input_scissor = ["Scissor", 'S', 's', 'scissor']
bot_weapon_list = [bot_rock, bot_paper, bot_scissor]
keep_playing = True
player_name = ''
# ---------------------------------Functions---------------------------------
def time_pause():
time.sleep(0.5)
def introduction():
print('Rock Paper Scissor Python or RPSP, By DirtyRat')
divider()
print(rps_hozontal_ascii_art)
divider()
print('System: ' + platform)
print()
divider()
leaderboard_print()
divider()
def replay_function():
global keep_playing
yea_or_nae = input()
if yea_or_nae == 'y':
keep_playing = True
os.system(clear)
elif yea_or_nae == 'n':
keep_playing = False
os.system(clear)
else:
print('Please only enter [y/n]')
replay_function()
def normalise_input():
global player_weapon
if player_weapon in input_paper:
player_weapon = player_paper
elif player_weapon in input_scissor:
player_weapon = player_scissor
elif player_weapon in input_rock:
player_weapon = player_rock
def divider():
print('**********************************************')
# global is pass by reference
def random_gen_bot_weapon(bot_weapon_list):
global bot_weapon
bot_weapon = bot_weapon_list[random.randint(0, 2)]
def input_check_and_route_player_weapon():
global player_status
global player_weapon
print(rps_hozontal_ascii_art)
divider()
print("""What's your weapon?
r or rock for Rock
p or paper for Paper
s scissor for Scissor
""")
player_weapon = input()
if player_weapon in input_rock + input_paper + input_scissor:
normalise_input()
if bot_weapon == bot_rock:
bot_is_rock()
elif bot_weapon == bot_paper:
bot_is_paper()
elif bot_weapon == bot_scissor:
bot_is_scissor()
else:
os.system(clear)
divider()
print("C'mon! Do you know how to play rock paper scissor?")
input_check_and_route_player_weapon()
def enter_or_update_username():
global player_name
print('Please enter your name')
name_under_10 = 'True'
while str(name_under_10) == 'True':
player_name = input()
if len(player_name) <= 10:
name_under_10 = 'False'
if len(player_name) > 10:
print('Name under 10 characters please')
def display_score():
print()
print('---------------------------------- Score: ' + str(player_score))
def initalise_csv_file():
if str(path.exists('player_file.csv')) == 'False':
with open('player_file.csv', 'w', newline='') as player_file:
player_writer = csv.writer(player_file, delimiter=',')
player_writer.writerow(['Player', 'Score'])
if str(path.exists('player_file.csv')) == 'True':
pass
def write_single_player_line_score_csv():
with open('player_file.csv', 'a', newline='') as player_file:
player_writer = csv.writer(player_file, delimiter=',')
player_writer.writerow([player_name, player_score])
def read_single_player_line_score_csv():
with open('player_file.csv') as player_file:
player_reader = csv.reader(player_file, delimiter=',')
row_count = sum(1 for row in player_reader)
row_count_minus = row_count - 1
os.system(clear)
print('Your score is saved')
with open('player_file.csv') as player_file:
player_reader = csv.reader(player_file, delimiter=',')
for row in list(player_reader)[row_count_minus:row_count]:
print(row)
def leaderboard_print():
print('-----------High Score Leaderboard-----------')
leaderboard = pd.read_csv("player_file.csv", delimiter=',')
leaderboard.sort_values(by='Score', ascending=False, inplace=True)
print(leaderboard.to_string(index=False))
# ------------------------------Bot Dependant------------------------------
# From function input_and_check_player_weapon(), program makes decision here
def bot_is_rock():
global player_status
if player_weapon == player_paper:
player_status = 'win'
elif player_weapon == player_scissor:
player_status = 'lose'
elif player_weapon == player_rock:
player_status = 'draw'
def bot_is_paper():
global player_status
if player_weapon == player_scissor:
player_status = 'win'
elif player_weapon == player_rock:
player_status = 'lose'
elif player_weapon == player_paper:
player_status = 'draw'
def bot_is_scissor():
global player_status
if player_weapon == player_rock:
player_status = 'win'
elif player_weapon == player_paper:
player_status = 'lose'
elif player_weapon == player_scissor:
player_status = 'draw'
# ---------------------------------End-Fucntion---------------------------------
os.system(clear)
introduction()
input('Press enter to play the game')
while keep_playing is True:
os.system(clear)
display_score()
random_gen_bot_weapon(bot_weapon_list)
input_check_and_route_player_weapon()
os.system(clear)
divider()
print('Your Weapon is ' + player_weapon)
time_pause()
print("Bot's Weapon is " + bot_weapon)
print('You ' + player_status + '!')
if player_status == 'win':
losing_power = 1
player_score = player_score + (100 * (2)**combo_power)
combo_power = combo_power + 1
if player_status == 'lose':
time_pause()
print('U disaapointment')
time_pause()
print('U Lost HAHA')
time_pause()
print('TM by Tony Xu')
divider()
combo_power = 1
player_score = player_score - (100 * (2)**losing_power)
losing_power = losing_power + 1
display_score()
divider()
print('You want to keep playing?')
print('If you lose the game ends')
print('[y/n]')
replay_function()
print()
divider()
print(rps_hozontal_ascii_art)
enter_or_update_username()
initalise_csv_file()
write_single_player_line_score_csv()
read_single_player_line_score_csv()
divider()
leaderboard_print()