void Game_SquareTriggered(object sender, Square.MineSquareEventArgs e) { if (gameOver == true) { return; } int untriggeredCount = 0; // get count of total untriggered squares foreach (Square item in grid) { if (item.Checked == false) { untriggeredCount++; } } // get count of mines // this.mineCount(); // if untriggered square count <= mine count, game is won. if (untriggeredCount == mineCount( )) { gameOver = true; // stop timer t.Stop( ); // fetch time int time = ((GameForm)Parent.Parent.Parent).Time; foreach (Square item in grid) { item.autoFlag(this, new EventArgs( )); } // WOOOOOOOO!!!!! MessageBox.Show(string.Format("Yay! You won the game!\n\nYour final time was: {0}", time.ToString( ))); } }
void Game_TriggerSurroundingSquares(object sender, Square.MineSquareEventArgs e) { int x = e.X; int y = e.Y; int height = this.gridHeight; int width = this.gridWidth; if (x != 0) { if (!grid[x - 1, y].Checked) { grid[x - 1, y].Trigger( ); } } if (y != 0) { if (!grid[x, y - 1].Checked) { grid[x, y - 1].Trigger( ); } } if (y != 0 && x != 0) { if (!grid[x - 1, y - 1].Checked) { grid[x - 1, y - 1].Trigger( ); } } if ((y + 1) != height) { if (!grid[x, y + 1].Checked) { grid[x, y + 1].Trigger( ); } } if ((x + 1) != width) { if (!grid[x + 1, y].Checked) { grid[x + 1, y].Trigger( ); } } if ((x + 1) != width && y != 0) { if (!grid[x + 1, y - 1].Checked) { grid[x + 1, y - 1].Trigger( ); } } if ((y + 1) != height && x != 0) { if (!grid[x - 1, y + 1].Checked) { grid[x - 1, y + 1].Trigger( ); } } if ((x + 1) != width && (y + 1) != height) { if (!grid[x + 1, y + 1].Checked) { grid[x + 1, y + 1].Trigger( ); } } }