Skip to content

Instantly share code, notes, and snippets.

@mukeshsolanki
Created May 27, 2022 05:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mukeshsolanki/5985e08fcd609d6182c552d9598f8baa to your computer and use it in GitHub Desktop.
Save mukeshsolanki/5985e08fcd609d6182c552d9598f8baa to your computer and use it in GitHub Desktop.
val hasReachedLeftEnd =
it.snake.first().first == 0 && it.currentDirection == SnakeDirection.Left
val hasReachedTopEnd =
it.snake.first().second == 0 && it.currentDirection == SnakeDirection.Up
val hasReachedRightEnd =
it.snake.first().first == BOARD_SIZE - 1 && it.currentDirection == SnakeDirection.Right
val hasReachedBottomEnd =
it.snake.first().second == BOARD_SIZE - 1 && it.currentDirection == SnakeDirection.Down
if (hasReachedLeftEnd || hasReachedTopEnd || hasReachedRightEnd || hasReachedBottomEnd) {
snakeLength = 2
onGameEnded.invoke()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment