If we run outof places to place barbarians at the start of the game, of if we randomly select the same tile twice, the gam wil not crash

This commit is contained in:
Yair Morgenstern
2018-06-10 17:30:49 +03:00
parent b31e7ccc3d
commit 98932473eb

View File

@ -31,7 +31,14 @@ class GameStarter(){
gameInfo.setTransients() // needs to be before placeBarbarianUnit because it depends on the tilemap having its gameinfo set
(1..5).forEach { gameInfo.placeBarbarianUnit(freeTiles.toList().getRandom()) }
(1..5).forEach {
val freeTilesList = freeTiles.toList()
if(freeTilesList.isNotEmpty()){
val placedTile = freeTilesList.getRandom()
gameInfo.placeBarbarianUnit(placedTile)
freeTiles.remove(placedTile)
}
}
return gameInfo
}