Win condition in minesweeper
Hello, i am new to unity and i tried to make simple game of minesweeper. It works pretty well, except winning. As it is now player wins every time he click on part that is not mine. I need to make it so player wins only after he uncovered all elements that are not mines. I have two scripts, grid.cs and element.cs. This part in grid.cs should find if all non-mines were uncovered:
public static bool isFinished() {
foreach (Element elem in elements)
if (elem.isCovered() && !elem.mine)
return false;
return true;
}
And this part in element.cs should tell you if you lost or won:
void OnMouseUpAsButton() {
if (mine) {
Grid.uncoverMines();
print("game over");
}
else {
int x = (int)transform.position.x;
int y = (int)transform.position.y;
loadTexture(Grid.adjacentMines(x, y));
Grid.FFuncover(x, y, new bool[Grid.w, Grid.h]);
if (Grid.isFinished())
print("win");
}
}
Sorry if its something very trivial, like i said i just started. Thank you for your help
Please format your pasted code with the 101010 button.
Otherwise an okay question so I'll do this on your behalf.
Sorry it took so long to go through moderation.
isFinished is returning in the first check. you could return within the loop when a non win condition has been found and return win after the loop, which will only happen when no non win condition has been met
Your answer
Follow this Question
Related Questions
Which version of Unity is more suitable for a pure 2D mobile game for a newbie? 0 Answers
I'm making a 2D game with no levels like flappy bird. How many scenes will I need? 1 Answer
platformEffector2D pushing character upward,Platform Effector 2D pushing character if Keypressed 0 Answers
2D topdown turn based, some hints to get started please 1 Answer
how to tell what scene the player was previously in 1 Answer