Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.69 KB | None | 0 0
  1.   def move(): Unit = {
  2.     val someSnake = game.players.find(p => p.snake.headColor != headColor)
  3.  
  4.     if (someSnake.isDefined) {
  5.       val nbr_snake = someSnake.get.snake
  6.  
  7.       if (isHeadCollision(nbr_snake)) {
  8.         dir match {
  9.           case North | South => dir = East; nbr_snake.dir = West
  10.           case East | West => dir = North; nbr_snake.dir = South
  11.           case _ =>
  12.         }
  13.       }
  14.  
  15.       if (isTailCollision(nbr_snake)) game.enterGameOverState()
  16.  
  17.     }
  18.     if (!isOccupyingBlockAt(body.head + dir)) (body.head + dir) +=: body else game.enterGameOverState()
  19.  
  20.     if (body.size > initTailSize) body -= body.last
  21.  
  22.  
  23.   } // väx och krymp enl. regler; action om äter frukt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement