I am trying to make a primitive minesweeper game, my program has two classes, one of which is Point, that is supposed to be made into an array of objects.
public Point(int x, int y, int status, int contents)
Those are the values that it takes, an object of a sort is created. Then, i have to get an array of those objects in specified size^2 that is set by the user. After that, i take the regular size and assign a Game Field instance, which supposedly creates a 2d array which then is further initialised..
Long story short, i want the 2d array take values of each object from my 1d array as each point.
Now, i'll try show what i want and what do i have on hands.
public GameField(int size, int treasures, int bullets)
these are the values field takes, they are being switched based on difficulty the user chooses.
public void Initialize(int size, int treasures, int bullets)
{
for (int i = 0; i < size; i++)
{
for (int j = 0; j < size; j++)
{
int[i, j] field = new Point(....); //How?
}
}
}
My problem appears here. The point has two other attributes that show its status on field and contents (treasure, enemy or blank) that are also being randomised. I had an idea of ditching the coordinates part and make the player call a point by its index in array of objects but that really defeats the meaning of "Point", unless. I need an advice on how to make it make sense.
Something like this seems to be what you are looking for. It is skeleton code to initialize the game field with the specified number of treasures and bullets, and leave the remaining cells blank.
The result is all the cells are hidden
But if I run with
Status status = Status.Shown;in the constructor forGridthen the result is (as expected) random placement of treasures and bullets.