-
Notifications
You must be signed in to change notification settings - Fork 0
/
units.py
43 lines (35 loc) · 1.19 KB
/
units.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
class unitBase:
def __init__(self, dest: tuple, currPos: tuple):
self.currPos = currPos
self.dest = dest
def setPos(self, pos: tuple):
self.currPos = pos
def setDest(self, pos: tuple):
self.dest = pos
def getNext(self):
deltaX = self.currPos[0] - self.dest[0]
deltaY = self.currPos[1] - self.dest[1]
if deltaX !=0:
xChange = (-1 * deltaX) / abs(deltaX)
yChange = 0
else:
xChange = 0
if deltaY != 0:
yChange = (-1 * deltaY) / abs(deltaY)
else:
yChange = 0
return (int(self.currPos[0] + xChange), int(self.currPos[1] + yChange))
def atDestination(self):
return self.currPos == self.dest
class Worker(unitBase):
def __init__(self, dest: tuple, currPos: tuple):
super().__init__(dest, currPos)
class Army(unitBase):
def __init__(self, dest: tuple, currPos: tuple):
super().__init__(dest, currPos)
self.hp = 100
self.currTileResist = 0
def updateHP(self, hp: int):
self.hp = hp
def updateRes(self, res: float):
self.currTileResist = res