/
text_game.py
276 lines (257 loc) · 12.1 KB
/
text_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
#Text game by Colin Gideon
#The FIRST Robotics Competition and Infinite Recharge are trademarks of FIRST
import random
import time
#Backup method for Linux or MacOS users where msvcrt doesn't exist
try:
from msvcrt import getch
def keypress():
return getch()
except ModuleNotFoundError:
def keypress():
key = input()
if key == "":
return b'\r'
else:
return key.encode()
match_time = 150
class matchtimer():
#Class that controls the match timer throughout the program
def auto(self):
global match_time
match_time -= 15
def intake(self):
global match_time
if match_time >= 10:
match_time -= random.randint(3,10)
else:
match_time -= random.randint(1,match_time)
def lowgoal(self):
global match_time
if match_time >= 7:
match_time -= random.randint(3,7)
else:
match_time -= random.randint(1,match_time)
def highgoal(self):
global match_time
if match_time >= 15:
match_time -= random.randint(5,15)
else:
match_time -= random.randint(1,match_time)
def inner(self):
global match_time
if match_time >= 17:
match_time -= random.randint(7,17)
else:
match_time -= random.randint(1,match_time)
def cwheel(self):
global match_time
if match_time >= 10:
match_time -= random.rantint(5,10)
else:
match_time -= random.randint(1,match_time)
def end(self):
global match_time
if match_time >= 5:
match_time -= (5,match_time)
fail_flag = False
else:
fail_flag =True
matchtimer = matchtimer()
#Hella variables
red_alliance_score = 0
blue_alliance_score = 0
low_goal = 1
high_goal = 2
inner_goal = 3
rotation_control = 10
position_control = 20
end_hang = 25
end_park = 5
end_level = 15
stage1 = 9
stage2and3 = 20
pen_auto_sector = 3
pen_alliance_zones = 15
pen_pin = 3
pen_damage = 15
begin_cells = 3
robot_cells = 0
robot_cells_max = 5
powercount = 0
print("""Hello and welcome to the 2020 FIRST Robotics Competition!
This years game: INFINITE POSTPONEMENT-er...RECHARGE!
press ENTER to begin or Q to Quit""")
#char_catch has to be redefined before every if check since getch() behaves like input()
char_catch = keypress()
if b'\r' in char_catch:
#Excruciating Pain via Text Wall
print("""Infinite Recharge is played by 2 alliances of 3 robots each.
Scoring is done when a robot from either alliance puts a yellow POWER CELL into their alliances POWER PORT
The POWER PORT has 3 goals:
A low goal easily completable by any robot with a low chance of missing a majority of the shots made (2 Points during Auto, 1 during Teleop)
A high goal that requires a robot to aim to the port to score, with a moderate risk of missing (4 Points during Auto, 2 during Teleop)
A inner port inside of the high goal with a high risk of missing but low chance of missing the high goal (6 Points during Auto, 3 during Teleop)
The game plays out in a 2:30 timed period where the first 15 are taken by the auto period. During this period you can't make contact with the opposing alliances
robots or enter the opposing alliances sector. (Penalty of 3 points given to the opposing alliance)
During the Teleop period, you can defend against other robots to prevent them from scoring. HOWEVER, you can\'t:
Enter the opposing alliances zones marked out around their TRENCH RUN, LOADING ZONE, and POWER PORT
(Penalty of 15 points given to the opposing alliance IF contact is made with a opposing robot in this zone)
Pin for longer than 5 seconds (Penalty of 3 Points given to the opposing alliance)
You can\'t damage other robots (Penalty of 15 Points given to the opposing alliance and a YELLOW CARD given against you
There's 3 stages of play during the game
The first stage is completed when a alliance scores 9 power cells
The second stage is completed when a alliance scores 20 more power cells and ROTATION CONTROL is completed (10 Points to corrosponding Alliance)
The third stage is completed when a alliance scores 20 more power and POSITION CONTROL is completed (20 Points to corrosponding Alliance)
(The option to spin the CONTROL PANEL will show up when ROTATION & POSITION CONTROL is activated and will dissapear after it's been completed)
FINALLY, in the last 30 seconds of the game, you're able to score by climbing the SHIELD GENERATOR SWITCH
For each robot hung, the corrosponding alliance scores 25 points
For each robot parked, the corrosponding alliance scores 5 points
If the switch is level, the corrosponding alliance scores 15 points
-=- END OF TEXT WALL -=-""")
#time.sleep(10)
while True:
#1 = Blue Alliance
#2 = Red Alliance
alliance = random.randint(1,2)
if alliance == 1:
user_alliance = "Blue Alliance"
comp_alliance = "Red Alliance"
else:
comp_alliance = "Blue Alliance"
user_alliance = "Red Alliance"
print(f"""For the match you are on the {user_alliance}
You will be playing against the computer on the {comp_alliance}""")
print("Would you like to begin? Press Enter to Continue or Q to Quit")
char_catch = keypress()
if b'\r' in char_catch:
#Start of game
print("Drivers behind the lines in...")
countdown = 3
for x in range(countdown):
print(f"{countdown}!")
countdown -= 1
time.sleep(1)
print("GO!")
auto_message_mod = ""
if random.randint(1,20) == 6:
if random.randint(1,2) == 2:
blue_alliance_score += pen_auto_sector
auto_message_mod = "However, your robot entered the opposing alliances sector and incurred a foul! The opposing alliance gained 3 of their points from it!"
else:
red_alliance_score += pen_auto_sector
auto_message_mod = "However, the opposing robot entered your alliances sector and incurred a foul! Your alliance gained 3 of your points from it!"
blue_alliance_score += random.randint(1,12) * (high_goal * 2)
red_alliance_score += random.randint(1,12) * (high_goal * 2)
matchtimer.auto()
print(f"During the auto period, the blue alliance scored {blue_alliance_score}, and the red alliance scored {red_alliance_score}. {auto_message_mod}")
time.sleep(3)
wheelstage = 0
while True:
colorwheel = "6) Color wheel Unavailable"
climb = "7) Climb Unavailable"
while wheelstage == 0:
if powercount >= 29:
colorwheel = "6) Spin the color wheel"
break
while wheelstage == 1:
if powercount >= 49:
colorwheel = "6) Spin the color wheel"
break
if match_time <= 30:
climb = "7) Climb!!!"
print(f"""
MATCH SCORE:
Blue Alliance: {blue_alliance_score} Red Alliance: {red_alliance_score}
MATCH TIME: {match_time}""")
print(f"""Power Cells currently in robot: {robot_cells}
What would you like to do?
1) Collect Power Cells
2) Go for the low goal
3) Go for the high goal
4) Go for the inner port
5) Play Defense
{colorwheel}
{climb}
Q) Quit""")
char_catch = keypress()
if b'1' in char_catch:
powercollect = random.randint(0,5)
if powercollect != 0:
if powercollect + robot_cells > 5:
powercollect = 5 - robot_cells
robot_cells += powercollect
print(f"Your robot went and collected {powercollect} Power Cells! This brings your total up to {robot_cells} Power Cells!")
else:
print("Ouch! Your robot didn't collect any Power Cells! Better luck next time!")
matchtimer.intake()
if b'2' in char_catch:
if robot_cells >= 1:
lowshoot = random.randint(1,robot_cells)
lowmiss = random.randint(1,100)
if lowmiss == 50:
lowmissed = random.randint(1, lowshoot)
lowshoot -= lowmissed
robot_cells -= lowshoot
powercount += lowshoot
print(f"Your robot shot {lowshoot} Power Cells, gaining your alliance {lowshoot} points!")
if user_alliance == "Blue Alliance":
blue_alliance_score += lowshoot
elif user_alliance == "Red Alliance":
red_alliance_score += lowshoot
else:
print("You don't have enough Power Cells to do this! Go get more!")
matchtimer.lowgoal()
if b'3' in char_catch:
highmissed = 0
if robot_cells >= 1:
highshoot1 = random.randint(1,robot_cells)
highshoot2 = highshoot1
highmiss = random.randint(1,2)
if highmiss == 2:
highmissed = random.randint(1,highshoot2)
highshoot2 -= highmissed
robot_cells -= highshoot1
powercount += highshoot2
highscore = highshoot2 * high_goal
print (f"Your robot shot {highshoot1} Power Cells and missed {highmissed} shots! Your alliance gained {highscore} points!")
if user_alliance == "Blue Alliance":
blue_alliance_score += highscore
elif user_alliance == "Red Alliance":
red_alliance_score += highscore
else:
print("You don't have enough Power Cells to do this! Go get more!")
matchtimer.highgoal()
if b'4' in char_catch:
innermissed = 0
if robot_cells >= 1:
innershoot1 = random.randint(1,robot_cells)
innershoot2 = innershoot1
innermissed = random.randint(1,highshoot2)
innershoot2 -=innermissed
highshoot1 = innermissed
robot_cells -= highshoot1
powercount += innershoot1
innerscore = highshoot1 * high_goal + innershoot2 * inner_goal
print(f"""Your robot shot {innershoot1} Power Cells towards the inner port, missing {innermissed} shots and scoring them into the high goal instead!
Your Alliance gained {innerscore} points!""")
if user_alliance == "Blue Alliance":
blue_alliance_score += innerscore
elif user_alliance == "Red Alliance":
red_alliance_score += innerscore
else:
print("You don't have enough Power Cells to do this! Go get more!")
if b'5' in char_catch:
if match_time == 0:
print("Aaaand game! Press Q to Quit")
char_catch = keypress()
if char_catch in [b'q',b'Q']:
exit("Goodbye!")
elif char_catch in [b'q',b'Q']:
exit("Goodbye!")
#Exit condition for pre-game
elif char_catch in [b'q',b'Q']:
exit("Goodbye!")
#Exit condition for beginning
elif char_catch in [b'q',b'Q']:
exit("Goodbye!")