Пример #1
0
    def move(self, direction, real=False):
        """
        Move from the current square in the specified direction if possible
        Return T if the move was valid and occurred successfully

        The client simply prints out the move
        The server deals with actually updating the world state
        """

        currY = self._square.getRow()
        currX = self._square.getColumn()

        destX = currX
        destY = currY

        if direction == gameSquare.GameSquare.DIRECTION_UP:
            destY = destY - 1
        elif direction == gameSquare.GameSquare.DIRECTION_DOWN:
            destY = destY + 1
        elif direction == gameSquare.GameSquare.DIRECTION_LEFT:
            destX = destX - 1
        elif direction == gameSquare.GameSquare.DIRECTION_RIGHT:
            destX = destX + 1

        destSquare = gameSquare.findSquareByLocation(destX,destY)

        # only allow orthogonal moves of 1 square
        if not self.canTakeAction() or destSquare==None or not destSquare.isEmpty() or not ((currX - destX == 0 and abs(currY - destY) == 1) or (abs(currX - destX) == 1 and currY - destY == 0)):
            return False

        if real:
            print('MOVE {0} {1}'.format(self._id,direction))
        return True
Пример #2
0
    def checkMove(self, direction):
        """
        Check if the entity is able to move in the specified direction
        """
        currY = self._square.getRow()
        currX = self._square.getColumn()

        destX = currX
        destY = currY

        if direction == gameSquare.GameSquare.DIRECTION_UP:
            destY = destY - 1
        elif direction == gameSquare.GameSquare.DIRECTION_DOWN:
            destY = destY + 1
        elif direction == gameSquare.GameSquare.DIRECTION_LEFT:
            destX = destX - 1
        elif direction == gameSquare.GameSquare.DIRECTION_RIGHT:
            destX = destX + 1

        destSquare = gameSquare.findSquareByLocation(destX,destY)

        if destSquare==None or not destSquare.isEmpty() or not destSquare.isPassable():
            return False
        else:
            return True
Пример #3
0
 def move(self, direction):
     """
     Move from the current square in the specified direction if possible
     Return T if the move was valid and occurred successfully
     
     The client simply prints out the move
     The server deals with actually updating the world state
     """
     
     dirTxt = [
         'Invalid',
         'North',
         'South',
         'West',
         'East'
     ]
     
     currY = self._square.getRow()
     currX = self._square.getColumn()
     
     destX = currX
     destY = currY
     
     if direction == gameSquare.GameSquare.DIRECTION_UP:
         destY = destY - 1
     elif direction == gameSquare.GameSquare.DIRECTION_DOWN:
         destY = destY + 1
     elif direction == gameSquare.GameSquare.DIRECTION_LEFT:
         destX = destX - 1
     elif direction == gameSquare.GameSquare.DIRECTION_RIGHT:
         destX = destX + 1
         
     # verify that the square is legal (i.e. on the board)
     if destX < 0 or destX >= len(gameBoard.GameBoard._instance._grid[0]) or destY < 0 or destY >= len(gameBoard.GameBoard._instance._grid):
         return False
         
     destSquare = gameSquare.findSquareByLocation(destX,destY)
     
     # only allow orthogonal moves of 1 square
     if destSquare==None:
         print '[debug] Entity',self._id,'cannot move in direction',dirTxt[direction],'(invalid square)'
         return False
     elif not destSquare.isEmpty():
         print '[debug] Entity',self._id,'cannot move in direction',dirTxt[direction],'(already occupied)'
         return False
     elif not destSquare.isPassable():
         print '[debug] Entity',self._id,'cannot move in direction',dirTxt[direction],'(impassible)'
         return False
     elif not self.canMakeAction():
         return False
         
     print '* Entity',self._id,'moved',dirTxt[direction]
     self._square.clearOccupant()
     destSquare.setOccupant(self)
     self.actionsTaken = self.actionsTaken+1
     
     return True