Exemple #1
0
 def launch(self, target):
     totcost = sum((ship(s).cost for s in self.ships.elements()), Counter())
     if not all(v >= totcost.get(k, 0) for k, v in self.planet.storage.items()):
         return
     self.planet.storage -= totcost
     if target is None or not any(s for s in self.ships.values()):
         return
     FleetFlying(self, target)
Exemple #2
0
 def apply_damage(ships, amount):
     while amount > 0:
         countships = sum(ships.values())
         if countships == 0:
             break
         index = random.randrange(countships)
         targetship = next(islice(ships.elements(), index, None))
         amount -= ship(targetship).defence
         ships[targetship] -= 1
     return ships
Exemple #3
0
 def draw_structures(self):
     self.banner.fill(self.color, (0, 100, 400, 100))
     for i, s in enumerate(self.structures):
         s.draw_far(i)
     index = 0
     for f in self.get_battles():
         if f.loc != self:
             continue
         for s, c in f.ships.items():
             for _ in range(c):
                 index += 1
                 pygame.draw.circle(self.banner, ship(s).color, (index * 25, 25), 10)
Exemple #4
0
 def get_builder(self):
     return any(ship(s).build * v for s, v in self.ships.items())
Exemple #5
0
 def get_power(self):
     return sum(ship(s).power * v for s, v in self.ships.items())
Exemple #6
0
 def getinfo(self):
     for i, m in enumerate(metals()):
         yield (
             m.name,
             "{:>4}/{:>4.0f}".format(sum(ship(s).cost.get(m, 0) for s in self.ships), self.planet.storage[m]),
         )