Beispiel #1
0
 def _layerInit(self, scene):
     self.scene = scene
     
     hadCannons = False
     self.playerMap = {}
     for p in self.scene.app.players:
         if not p.inGame:
             continue
         self.playerMap[p] = FirePhaseData(self.scene.board)
         
     # Make sure anyone CAN fire.  Also, restore the health of all TileObjs.
     for t in self.scene.board.tileObjs:
         t.health = t.HEALTH
         if not isinstance(t, Cannon):
             continue
         
         tile = self.scene.board.get(t.x, t.y)
         if tile.isTerritory:
             self.playerMap[tile.owner].cannons.append(t)
             hadCannons = True
             
     if not hadCannons:
         # Skip this phase, go straight to rebuilding - no one had cannons!
         self.remove()
         # Avoid circular dependency here
         from rebuildLayer import RebuildLayer
         self.scene.addLayer(RebuildLayer())
         return
             
     self.hasUpdated = False # Wait for ticker to clear before firing
     GamePhaseLayer._layerInit(self, scene)
Beispiel #2
0
 def _layerInit(self, scene):
     self.scene = scene
     
     # Players might build over there territory, so remove that so as not
     # to confuse whether or not a player can place any cannons
     self.scene.board.territoryCheck()
     
     baseCannons = 1
     if self.scene.isFirstRound:
         # Extra cannon for round one
         baseCannons = 2
     
     castlesPerPlayer = {}
     for p in self.scene.app.players:
         castlesPerPlayer[p] = 0
         
     for to in self.scene.board.tileObjs:
         if not isinstance(to, Castle):
             continue
         t = self.scene.board.get(to.x, to.y)
         if t.isTerritory:
             castlesPerPlayer[t.owner] += 1
      
     hadCannons = False
     self.placer = pyglet.sprite.Sprite(TileObjectImages.UNKNOWN)
     self.label = pyglet.text.Label(anchor_x = 'center', anchor_y = 'center')
     self.label.bold = True
     self.placeInfo = {}
     for p in self.scene.app.players:
         if p.inGame:
             self.placeInfo[p] = PlaceCannonInfo(p,
                     baseCannons + castlesPerPlayer[p])
             if not self._checkPlayerSpace(p):
                 self.placeInfo[p].numCannons = 0
             else:
                 hadCannons = True
     
     # No cannons to place?  Skip this phase
     if not hadCannons:
         self.remove()
         self.scene.addLayer(FirePhase())
         return
      
     GamePhaseLayer._layerInit(self, scene)       
Beispiel #3
0
    def onAction(self, player, action):
        if not player.inGame:
            return

        if action == Actions.BTN1:
            x = player.inGame.x
            y = player.inGame.y
            t = self.board.get(x, y)
            t.setType((t.type + 1) % TileTypes.MAX)
        else:
            return GamePhaseLayer.onAction(player, action)
        return True
Beispiel #4
0
 def onAction(self, player, action):
     if not player.inGame:
         return False
     
     if action == Actions.BTN1:
         pi = self.placeInfo[player]
         obj = pi.obj
         if pi.numCannons >= obj.cannonCount:
             x = player.inGame.x
             y = player.inGame.y
             if obj.canPlace(player, self.board, x, y):
                 c = obj(x, y)
                 self.board.addObj(c)
                 AllSounds.WALL.play(minTime = 0.3, maxInstances = 3)
                 pi.numCannons -= obj.cannonCount
                 if pi.numCannons > 0 and not self._checkPlayerSpace(player):
                     pi.numCannons = 0
     else:
         return GamePhaseLayer.onAction(self, player, action)
     return True