Пример #1
0
        private void cellClick(Button cell)
        {
            short value     = short.Parse(cell.Name.Substring(4, cell.Name.Length - 4)); //value = row * sideWidth + col......
            short row       = (short)(value / sideWidth);
            short col       = (short)(value % sideWidth);
            short cellValue = numGrid.grid[row, col];

            if (cellValue == 0) //No any bomb surround
            {
                freeCellsCount++;
                clearZeroCells(row, col);
                checkWin();
            }
            else if (cellValue >= 99)              //Clicked on a bomb
            {
                if (freeCellsCount == 0 && !retry) //First click
                {
                    numGrid = new NumberGrid();
                    cellClick(cell);
                    return;
                }

                //Not the first click (Defeat - Lose the game)
                loseTheGame();
            }
            else //Not 0 or not a bomb
            {
                showNumberOnCell(cell, cellValue);
                freeCellsCount++;
            }

            checkWin();
        }
Пример #2
0
        private void loseTheGame()
        {
            PlayTimeTimer.Enabled = false;
            showBombs();

            DialogResult retryOrCancel = loseMsg.ShowDialog();

            //New Game
            if (retryOrCancel == DialogResult.OK)
            {
                removeCells();
                InitializeGrid();
                InitializeProperties();
                numGrid       = new NumberGrid();
                TimeShow.Text = "00:00:00";
                playTime      = TimeSpan.FromSeconds(0);
                retry         = false;
            }

            //Retry
            else if (retryOrCancel == DialogResult.Retry)
            {
                removeCells();
                InitializeGrid();
                InitializeProperties();
                retry = true;
            }

            //Cancel
            else
            {
                Close();
            }
        }