-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
222 lines (152 loc) Β· 5.64 KB
/
main.py
File metadata and controls
222 lines (152 loc) Β· 5.64 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
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
import os
os.system('')
from items import iron_sword, wooden_staff
from entities import Character, hero1, hero2,hero3, slime, dragon, wizard
from spells import fireball, icebolt, light_heal
from items.create_db import create_db, add_item, show_items
from save.save_system import save_game, load_game
from maps.map_manager import MapManager
# Clears Screen
os.system('cls')
def setup_party(party):
hero3.learnt_spells.append(fireball)
hero3.learnt_spells.append(icebolt)
hero3.learnt_spells.append(light_heal)
hero2.learnt_spells.append(light_heal)
hero1.equip(iron_sword)
hero2.equip(iron_sword)
party.add_member(hero1)
party.add_member(hero2)
party.add_member(hero3)
party.add_item_to_inventory('Light Healing Potion', 5)
party.add_item_to_inventory('Mid Revive', 2)
from entities.party import Party
party = Party()
from maps.overworld import Map
from utils.getch import getch
print('Press any key to continue...')
getch()
def clear_screen_ansi():
print("\033[H\033[J", end='')
controls = { 'Q': 'Quit',
'M': 'Spell Menu',
'O': 'Overworld Spells',
'L': 'Add Light Healing Potion & Mid Revive',
'I': 'Inventory Menu π'}
debug_controls = { 'G': 'Add Gold'}
def print_controls():
print('Controls:')
print('Q - Quit')
print('M - Spell Menu')
print('O - Overworld Spells')
print('I - Inventory Menu π')
print('F - Use Item π')
print('P - Show Party Details')
print('9 - Save Game, 0 - Load Game')
# Debug controls
print('B - Test Battle', end=' ') #Debug
print('G - Add Gold', 'K - Kill Hero1 and Hero2') #Debug
print('E - Gain Exp', end=' ') #Debug
print('R - Reset Enemy', end= ' ') #Debug
print('L - Add Light Healing Potion & Mid Revive') #Debug
print('Y - Save Map') #Debug
def show_gold(party):
gold_str = str(party.gold)
border = '-------' + '-' * len(gold_str)
print(border)
print(f'|{gold_str} Gold|')
print(border)
from battle.system import BattleSystem
def run() -> None:
while True:
game_map = map_manager.current_map
clear_screen_ansi()
party.show_party()
show_gold(party)
map_manager.current_map.display_map()
print('Message Board: ')
print_controls()
move = getch().upper()
if move == 'Q':
break
if move == '9':
save_game(map_manager, party)
print('Game saved!')
input('Press Enter to continue...')
if move == '0':
print('Loading Game is currently not implemented correctly. Do you want to continue? (Y/N)')
if getch().upper() == 'Y':
load_game(map_manager, party)
if move == 'C':
map_manager.switch_map('Town')
if move == 'P':
party.show_all_details()
input('Press Enter to continue...')
if move == 'K':
hero1.take_damage(100000)
hero2.kill()
if move == 'Y':
game_map.save_map_to_file('map.txt')
print('Map saved to map.txt')
input('Press Enter to continue...')
if move == 'R':
slime.reset()
input()
if move == 'M':
from ui.spell_menu import test_pick_spells
test_pick_spells(hero1, slime)
input('Press Enter to continue...')
if move == 'O':
from ui.spell_menu import overworld_spells
overworld_spells(party)
if move == 'L':
party.add_item_to_inventory('Light Healing Potion', 5)
party.add_item_to_inventory('Mid Revive', 5)
input()
if move == 'I':
from ui.inventory_menu import show_inventory_menu
show_inventory_menu(hero1, party)
input('Press Enter to continue...')
if move == 'G':
party.add_gold(50)
getch()
if move == 'F':
BattleSystem(party, slime).victory()
if move == 'E':
hero1.gain_exp(1000)
hero2.gain_exp(2000)
input()
if move == '2':
BattleSystem(party, wizard).start_battle()
if move == '3':
BattleSystem(party, dragon).start_battle()
tile = map_manager.current_map.map_data[
map_manager.current_map.player_y
][
map_manager.current_map.player_x
]
if tile.name == 'town':
print('You entered a town!')
map_manager.switch_map('Town', (7,6))
input('Press Enter to continue...')
elif tile.name == "shop" and map_manager.current_map_name == "Town":
print("π You entered the shop!")
input()
elif map_manager.current_map_name == "Town" and map_manager.current_map.player_x == 7 and map_manager.current_map.player_y == 7:
map_manager.switch_map('overworld', (10,3))
if move == 'B':
print('BATTLE')
enemy = slime
BattleSystem(party, enemy).start_battle()
result = game_map.move_player(move)
if result['event'] == 'enemy_encounter':
enemy = result['enemy']
print(f'You encountered a {enemy.name}!')
BattleSystem(party, enemy).start_battle()
if __name__ == '__main__' :
setup_party(party)
map_manager = MapManager()
map_manager.load_map('overworld', 'data/maps/map.txt', spawnable_enemies={slime: 0.6, dragon: 0.03, wizard: 0.1})
map_manager.load_map('Town', 'data/maps/townmap.txt')
map_manager.switch_map('overworld')
run()