Need help with a method to randomly lay mines in a minesweeper game

Posted by avatarX on Programmers See other posts from Programmers or by avatarX
Published on 2011-01-10T17:27:20Z Indexed on 2011/01/10 17:59 UTC
Read the original article Hit count: 201

Filed under:

So my Java minesweeper game is represented as a int[][] where -1 represents a mine. When I initialize my game I need to randomly place x amount of mines.

What is an elegant way of doing this? I was thinking of using an ArrayList with the coordinates of each cell, randomly selecting it, changing the state of the int[][] and then removing that Point. This would ensure that no point is selected twice.

Is there a more elegant way of doing this?

© Programmers or respective owner

Related posts about java