-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.py
111 lines (86 loc) · 3.27 KB
/
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
from Interfaces.TileObjectInterface import TileObjectInterface
from Interfaces.HeroInterface import HeroInterface
from GameEngine.MinionDefinition import MinionDefinition
from Interfaces.MinionInterface import MinionInterface
import pygame
pygame.init()
class Game():
def __init__(self) -> None:
pass
def get_tilemap(self):
return self.ui.get_world().get_tilemap()
def start(self):
from UI import UI
self.ui = UI()
from GameEngine.MinionPack import MinionPack
self.minion_pack = MinionPack()
self.spawn_heroes()
def spawn_heroes(self):
from GameEngine.HeroDefinition import LordOfKarak,Thief
from GameEngine.Hero import Hero
self.heroes: list[Hero] = []
self.heroes.append(Hero(LordOfKarak,'Marek'))
self.heroes.append(Hero(Thief,'Katka'))
from GameEngine.Item import Item
from GameEngine.ItemDefinition import Axe,Sword,Key,FrostFist,HealingPortal,MagicBolt
for h in self.heroes:
h.move_to_tile(self.get_tilemap().tiles[0])
h.refresh_move_points()
self.heroes[0].inventory.add_item(Item(Axe))
self.heroes[0].inventory.add_item(Item(FrostFist))
self.heroes[0].inventory.add_item(Item(Key))
self.heroes[0].inventory.add_item(Item(HealingPortal))
self.heroes[0].inventory.add_item(Item(MagicBolt))
self.heroes[0].inventory.add_item(Item(Sword))
self.load_actions()
def choose_minion(self, tile: TileObjectInterface):
arr = self.minion_pack.pick()
if len(arr) == 0:
self.move_to_tile(tile)
else:
if len(arr) == 1:
self.spawn_minion(arr[0],tile)
self.move_to_tile(tile)
else:
pass
def spawn_minion(self, definition: MinionDefinition, tile: TileObjectInterface):
from GameEngine.Minion import Minion
tile.add_placeable(Minion(definition))
def get_current_hero(self):
return self.heroes[0]
def confirm_tile_placement(self, tile: TileObjectInterface):
tile.on_click(self.move_to_tile,tile)
if tile.is_spawn:
self.choose_minion(tile)
else:
self.move_to_tile(tile)
def move_to_tile(self, tile: TileObjectInterface):
self.get_current_hero().move_to_tile(tile)
self.load_actions()
def load_actions(self):
hero = self.get_current_hero()
tile = hero.get_tile()
placeable = tile.get_placeable()
if isinstance(placeable,MinionInterface) and placeable.agressive:
print(placeable.definition)
if hero.get_move_points() <= 0:
self.end_turn()
else:
tile = hero.get_tile()
self.get_tilemap().load_path(tile,1)
def end_turn(self):
hero = self.get_current_hero()
hero.hurt()
for i,h in enumerate(self.heroes):
if i != 0:
self.heroes[i-1] = h
self.heroes[i] = hero
self.refresh_hero(self.heroes[0])
self.load_actions()
def refresh_hero(self, hero: HeroInterface):
hero.refresh_move_points()
def update(self):
self.ui.get_hero_panel().update()
def draw(self):
self.ui.draw()
GAME = Game()