-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmonster.py
executable file
·49 lines (35 loc) · 1.25 KB
/
monster.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
'''
@authors: Richard B. Johnson
'''
from entity import Entity, Action
from utility import *
class Monster(Entity):
pattern = {}
def __init__(self, type, x=0, y=0, f=Action.South):
Entity.__init__(x, y, f)
self.type = type
if debug.active: print self
def standStill(self, isWall):
return self.X, self.Y
def moveBackAndForth(self, isWall):
x, y = self.getNextStep()
if (isWall(x, y) == True):
self.turnAround()
x, y = self.getNextStep()
if (isWall(x, y) == True):
return self.standStill(isWall)
return x, y
pattern["ball"] = moveBackAndForth
pattern["bat"] = standStill
pattern["ant"] = standStill
pattern["ship"] = standStill
def getNextMove(self, isWall):
nextMove = Monster.pattern[self.type]
return nextMove(self, isWall)
def __str__(self):
s = "Monster Information:\n"
s += Entity.__str__(self)
s += "%s %s\n"%(col("Type"), self.type)
return s
def brief(self):
return Entity.brief(self) + ", %s"%(self.type)