def placeSnake(self): playerBoard = self.currentPlayer.getGameBoard() board = BoardUtils.clone(playerBoard.getBoard()) row, column = BoardUtils.rowCount(board) // 2 - 1, BoardUtils.columnCount(board) // 2 board, snake_coordinates = GameService.insertSnake(board, row, column) playerBoard.setBoard(board) self.currentPlayer.snake.addCoordinates(snake_coordinates)
def moveSnake(self, n): gameBoard = self.currentPlayer.getGameBoard() direction = self.currentPlayer.snake.getDirection().lower() directionRowIndex, directionColumnIndex = BoardUtils.DIRECTIONS.get(direction) for i in range(n): board = BoardUtils.clone(gameBoard.getBoard()) row, column = self.currentPlayer.snake.getHead() GameService.validateMove(board, row + directionRowIndex, column + directionColumnIndex) eatApple = False if board[row + directionRowIndex][column + directionColumnIndex] == Constants.APPLE: eatApple = True self.moveHead(board, row + directionRowIndex, column + directionColumnIndex, eatApple) gameBoard.setBoard(board)