forked from cherryunix/jn-blacktech
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fleet.py
53 lines (45 loc) · 1.37 KB
/
fleet.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
from ship import Ship
class Fleet:
def __init__(self, game, id_, ships):
self.game = game
self.id = id_
self.ships = ships
self.expedition = None
for ship in self.ships:
ship.fleet = self
def isReady(self):
if not self.ships:
return False
for ship in self.ships:
if not ship.isIdle() or ship.isBadlyBroken() or not ship.isFilled():
return False
return True
def getShipHp(self):
return [ ship.hp for ship in self.ships ]
def setRunningExpedition(self, exp):
self.expedition = exp
def fill(self):
if self.expedition is not None:
return False
for ship in self.ships:
if not ship.isFilled():
self.game.fill(self)
for ship in self.ships:
ship.setFilled()
return True
return True
def changeShips(self, ships):
if self.expedition is not None:
return False
self.game.changeShips(self, ships)
for ship in self.ships:
ship.fleet = None
for ship in ships:
ship.fleet = self
self.ships = ships
return True
def printHp(self):
ret = ''
for ship in self.ships:
ret += '%d/%d ' % (ship.hp, ship.maxHp)
return ret