-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathlevel_loader.py
More file actions
60 lines (45 loc) · 1.73 KB
/
level_loader.py
File metadata and controls
60 lines (45 loc) · 1.73 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
from pythonwarrior.floor import Floor
# These are used dynamically via unit_to_constant
from pythonwarrior.units.archer import Archer
from pythonwarrior.units.captive import Captive
from pythonwarrior.units.golem import Golem
from pythonwarrior.units.sludge import Sludge
from pythonwarrior.units.thick_sludge import ThickSludge
from pythonwarrior.units.wizard import Wizard
from pythonwarrior.units.base import UnitBase
from pythonwarrior.units.warrior import Warrior
class LevelLoader(object):
def __init__(self, level):
self.floor = Floor()
self.level = level
self.level.floor = self.floor
def description(self, desc):
self.level.description = desc
def tip(self, level_tip):
self.level.tip = level_tip
def clue(self, level_clue):
self.level.clue = level_clue
def time_bonus(self, bonus):
self.level.time_bonus = bonus
def ace_score(self, score):
self.level.ace_score = score
def size(self, width, height):
self.floor.width = width
self.floor.height = height
def stairs(self, x, y):
self.floor.place_stairs(x, y)
def unit(self, a_unit, x, y, facing="north", func=None):
if not isinstance(a_unit, UnitBase):
a_unit = self._unit_to_constant(a_unit)()
self.floor.add(a_unit, x, y, facing)
if func:
func(a_unit)
return a_unit
def warrior(self, *args, **kwargs):
a_func = kwargs.get('func', None)
warrior = Warrior(self.level)
return self.level.setup_warrior(self.unit(warrior, *args, func=a_func))
@staticmethod
def _unit_to_constant(name):
camel = "".join([x.capitalize() for x in str(name).split('_')])
return eval(camel)