/// <summary> /// Reveals the buttons on the grid as a loss state and disables the grid on defeat /// </summary> private void RevealGridLoss() { swGameTime.Stop(); for (int i = 0; i < board.Size; i++) { for (int j = 0; j < board.Size; j++) { //bombs show up as * if (board.Grid[i, j].Live) { btnGrid[i, j].BackgroundImage = Image.FromFile(@"..\Bomb.png"); btnGrid[i, j].BackgroundImageLayout = ImageLayout.Stretch; } //non-bombs show up with their number of liveNeighbors else { btnGrid[i, j].Text = "" + board.Grid[i, j].LiveNeighbors; } //disables the grid to prevent further play btnGrid[i, j].Enabled = false; } } string message = ("You Lost."); int score = 0; frmResult frmResult = new frmResult(PrepForm, this, message, GameSize, score, swGameTime.Elapsed); frmResult.ShowDialog(); }
/// <summary> /// Reveals the board as a win state and disables the grid on victory /// </summary> private void RevealGridWin() { swGameTime.Stop(); string gameTime = string.Format("{0:hh\\:mm\\:ss\\:ff}", swGameTime.Elapsed); for (int i = 0; i < board.Size; i++) { for (int j = 0; j < board.Size; j++) { //bombs show up as * if (board.Grid[i, j].Live) { btnGrid[i, j].BackgroundImage = Image.FromFile(@"..\Flag.png"); btnGrid[i, j].BackgroundImageLayout = ImageLayout.Stretch; } //non-bombs show up with their number of liveNeighbors else { btnGrid[i, j].Text = "" + board.Grid[i, j].LiveNeighbors; } //disables the grid to prevent further play btnGrid[i, j].Enabled = false; } } string message = ("You win!\n It took you " + gameTime.Substring(0, 8) + " to complete the game!\n Would you like to play again?"); int score; if (GameSize < 16) { score = 50000 - (int)swGameTime.ElapsedMilliseconds; } else if (GameSize < 25) { score = 750000 - (int)swGameTime.ElapsedMilliseconds; } else { score = 50000000 - (int)swGameTime.ElapsedMilliseconds; } frmResult frmResult = new frmResult(PrepForm, this, message, GameSize, score, swGameTime.Elapsed); frmResult.ShowDialog(); }