public IMineMemento CreateMemento() { var copy = MineBoard.Copy(); return(new MineMemento { State = copy }); }
protected override void Initialize() { initDefaultTexture(); this.IsMouseVisible = true; mineBoard = new MineBoard((GameProperties.GAME_SCREEN_X / 10) / 2, (GameProperties.GAME_SCREEN_Y / 10) / 2, GameProperties.MINES_NUMBER); base.Initialize(); }
public void ZeroCheck() { if (!Board[X, Y].IsBomb) { int c = MineBoard.CountMines(X, Y); UnClick = true; Board[X, Y].BackgroundImage = Properties.Resources.NumberSquareBack; if (c == 0) { CheckSurround(X, Y); } else { NumLabel(c); } } }
private void Box_Click(object sender, System.Windows.Forms.MouseEventArgs e) { try { // Console.WriteLine(UnClick) // Console.WriteLine() if (!UnClick) { if (e.Button == System.Windows.Forms.MouseButtons.Right && !UnClick && (!Done || MineBoard.clickCount() >= (TotalHeight * TotalWidth) - 1)) { Flagged = !Flagged; } if (e.Button == System.Windows.Forms.MouseButtons.Left && (!Done || MineBoard.clickCount() >= (TotalHeight * TotalWidth) - 1)) { UnClick = true; if (IsBomb & !Flagged) { FaceChange?.Invoke(FaceType.Dead, new EventArgs()); BackColor = Color.Red; } else { int c = MineBoard.CountMines(X - 0, Y - 0); // Console.WriteLine(X & "," & Y) if (c == 0 && !Flagged) { CheckSurround(X, Y); } else if ((!Done) || Flagged || MineBoard.clickCount() >= (TotalHeight * TotalWidth) - 1) { //lbl = new Label() { ForeColor = numColours[c - 1], Text = c.ToString(), TextAlign = ContentAlignment.MiddleCenter, Font = new System.Drawing.Font("Arial", 12), Location = new Point(2, -1), BackColor = Color.Transparent, Size = new Size(12, 15), Padding = new System.Windows.Forms.Padding(0), Margin = new System.Windows.Forms.Padding(0) }; NumLabel(c);//this.Controls.Add(lbl); } } } if (!Done) { MouseClick?.Invoke(this, e); } } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
void OnMouseOver() { if (MineAssets.instance.gameWon | MineAssets.instance.gameLost) { return; //If the game is over, return because we shouldn't allow any tiles to be flagged or filled. } if (Input.GetMouseButtonDown(1) || (Input.touchCount > 0 ? Input.GetTouch(0).deltaTime >= 0.8f : false)) //If we right clicked. { flag(); //Flag the selected tile. MineBoard.checkCompletion(); //Then check if we flagged the last mine, and if we did, tell the user that they won. return; } if (Input.GetMouseButtonDown(0)) // || Input.touchCount > 0) //If we left clicked or touched the screen { if (MineAssets.instance.firstClick) //If it's the very first click of the game, we have special rules. { this.mine = false; //We never want the first click to be a mine, so set wherever we clicked to false. //Not only do we make sure the clicked tile isn't a mine, we make sure all adjacent tiles aren't mines either. //This effectively forces a bubble wherever the player decides to start, which should signficantly //reduce chances of the player having to make guesses. //We first check if a tile is on the board, before setting them to not be mines. if ((xpos - 1 >= 0) && (ypos - 1 >= 0)) { MineAssets.instance.tiles[xpos - 1, ypos - 1].mine = false; Debug.Log("(" + (xpos) + "," + (ypos) + ") - (" + (xpos - 1) + "," + (ypos - 1) + ")"); } if (ypos - 1 >= 0) { MineAssets.instance.tiles[xpos, ypos - 1].mine = false; Debug.Log("(" + (xpos) + "," + (ypos) + ") - (" + (xpos + 0) + "," + (ypos - 1) + ")"); } if ((xpos + 1 < w) && (ypos - 1 >= 0)) { MineAssets.instance.tiles[xpos + 1, ypos - 1].mine = false; Debug.Log("(" + (xpos) + "," + (ypos) + ") - (" + (xpos + 1) + "," + (ypos - 1) + ")"); } if (xpos - 1 >= 0) { MineAssets.instance.tiles[xpos - 1, ypos].mine = false; Debug.Log("(" + (xpos) + "," + (ypos) + ") - (" + (xpos - 1) + "," + (ypos + 0) + ")"); } if (xpos + 1 < w) { MineAssets.instance.tiles[xpos + 1, ypos].mine = false; Debug.Log("(" + (xpos) + "," + (ypos) + ") - (" + (xpos + 1) + "," + (ypos + 0) + ")"); } if ((xpos - 1 >= 0) && (ypos + 1 < h)) { MineAssets.instance.tiles[xpos - 1, ypos + 1].mine = false; Debug.Log("(" + (xpos) + "," + (ypos) + ") - (" + (xpos - 1) + "," + (ypos + 1) + ")"); } if (ypos + 1 < h) { MineAssets.instance.tiles[xpos, ypos + 1].mine = false; Debug.Log("(" + (xpos) + "," + (ypos) + ") - (" + (xpos + 0) + "," + (ypos + 1) + ")"); } if ((xpos + 1 < w) && (ypos + 1 < h)) { MineAssets.instance.tiles[xpos + 1, ypos + 1].mine = false; Debug.Log("(" + (xpos) + "," + (ypos) + ") - (" + (xpos + 1) + "," + (ypos + 1) + ")"); } MineAssets.instance.board.check(xpos, ypos); //Fill the current tile, this'll also pop the bubble around it. MineAssets.instance.minesLeftText.text = MineAssets.instance.board.totalUnflaggedMines().ToString(); MineAssets.instance.firstClick = false; //We then set first click to be false, since we only want to do this once at the beginning of the game. return; } //If we aren't just starting the game. MineAssets.instance.board.check(xpos, ypos); //Fill the current tile, this'll also pop any adjacent bubbles if there are any. } }