forked from darrenks/cloneworld
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entity.py
executable file
·71 lines (56 loc) · 1.87 KB
/
entity.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
'''
@authors: Richard B. Johnson
'''
from abc import ABCMeta, abstractmethod
from action import Action
from utility import *
class Entity:
__metaclass__ = ABCMeta
__idCounter = 1
@classmethod
def __init__(self, x=0, y=0, f=Action.South):
self.setLocation(x, y)
self.startX = x
self.startY = y
self.facing = f
self.active = True
self.ID = Entity.__idCounter
Entity.__idCounter += 1
@classmethod
def setActive(self, active):
self.active = active
@classmethod
def setLocation(self, x, y):
self.X = x
self.Y = y
@classmethod
def setFacing(self, f):
self.facing = f
@classmethod
def turnLeft(self):
self.facing = Action.turnLeft(self.facing)
@classmethod
def turnRight(self):
self.facing = Action.turnRight(self.facing)
@classmethod
def turnAround(self):
self.facing = Action.turnAround(self.facing)
@classmethod
def getNextStep(self):
x, y = Action.nextStep(self.facing)
return self.X + x, self.Y + y
@abstractmethod
def getNextMove(self):
debug.raiseNotDefined()
def __str__(self):
s = "%s %i\n"%(col("Unique ID"), self.ID)
s += "%s %i, %i\n"%(col("Start"), self.startX, self.startY)
s += "%s %i, %i\n"%(col("Location"), self.X, self.Y)
s += "%s %s\n"%(col("Facing"), Action.toStr(self.facing))
t = "active" if self.active else "inactive"
s += "%s %s\n"%(col("Status"), t)
return s
def brief(self):
t = "active" if self.active else "inactive"
return "ID %i, Loc (%i, %i), %s, %s"%(
self.ID, self.X, self.Y, Action.toStr(self.facing), t)