/
game.py
351 lines (278 loc) · 14.2 KB
/
game.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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
import tools
import time
import colors
in_room = False
my_room = None
my_player = None
upper_lines = "+-----+"
print(f"\nSome {colors.UNDERLINE}RULES{colors.ENDC} before we get into it :\n--\n")
time.sleep(1.5)
print(f"1. Don't rush into anything in life. Join the game {colors.BOLD}ONE PLAYER AT A TIME{colors.ENDC}.\n")
time.sleep(1)
print(f"2. Be patient in life. You will have to {colors.BOLD}WAIT{colors.ENDC} for the room to be initialised and connected. <Waiting for 30s won't hurt.>")
print(" (It depends on your internet connection and fragility of my code, but mostly your internet.) MEH.\n")
time.sleep(1)
print(f"3. Understand that you won't be the number 1 always. {colors.BOLD}DO NOT{colors.ENDC} initialise room after it has been initialised once.\n")
time.sleep(1)
print(f"4. It's the spirit of sportsmanship that drives the world. Don't be an asshole. {colors.BOLD}DON'T CHEAT{colors.ENDC}.\n")
time.sleep(1)
print(f"5. Don't assume, ask. So ask yourself, do {colors.BOLD}I KNOW THE RULES OF CAMEO ?{colors.ENDC}\n")
time.sleep(1)
print(f"6. You don't get second chances in life. {colors.BOLD}DON'T MESS UP THE OPTIONS AND SPELLINGS{colors.ENDC}. Whole room will have to be re-initialised.\n")
time.sleep(1)
print(f"7. Lower the expectations, lesser the hurt. This game might have some {colors.BOLD}BUGS{colors.ENDC} and {colors.BOLD}ERRORS{colors.ENDC}, we'll keep making it better.\n")
time.sleep(1)
print(f"8. You are an Engineer. Act like one. Make sure you meet all the {colors.BOLD}REQUIREMENTS{colors.ENDC} of the game -> Python with 'Selenium' package.\n")
time.sleep(1)
print(f"9. Keep your feet on the ground, but touch the sky. Be connected to {colors.BOLD}INTERNET{colors.ENDC}.\n")
time.sleep(1.5)
print("--------------------------------------------------------------------------------------------------------------------")
time.sleep(1.5)
def power_play(top_card):
if tools.show_card(top_card)[2:] in ['7', '8']:
while True:
my_index = int(input(f"INDEX of {my_player.name.upper()}'s card which you wanna see : "))
if my_index not in my_player.cards_index:
print(f"-> Invalid card index for {my_player.name.upper()}.\n")
continue
else:
break
my_player.look(index=my_index-1)
tools.stage_changes(my_room=my_room, player=my_player, what="looked", whose=my_player.name, which=str(my_index))
elif tools.show_card(top_card)[2:] in ['9', '10']:
while True:
other_name = input("WHOSE card do you wanna SEE : ").lower()
if other_name != my_room.cameo_invoked or other_name != my_player.name:
break
elif other_name == my_player.name:
print(f"-> You can't see your own card with these powers.\n")
continue
else:
print(f"-> {other_name.upper()} has invoked {colors.red}CAMEO{colors.ENDC}. You can't mess with that player.\n")
continue
other_player = tools.get_other_player(my_room=my_room, name=other_name)
while True:
other_index = int(input(f"INDEX of {other_name.upper()}'s card which you wanna see : "))
if other_index not in other_player.cards_index:
print(f"-> Invalid card index for {other_player.name.upper()}.\n")
continue
else:
break
other_player.look(index=other_index-1)
tools.stage_changes(my_room=my_room, player=my_player, what="looked", whose=other_name, which=str(other_index))
# elif tools.show_card(top_card)[-1] == 'J':
# while True:
# other_name = input("WHOSE cards do you wanna SHUFFLE : ").lower()
# if other_name != my_room.cameo_invoked:
# break
# else:
# print(f"-> {other_name.upper()} has invoked {colors.red}CAMEO{colors.ENDC}. You can't mess with that player.\n")
# continue
#
# other_player = tools.get_other_player(my_room=my_room, name=other_name)
# other_player.shuffle()
#
# my_room.update_individual_player(player=[other_player])
# tools.stage_changes(my_room=my_room, player=my_player, what="shuffled", whose=other_name)
elif tools.show_card(top_card)[-1] in ['J', 'Q']:
while True:
other_name = input("WHOSE card do you wanna SWAP with one of yours : ").lower()
if other_name != my_room.cameo_invoked or other_name != my_player.name:
break
elif other_name == my_player.name:
print(f"-> You can't use these powers on your own card.\n")
continue
else:
print(
f"-> {other_name.upper()} has invoked {colors.red}CAMEO{colors.ENDC}. You can't mess with that player.\n")
continue
my_index = int(input(f"INDEX of YOUR card which you wanna swap : "))
other_player = tools.get_other_player(my_room=my_room, name=other_name)
while True:
other_index = int(input(f"INDEX of {other_name.upper()}'s card which you wanna see : "))
if other_index not in other_player.cards_index:
print(f"-> Invalid card index for {other_player.name.upper()}.\n")
continue
if my_index not in my_player.cards_index:
print(f"-> Invalid card index for {my_player.name.upper()}\n")
continue
else:
break
temp_card = other_player.cards[other_index-1]
other_player.swap(card=my_player.cards[my_index-1], index=other_index-1)
my_player.swap(card=temp_card, index=my_index-1)
my_room.update_individual_player(player=[other_player, my_player])
tools.stage_changes(my_room=my_room, player=my_player, what="swapped", whose=other_name, which=f"{my_index},{other_index}")
elif tools.show_card(top_card)[-1] == 'K':
while True:
other_name = input("WHOSE card do you wanna COMPARE & SWAP with one of yours : ").lower()
if other_name != my_room.cameo_invoked and other_name != my_player.name:
break
elif other_name == my_player.name:
print(f"-> You can't use these powers on your own card.\n")
continue
else:
print(
f"-> {other_name.upper()} has invoked {colors.red}CAMEO{colors.ENDC}. You can't mess with that player.\n")
continue
my_index = int(input(f"INDEX of YOUR card which you wanna swap : "))
other_player = tools.get_other_player(my_room=my_room, name=other_name)
while True:
other_index = int(input(f"INDEX of {other_name.upper()}'s card which you wanna see : "))
if other_index not in other_player.cards_index:
print(f"-> Invalid card index for {other_player.name.upper()}.\n")
continue
if my_index not in my_player.cards_index:
print(f"-> Invalid card index for {my_player.name.upper()}\n")
continue
else:
break
print(f"\n{colors.purple}{other_name.upper()} card {other_index} : {tools.show_card(other_player.cards[other_index-1])}{colors.ENDC}")
print(f"{colors.purple}YOUR card {my_index} : {tools.show_card(my_player.cards[my_index-1])}{colors.ENDC}")
swap_option = input("Do you want to SWAP them ? (yes/no) -> ").lower()
if swap_option == 'yes':
temp_card = other_player.cards[other_index-1]
other_player.swap(card=my_player.cards[my_index-1], index=other_index-1)
my_player.swap(card=temp_card, index=my_index-1)
my_room.update_individual_player(player=[other_player, my_player])
tools.stage_changes(my_room=my_room, player=my_player, what="looked,swapped", whose=other_name,
which=f"{my_index},{other_index}")
else:
tools.stage_changes(my_room=my_room, player=my_player, what="looked", whose=other_name,
which=f"{my_index},{other_index}")
my_room.stack.append(top_card)
# ---------------------------------
print(f"{colors.yellow}{colors.BOLD}\n\\ __ - CAMEO - __ /{colors.ENDC}")
while True:
game_choice = int(input("\n1. Initialise room\n"
"2. Join room\n"
"3. Exit\n"
"-> "))
if game_choice == 1:
if not in_room:
my_room, my_player = tools.init_game()
in_room = True
time.sleep(1)
print("\nPlayer CONNECTED!\tPlease advise the next player to join.")
time.sleep(2)
starter = input(f"{colors.green}Please wait until all the players have joined.{colors.ENDC} \n\nENTER 'start' TO BEGIN -> ").lower()
if starter == "start":
break
break
elif game_choice == 2:
if not in_room:
my_room, my_player = tools.join_room()
in_room = True
time.sleep(1)
print("\nPlayer CONNECTED!\tPlease advise the next player to join.")
time.sleep(2)
starter = input(f"{colors.green}Please wait until all the players have joined. {colors.ENDC}\n\nENTER 'start' TO BEGIN -> ").lower()
if starter == "start":
break
break
elif game_choice == 3:
if in_room:
my_room.kill_me()
exit()
else:
print("Invalid input. TRY AGAIN.")
continue
print("\n== INSIDE THE ROOM ==\n")
current_player = my_player.name
while True:
current_bit = my_room.current_status
if "_" in my_room.players[0]:
first_player = my_room.players[0].split('_')[0]
else:
first_player = my_room.players[0]
if first_player == my_room.cameo_invoked:
tools.execute_cameo(my_room=my_room)
elif first_player == my_player.name:
current_player = my_room.players[0]
time.sleep(1.5)
print(my_room)
# if power_card is None:
in_game = int(input("\n1. New card from deck\n"
"2. Burn\n"
"3. CAMEO !\n"
"-> "))
if in_game == 1:
new_card = my_room.deck.pop(0)
if len(my_room.deck) == 0:
my_room.deck = tools.shuffle(deck=my_room.stack)
my_room.stack = []
print(f"\n{upper_lines:>{18}}")
print(f"new card : | {colors.BOLD}{tools.show_card(new_card)}{colors.ENDC} |")
print(f"{upper_lines:>{18}}")
if tools.show_card(new_card) not in tools.power_deck:
card_option = int(input("\n1. Do nothing\n"
"2. Replace with one of yours\n"
"-> "))
else:
card_option = int(input(f"\n{colors.red}POWER CARD !{colors.ENDC}\n"
"1. Do nothing\n"
"2. Replace with one of yours\n"
"3. Avail powers\n"
"-> "))
if card_option == 1:
# if tools.show_card(new_card) in tools.power_deck:
# print("\n-\\(-.-)/-")
# time.sleep(0.5)
# print(f"Listen here, you little shit. THIS IS A POWER CARD. You get powers. {colors.BOLD}USE THE POWERS.{colors.ENDC}\n")
# power_play(top_card=new_card)
# else:
my_room.stack.append(new_card)
elif card_option == 2:
index = int(input("Enter the number of the card you want to SWAP : "))
player_card = my_player.swap(card=new_card, index=index-1)
# if tools.show_card(player_card) in tools.power_deck:
# my_room.stack.append(player_card)
# power_card = player_card
# tools.power_function(my_room=my_room)
#
# else:
my_room.update_individual_player(player=[my_player])
my_room.stack.append(player_card)
tools.stage_changes(my_room=my_room, player=my_player, what="swapped", whose=my_player.name, which=str(index))
elif card_option == 3:
power_play(top_card=new_card)
else:
print("Invalid input. TRY AGAIN.")
continue
elif in_game == 2:
cards = input("Enter the indexes of cards you want to BURN. <use commas to separate them> :")
if len(cards) > 0:
cards = cards.split(",")
else:
cards = [cards]
if tools.show_card(my_room.stack[-1])[2:] in ['J', 'Q', 'K']:
if len(cards) == 1:
if tools.show_card(my_player.cards[int(cards[0])-1])[2:] == tools.show_card(my_room.stack[-1])[2:]:
tools.execute_burn(my_room=my_room, my_player=my_player, indexes=cards)
else:
tools.lol_burn(my_room=my_room, my_player=my_player)
else:
tools.lol_burn(my_room=my_room, my_player=my_player)
else:
player, score = tools.player_score(player=my_player, indexes=cards)
if score == int(tools.show_card(my_room.stack[-1])[2:]):
tools.execute_burn(my_room=my_room, my_player=my_player, indexes=cards)
else:
tools.lol_burn(my_room=my_room, my_player=my_player)
my_room.update_individual_player(player=[my_player])
elif in_game == 3:
tools.invoke_cameo(my_room=my_room, my_player=my_player)
else:
print("Invalid input. TRY AGAIN.")
continue
# else:
# print(f"You just got a {colors.red}POWER CARD!{colors.ENDC} -> {colors.BOLD}{tools.show_card(power_card)}{colors.ENDC}\n")
# power_play(top_card=power_card)
my_room.update_room()
else:
print(my_room)
while True:
if my_room.current_status == current_bit:
continue
else:
break