Skip to content

Commit 4e4818f

Browse files
authored
fix: try 2
1 parent ff15702 commit 4e4818f

File tree

1 file changed

+61
-61
lines changed

1 file changed

+61
-61
lines changed

main.py

+61-61
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
import sys
55
import json
66
from getkey import getkey, keys
7-
from rich import clear
8-
from rich import print
7+
from rich.console import Console
98

9+
console = Console()
1010
try:
1111
db = json.load(open("save.json", "r"))
1212
except FileNotFoundError:
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.")
1414
exit(1)
1515
cheatcode = False
1616

@@ -19,30 +19,30 @@ class Alarm(Exception):
1919

2020
try:
2121
argv = sys.argv[1]
22-
print(argv)
22+
console.print(argv)
2323
if argv == "dev":
24-
print("[⚠️ ⚠️ ⚠️ ]: Dev mode. Certain things may break.")
24+
console.print("[⚠️ ⚠️ ⚠️ ]: Dev mode. Certain things may break.")
2525
cheatcode = True
26-
print("[NOTE]: Cheat code registered.")
26+
console.print("[NOTE]: Cheat code registered.")
2727
input("Press enter to continue...")
2828
elif argv == "reset-data":
2929
db["first_time"] = True
3030
db["stage"] = 1
3131
with open('save.json', 'w') as f:
3232
json.dump(db, f)
33-
print("[NOTE]: Your data has been reset.")
33+
console.print("[NOTE]: Your data has been reset.")
3434
exit()
3535
elif argv == "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")
3737
exit()
3838
else:
39-
print("[ERROR]: Why did you try?")
39+
console.print("[ERROR]: Why did you try?")
4040

4141
except KeyError:
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?")
4343
exit()
4444
except IndexError:
45-
print("[NOTE]: Cheat code bypassed.")
45+
console.print("[NOTE]: Cheat code bypassed.")
4646

4747
if not db["first_time"]:
4848
pass
@@ -71,74 +71,74 @@ def climb(self):
7171
if not self.alive:
7272
return False
7373

74-
print(f"Press '{self.current_key}' to climb!")
74+
console.print(f"Press '{self.current_key}' to climb!")
7575
key = getkey()
7676
if key == self.current_key:
7777
self.position += 1
7878
if self.position > self.max_height:
7979
self.position = self.max_height
80-
os.system(clear)
80+
console.clear()
8181
if self.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.")
8383
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.")
8585
elif key == keys.ESC:
8686
return False
8787
else:
8888
fall_distance = 1
8989
if self.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!")
9292
self.alive = False
9393
return False
9494
else:
9595
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}")
9898

9999
self.current_key = random.choice(self.keys)
100100
return True
101101

102102
def climb():
103103
# Usage example
104104
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!")
110110

111111
while climber.position < climber.max_height and climber.alive:
112112
if not climber.climb():
113113
break
114114

115115
if climber.position >= climber.max_height:
116-
print("Congratulations! You reached the top!")
116+
console.print("Congratulations! You reached the top!")
117117
return True
118118
else:
119-
print("Game Over. You died from falling.")
119+
console.print("Game Over. You died from falling.")
120120
return False
121121

122122

123-
os.system(clear)
124-
print("[NOTE]: Successfully launched game.")
123+
console.clear()
124+
console.print("[NOTE]: Successfully launched game.")
125125

126126
# CODE STARTS HERE
127-
print("WELCOME!")
127+
console.print("WELCOME!")
128128
start = input("Do. \nYou. \nWish. \nTo. \nPlay. \nMy. \nGame? \n[y/n] ").upper()
129129
if "Y" in start:
130130
pass
131131
else:
132-
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?")
133133
with open('save.json', 'w') as f:
134134
json.dump(db, f)
135135
exit()
136-
os.system(clear)
136+
console.clear()
137137

138138

139139
def sequence1():
140-
print("Good. Let's begin.")
141-
print("""
140+
console.print("Good. Let's begin.")
141+
console.print("""
142142
You are at a payphone, and you have a piece of paper reading:
143143
Some of us contain 10 numbers, some of them don't.
144144
The three-digit ones, will not help you at all.
@@ -149,23 +149,23 @@ def sequence1():
149149
And here's the answer: The last digit is a multiple of 3""")
150150
no = int(input("What's the number? "))
151151
if no == 1209444419:
152-
print("Correct. You have survived.")
153-
print(
152+
console.print("Correct. You have survived.")
153+
console.print(
154154
"The door of the locked payphone opens, and you see a cliff before your eyes."
155155
)
156156
elif no == 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.")
160160
with open('save.json', 'w') as f:
161161
json.dump(db, f)
162162
exit()
163163
elif cheatcode:
164164
pass
165165
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.")
169169
with open('save.json', 'w') as f:
170170
json.dump(db, f)
171171
exit()
@@ -175,63 +175,63 @@ def sequence1():
175175

176176

177177
def sequence2():
178-
print(
178+
console.print(
179179
"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."
180180
)
181-
print("You decide to climb.")
181+
console.print("You decide to climb.")
182182
input("Press enter to continue...")
183-
os.system(clear)
183+
console.clear()
184184
climb_result = climb() # Climbing system initation
185185
if climb_result:
186186
pass
187187
elif not climb_result:
188-
print("You. Are. Dead.")
188+
console.print("You. Are. Dead.")
189189
with open('save.json', 'w') as f:
190190
json.dump(db, f)
191191
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()
194194
with open('save.json', 'w') as f:
195195
json.dump(db, f)
196196
db['stage'] = 3
197197

198198

199199
def sequence3():
200-
print(
200+
console.print(
201201
"You reach a treasure area with a pot of gold, but the same phone booth is there."
202202
)
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.")
204204
choice = input("Do you wish to take the gold? Or do you run away? (get gold/run away) ").upper()
205205
if choice == "GET GOLD":
206-
print(
206+
console.print(
207207
"Lucky for you, the phone booth was a prop and did not do anything. You were able to retrieve the gold and win!"
208208
)
209209

210-
print("You. Won.")
210+
console.print("You. Won.")
211211
x = input("Do you wish to save your data [yes/no]? ").upper()
212212
if x == "YES":
213213
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.")
215215
with open('save.json', 'w') as f:
216216
json.dump(db, f)
217217
else:
218218
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!")
220220
with open('save.json', 'w') as f:
221221
json.dump(db, f)
222222
exit()
223223
elif choice == "RUN AWAY":
224-
print(
224+
console.print(
225225
"Had you have known that the phone booth was a prop, you could have actually got the gold."
226226
)
227-
print(
227+
console.print(
228228
"Oblivious to the environment around you, you fall off the cliff")
229-
print("You. Are. Dead.")
229+
console.print("You. Are. Dead.")
230230
with open('save.json', 'w') as f:
231231
json.dump(db, f)
232232
exit()
233233
else:
234-
print(
234+
console.print(
235235
"That's not an option, but the computer recognises that and bans you for cheating. What an idiot you are :/"
236236
)
237237
return False
@@ -248,7 +248,7 @@ def sequence3():
248248
elif stage == 3:
249249
a = sequence3()
250250
if not a:
251-
print(
251+
console.print(
252252
"You are now banned. Because of how good you are, all of your progress has reset. You will have to restart the game."
253253
)
254254
db['stage'] == 1
@@ -262,16 +262,16 @@ def sequence3():
262262
except KeyError:
263263
sequence1()
264264
if db['stage'] == 4:
265-
print("You've won the game already.")
265+
console.print("You've won the game already.")
266266
x = input("Do you wish to keep your data [yes/no]? ").upper()
267267
if x == "YES":
268-
print("Alright then.")
268+
console.print("Alright then.")
269269
with open('save.json', 'w') as f:
270270
json.dump(db, f)
271271
exit()
272272
else:
273273
db['stage'] = 1
274-
print(
274+
console.print(
275275
"Game successfully reset. You will now start from the beginning next time you load."
276276
)
277277
with open('save.json', 'w') as f:

0 commit comments

Comments
 (0)