Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1.  
  2. def newLoc(): Unit = {
  3. var nrFreeSpots : Int = 0
  4. for (j <- 0 until nrRows; i <- 0 until nrColumns) {
  5. var foundSnake : Boolean = false
  6. for (k <- PlayerSnake.x.indices) {
  7. if (PlayerSnake.x(k) == i && PlayerSnake.y(k) == j) foundSnake = true
  8. }
  9. if (!foundSnake) nrFreeSpots += 1
  10. }
  11. if (nrFreeSpots == 0) {
  12. x = -1
  13. y = -1
  14. return
  15. }
  16. val r: Int = randomGen.randomInt(nrFreeSpots)
  17. var count : Int = 0
  18. for (j <- 0 until nrRows; i <- 0 until nrColumns) {
  19. var foundSnake : Boolean = false
  20. for (k <- PlayerSnake.x.indices) {
  21. if (PlayerSnake.x(k) == i && PlayerSnake.y(k) == j) foundSnake = true
  22. }
  23. if (!foundSnake) {
  24. if (count == r) {
  25. x = i
  26. y = j
  27. return
  28. }
  29. count += 1
  30. }
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement