I am trying to make a simple minesweeper game in Scala and I am trying to make a method that calls a nested method for randomly placing mines into the grid.
I am using the ofDim method on the Array to make it multi-dimensional which works great, until I specify it as the methods return type. The error I get is:
type ofDim is not a member of Object Array
The code is as follows:
class GridBuilder(x:Int, y:Int, mines:Int) {
def generateGrid: Array.ofDim[String](x, y) = {
def placeMines(mineLocations: Array.ofDim[String](x, y)): Array.ofDim[String](x, y) = {
val xcoord = Random.nextInt(x)
val ycoord = Random.nextInt(y)
if (mineLocations.count(_ == "Bomb") == mines)
mineLocations
else if (mineLocations(xcoord) (ycoord) contains "Mine")
placeMines(mineLocations)
else
placeMines(mineLocations(xcoord)(ycoord) = "Mine")
}
placeMines(new Array.ofDim[String](x, y))
}
}
I haven't found anything about returning multi-dimensional arrays anywhere. Is this possible in Scala? What am I missing here?