-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlevels.py
51 lines (38 loc) · 1.13 KB
/
levels.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
from abc import abstractmethod
class AbstractLevel:
@abstractmethod
def fieldSize(self):
pass
@abstractmethod
def units(self):
pass
@abstractmethod
def isGameOver(self, players):
pass
@abstractmethod
def nextLevel(self):
return "default"
@abstractmethod
def name(self):
return "default"
def onBombed(self, player, unit, enemy):
pass
def check(condition):
""" Decorators factory for check game over conditions"""
def checkDecorator(func):
""" Decorator. Check condition first and original function second """
def checkCondition(self, player):
return condition(self, player) or func(self, player)
return checkCondition
return checkDecorator
class LevelsFactory:
levels = {}
nextLevel = "default"
def __init__(self):
import simplelevel
def create(self, levelName):
if levelName in self.levels.keys():
return self.levels[levelName]
return self.levels["default"]
def next(self, currentLevel):
return self.levels[currentLevel.nextLevel()]