-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
183 lines (156 loc) Β· 6.16 KB
/
Copy pathmain.py
File metadata and controls
183 lines (156 loc) Β· 6.16 KB
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
import random, os
import time # Added time for dramatic pauses
class Student:
def __init__(self, name, energy, location_x, location_y, stamina, inventory):
self.name = name
self.energy = energy
self.location_x = location_x
self.location_y = location_y
self.stamina = stamina
self.inventory = inventory
self.journal = "Welcome to DTU! Adventure awaits."
def study(self):
if self.location_x == -2 and self.location_y == 0:
self.energy -= 10
self.journal = f"{self.name} studied hard! Energy -10."
else:
self.journal = "You can't study here! Go to the Library (-2, 0) π¦§"
def eat_maggie(self):
if self.location_x == 2 and self.location_y == 3:
self.energy += 5
self.journal = "Yummy Maggie! Energy +5. π¦"
else:
self.journal = "No food here! Go to Canteen (2, 3)"
def walk(self, direction):
new_x = self.location_x
new_y = self.location_y
if direction == "^[[A" or direction == "w":
new_y += 1
elif direction == "^[[B" or direction == "s":
new_y -= 1
elif direction == "^[[D" or direction == "a":
new_x -= 1
elif direction == "^[[C" or direction == "d":
new_x += 1
# --- BOSS BATTLE ZONE (0, 5) ---
if new_x == 0 and new_y == 5:
if "Key" in self.inventory:
# 1. Move Player
self.location_x = new_x
self.location_y = new_y
# 2. CLEAR SCREEN FOR BATTLE
os.system('clear')
print("\n\n")
print("π " * 10)
print(" A WILD PROFESSOR APPEARS! ")
print("π " * 10)
print("\nProfessor: 'So... you want to hack the server?'")
time.sleep(1)
print("Professor: 'Answer this to pass...'\n")
print("β QUESTION: What comes after 'check_surroundings' in our loop?")
print(" a) draw_world")
print(" b) input")
print(" c) exit")
# 3. WAITING FOR ANSWER
ans = input("\nYour Answer (a/b/c): ").lower()
if ans == "a":
self.journal = "π CORRECT! You hacked the server. DIPLOMA RECEIVED!"
self.inventory.append("π DIPLOMA")
else:
self.energy -= 50
self.journal = "β WRONG! The Professor fails you. Energy -50."
else:
self.journal = "π« LOCKED! You need a Key to enter here."
else:
self.location_x = new_x
self.location_y = new_y
self.energy -= 0.1
def check_surroundings(self):
# FIXED: Using self.journal instead of print
if self.location_x == -5 and self.location_y == 5:
increment = random.random()
self.stamina += increment
self.journal = f"β³οΈ Sports Complex! Stamina +{increment:.2f}"
elif self.location_x == 2 and self.location_y == 3:
self.journal = "π½οΈ Smells like Maggie... (Type 'eat')"
elif self.location_x == -2 and self.location_y == 0:
self.journal = "π Library Silence... (Type 'std')"
elif self.location_x == 0 and self.location_y == 0:
self.journal = "β³ Hostel Sweet Hostel."
# Note: We removed the 'validation' call because walk() handles it now!
# inventory
inventory = []
# student
character = Student("JOY", 100, 0, 0, 50, inventory)
# pickup function
def pick_up(character):
if character.location_x == 3 and character.location_y == -3:
if "Python Book" not in character.inventory:
character.inventory.append("Python Book")
character.journal = "π You picked up the Python Book!"
else:
character.journal = "You already have this book, nerd."
elif character.location_x == -2 and character.location_y == 4:
if "Key" not in character.inventory:
character.inventory.append("Key")
character.journal = "ποΈ You picked up the Key!"
else:
character.journal = "You already have this Key."
elif character.location_x == 1 and character.location_y == 1:
if "FootBall" not in character.inventory:
character.inventory.append("FootBall")
character.journal = "β½οΈ You picked up the FootBall!"
else:
character.journal = "You already have this."
# map
def draw_world(character):
os.system('clear')
print(f"Nameπ€: {character.name} | Energyπ: {character.energy:.2f} | Loc: ({character.location_x},{character.location_y})")
print(f"Inventory: {character.inventory}")
print("|--------------------------------------------------------------------------|")
for Y in range(5, -6, -1):
for X in range(-5, 6):
if X == character.location_x and Y == character.location_y:
print("π€ ", end="")
elif X == 2 and Y == 3:
print("π", end="")
elif X == -2 and Y == 0:
print("π", end="")
elif X == -5 and Y == 5:
print("β³οΈ", end="")
elif X == 0 and Y == 0:
print("π«", end="")
elif X == 3 and Y == -3:
print("π", end="")
elif X == -2 and Y == 4:
print("ποΈ ", end="")
elif X == 1 and Y == 1:
print("β½οΈ", end="")
elif X == 0 and Y == 5:
print("π’", end="")
else:
print("π©", end="")
print("")
print("|--------------------------------------------------------------------------|")
# THE JOURNAL DISPLAY
print(f"π JOURNAL: {character.journal}")
print("|--------------------------------------------------------------------------|")
# movement key list
movement = ["w", "a", "s", "d", "up", "down", "left", "right", "^[[A", "^[[B", "^[[C", "^[[D"]
# loop
while True:
# 1. Update Logic
character.check_surroundings()
pick_up(character)
# 2. Draw Screen
draw_world(character)
# 3. Wait for Input
command = input("Enter command: ").lower()
if command == "exit":
break
elif command == "std":
character.study()
elif command in movement:
character.walk(command)
elif command == "eat":
character.eat_maggie()