You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: main.py
+61-61
Original file line number
Diff line number
Diff line change
@@ -4,13 +4,13 @@
4
4
importsys
5
5
importjson
6
6
fromgetkeyimportgetkey, keys
7
-
fromrichimportclear
8
-
fromrichimportprint
7
+
fromrich.consoleimportConsole
9
8
9
+
console=Console()
10
10
try:
11
11
db=json.load(open("save.json", "r"))
12
12
exceptFileNotFoundError:
13
-
print("The save.json file was not found, or it was corrupted. Please retrieve it and put it in this working directory.")
13
+
console.print("The save.json file was not found, or it was corrupted. Please retrieve it and put it in this working directory.")
14
14
exit(1)
15
15
cheatcode=False
16
16
@@ -19,30 +19,30 @@ class Alarm(Exception):
19
19
20
20
try:
21
21
argv=sys.argv[1]
22
-
print(argv)
22
+
console.print(argv)
23
23
ifargv=="dev":
24
-
print("[⚠️ ⚠️ ⚠️ ]: Dev mode. Certain things may break.")
24
+
console.print("[⚠️ ⚠️ ⚠️ ]: Dev mode. Certain things may break.")
25
25
cheatcode=True
26
-
print("[NOTE]: Cheat code registered.")
26
+
console.print("[NOTE]: Cheat code registered.")
27
27
input("Press enter to continue...")
28
28
elifargv=="reset-data":
29
29
db["first_time"] =True
30
30
db["stage"] =1
31
31
withopen('save.json', 'w') asf:
32
32
json.dump(db, f)
33
-
print("[NOTE]: Your data has been reset.")
33
+
console.print("[NOTE]: Your data has been reset.")
34
34
exit()
35
35
elifargv=="debug":
36
-
print("Yep, all good. You would get errors if this didn't come up")
36
+
console.print("Yep, all good. You would get errors if this didn't come up")
37
37
exit()
38
38
else:
39
-
print("[ERROR]: Why did you try?")
39
+
console.print("[ERROR]: Why did you try?")
40
40
41
41
exceptKeyError:
42
-
print("This program comes with a file with '.json' at the end. If you're receiving this error, that file may be corrupted or does not exist. Can you please check that?")
42
+
console.print("This program comes with a file with '.json' at the end. If you're receiving this error, that file may be corrupted or does not exist. Can you please check that?")
43
43
exit()
44
44
exceptIndexError:
45
-
print("[NOTE]: Cheat code bypassed.")
45
+
console.print("[NOTE]: Cheat code bypassed.")
46
46
47
47
ifnotdb["first_time"]:
48
48
pass
@@ -71,74 +71,74 @@ def climb(self):
71
71
ifnotself.alive:
72
72
returnFalse
73
73
74
-
print(f"Press '{self.current_key}' to climb!")
74
+
console.print(f"Press '{self.current_key}' to climb!")
75
75
key=getkey()
76
76
ifkey==self.current_key:
77
77
self.position+=1
78
78
ifself.position>self.max_height:
79
79
self.position=self.max_height
80
-
os.system(clear)
80
+
console.clear()
81
81
ifself.position==1:
82
-
print(f"Climbed 1 up. You are now at {self.position} metre.")
82
+
console.print(f"Climbed 1 up. You are now at {self.position} metre.")
83
83
else:
84
-
print(f"Climbed 1 up. You are now at {self.position} metres.")
84
+
console.print(f"Climbed 1 up. You are now at {self.position} metres.")
85
85
elifkey==keys.ESC:
86
86
returnFalse
87
87
else:
88
88
fall_distance=1
89
89
ifself.position>5:
90
-
os.system(clear)
91
-
print(f"Fell from height {self.position}. You died!")
90
+
console.clear()
91
+
console.print(f"Fell from height {self.position}. You died!")
92
92
self.alive=False
93
93
returnFalse
94
94
else:
95
95
self.position=max(0, self.position-fall_distance)
96
-
os.system(clear)
97
-
print(f"Waited and fell to position: {self.position}")
96
+
console.clear()
97
+
console.print(f"Waited and fell to position: {self.position}")
98
98
99
99
self.current_key=random.choice(self.keys)
100
100
returnTrue
101
101
102
102
defclimb():
103
103
# Usage example
104
104
climber=ClimbingSystem()
105
-
print("To start climbing, press the key that is shown.")
106
-
print("You need to climb up to 10 metres to succeed.")
107
-
print("Pressing any other key or waiting will make you fall.")
108
-
print("Press 'ESC' to stop climbing.")
109
-
print("If you fall from a height greater than 5 metres, you die!")
105
+
console.print("To start climbing, press the key that is shown.")
106
+
console.print("You need to climb up to 10 metres to succeed.")
107
+
console.print("Pressing any other key or waiting will make you fall.")
108
+
console.print("Press 'ESC' to stop climbing.")
109
+
console.print("If you fall from a height greater than 5 metres, you die!")
print("You really don't want to play it, don't you?")
132
+
console.print("You really don't want to play it, don't you?")
133
133
withopen('save.json', 'w') asf:
134
134
json.dump(db, f)
135
135
exit()
136
-
os.system(clear)
136
+
console.clear()
137
137
138
138
139
139
defsequence1():
140
-
print("Good. Let's begin.")
141
-
print("""
140
+
console.print("Good. Let's begin.")
141
+
console.print("""
142
142
You are at a payphone, and you have a piece of paper reading:
143
143
Some of us contain 10 numbers, some of them don't.
144
144
The three-digit ones, will not help you at all.
@@ -149,23 +149,23 @@ def sequence1():
149
149
And here's the answer: The last digit is a multiple of 3""")
150
150
no=int(input("What's the number? "))
151
151
ifno==1209444419:
152
-
print("Correct. You have survived.")
153
-
print(
152
+
console.print("Correct. You have survived.")
153
+
console.print(
154
154
"The door of the locked payphone opens, and you see a cliff before your eyes."
155
155
)
156
156
elifno==000:
157
-
print("You really think the police can help you? I don't think so.")
158
-
print("The payphone shocks you hard, killing you in the process. ")
159
-
print("You. Are. Dead.")
157
+
console.print("You really think the police can help you? I don't think so.")
158
+
console.print("The payphone shocks you hard, killing you in the process. ")
159
+
console.print("You. Are. Dead.")
160
160
withopen('save.json', 'w') asf:
161
161
json.dump(db, f)
162
162
exit()
163
163
elifcheatcode:
164
164
pass
165
165
else:
166
-
print("Wrong number.")
167
-
print("The payphone shocks you hard, killing you in the process. ")
168
-
print("You. Are. Dead.")
166
+
console.print("Wrong number.")
167
+
console.print("The payphone shocks you hard, killing you in the process. ")
168
+
console.print("You. Are. Dead.")
169
169
withopen('save.json', 'w') asf:
170
170
json.dump(db, f)
171
171
exit()
@@ -175,63 +175,63 @@ def sequence1():
175
175
176
176
177
177
defsequence2():
178
-
print(
178
+
console.print(
179
179
"You are now surrounded by walls, you don't know how they got there, but you cannot climb them. They are covered in oil. There is, however, a cliff in front of you."
180
180
)
181
-
print("You decide to climb.")
181
+
console.print("You decide to climb.")
182
182
input("Press enter to continue...")
183
-
os.system(clear)
183
+
console.clear()
184
184
climb_result=climb() # Climbing system initation
185
185
ifclimb_result:
186
186
pass
187
187
elifnotclimb_result:
188
-
print("You. Are. Dead.")
188
+
console.print("You. Are. Dead.")
189
189
withopen('save.json', 'w') asf:
190
190
json.dump(db, f)
191
191
exit()
192
-
print("You have reached the top of the cliff.")
193
-
os.system(clear)
192
+
console.print("You have reached the top of the cliff.")
193
+
console.clear()
194
194
withopen('save.json', 'w') asf:
195
195
json.dump(db, f)
196
196
db['stage'] =3
197
197
198
198
199
199
defsequence3():
200
-
print(
200
+
console.print(
201
201
"You reach a treasure area with a pot of gold, but the same phone booth is there."
202
202
)
203
-
print("You are scared that the phone booth will attack you.")
203
+
console.print("You are scared that the phone booth will attack you.")
204
204
choice=input("Do you wish to take the gold? Or do you run away? (get gold/run away) ").upper()
205
205
ifchoice=="GET GOLD":
206
-
print(
206
+
console.print(
207
207
"Lucky for you, the phone booth was a prop and did not do anything. You were able to retrieve the gold and win!"
208
208
)
209
209
210
-
print("You. Won.")
210
+
console.print("You. Won.")
211
211
x=input("Do you wish to save your data [yes/no]? ").upper()
212
212
ifx=="YES":
213
213
db['stage'] =4
214
-
print("Your data is kept. You can now exit the game.")
214
+
console.print("Your data is kept. You can now exit the game.")
215
215
withopen('save.json', 'w') asf:
216
216
json.dump(db, f)
217
217
else:
218
218
db['stage'] =1
219
-
print("Your data has been wiped. Thank you for playing!")
219
+
console.print("Your data has been wiped. Thank you for playing!")
220
220
withopen('save.json', 'w') asf:
221
221
json.dump(db, f)
222
222
exit()
223
223
elifchoice=="RUN AWAY":
224
-
print(
224
+
console.print(
225
225
"Had you have known that the phone booth was a prop, you could have actually got the gold."
226
226
)
227
-
print(
227
+
console.print(
228
228
"Oblivious to the environment around you, you fall off the cliff")
229
-
print("You. Are. Dead.")
229
+
console.print("You. Are. Dead.")
230
230
withopen('save.json', 'w') asf:
231
231
json.dump(db, f)
232
232
exit()
233
233
else:
234
-
print(
234
+
console.print(
235
235
"That's not an option, but the computer recognises that and bans you for cheating. What an idiot you are :/"
236
236
)
237
237
returnFalse
@@ -248,7 +248,7 @@ def sequence3():
248
248
elifstage==3:
249
249
a=sequence3()
250
250
ifnota:
251
-
print(
251
+
console.print(
252
252
"You are now banned. Because of how good you are, all of your progress has reset. You will have to restart the game."
253
253
)
254
254
db['stage'] ==1
@@ -262,16 +262,16 @@ def sequence3():
262
262
exceptKeyError:
263
263
sequence1()
264
264
ifdb['stage'] ==4:
265
-
print("You've won the game already.")
265
+
console.print("You've won the game already.")
266
266
x=input("Do you wish to keep your data [yes/no]? ").upper()
267
267
ifx=="YES":
268
-
print("Alright then.")
268
+
console.print("Alright then.")
269
269
withopen('save.json', 'w') asf:
270
270
json.dump(db, f)
271
271
exit()
272
272
else:
273
273
db['stage'] =1
274
-
print(
274
+
console.print(
275
275
"Game successfully reset. You will now start from the beginning next time you load."
0 commit comments