Ejemplo n.º 1
0
 def move_action(self, grid, player, move):
     if type(move) != str:
         return
     r = player.row
     c = player.col
     cell = grid[r][c]
     if r < 0 or c < 0:
         return Wall.step(cell, self, player, grid, move)
     return cell.step(self, player, grid, move)
Ejemplo n.º 2
0
    def game_move(self, move):
        # Store current location, so if an illegal move is made, it can go back
        y = self.player.row
        x = self.player.col

        # Perform the given move command
        self.player.move(move)

        if (self.player.row < 0 or self.player.col < 0
                or self.player.row >= len(self.grid)
                or self.player.col >= len(self.grid[0])):
            # If the player is on the border and tries to step out of bounds, act as a wall
            # None is used in step as we do not require a cell instance here
            result = Wall.step(None, self)
            self.msg = result[2]
        else:
            # The player did not try step out of bounds, so perform the step
            # command for the cell type that the player went to
            result = self.grid[self.player.row][self.player.col].step(self)

            if len(result) == 3:
                self.msg = result[2]
            else:
                # The player moved onto the cell that does not return a message
                self.msg = ''

        isLegalMove, isEndingMove = result[0], result[1]

        if isLegalMove:
            if isEndingMove:
                # Player landed on finish point (Won game)
                self.moves_made.append(move)
                self.finished = True
            else:
                # Player made a legal move that did not win the game_won
                # i.e. player stepped on air,TP pad, water, start
                self.moves_made.append(move)

        else:
            if isEndingMove:
                # Player stepped on fire and died (Game over)
                self.moves_made.append(move)
                self.finished = True
                self.lost = True
            else:
                # Player walked into a wall, revert back to previous position
                self.player.row = y
                self.player.col = x