Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def newLoc(): Unit = {
- var nrFreeSpots : Int = 0
- for (j <- 0 until nrRows; i <- 0 until nrColumns) {
- var foundSnake : Boolean = false
- for (k <- PlayerSnake.x.indices) {
- if (PlayerSnake.x(k) == i && PlayerSnake.y(k) == j) foundSnake = true
- }
- if (!foundSnake) nrFreeSpots += 1
- }
- if (nrFreeSpots == 0) {
- x = -1
- y = -1
- return
- }
- val r: Int = randomGen.randomInt(nrFreeSpots)
- var count : Int = 0
- for (j <- 0 until nrRows; i <- 0 until nrColumns) {
- var foundSnake : Boolean = false
- for (k <- PlayerSnake.x.indices) {
- if (PlayerSnake.x(k) == i && PlayerSnake.y(k) == j) foundSnake = true
- }
- if (!foundSnake) {
- if (count == r) {
- x = i
- y = j
- return
- }
- count += 1
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement