Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.81 KB | None | 0 0
  1.   def move(): Unit = {
  2.  
  3.     grow()
  4.     shrink()
  5.  
  6.     if (body.tail.contains(body.head)) game.enterGameOverState()
  7.  
  8.     game.entities.foreach{
  9.       ent => if (ent.isOccupyingBlockAt(body.head)) {
  10.         ent match {
  11.           case c:CanTeleport => grow(); ent.reset()
  12.           case _ =>
  13.         }
  14.       }
  15.     }
  16.     if (game.players.length > 1) {
  17.       val other_snake = game.players.find(p => p.snake.headColor != headColor).get.snake
  18.  
  19.       if (isHeadCollision(other_snake)) {
  20.         dir match {
  21.           case North | South => dir = East; other_snake.dir = West
  22.           case East | West => dir = North; other_snake.dir = South
  23.           case _ =>
  24.         }
  25.       }
  26.  
  27.       if (isTailCollision(other_snake)) game.enterGameOverState()
  28.   }
  29.  
  30.   } // väx och krymp enl. regler; action om äter frukt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement