예제 #1
0
        private void UnPlay(int r, int c)
        {
            GamePiece gp = Item(r, c);

            UnPlay(gp.R, gp.C, true);
        }
예제 #2
0
        private bool CanUnExecutePlay(Point point)
        {
            GamePiece gp = Item((int)point.X, (int)point.Y);

            return(gp.IsPlayed);
        }
예제 #3
0
        private void NewGame(int r, int c, int mines)
        {
            GameBoardEnabled = false;
            result           = GameConstants.GameStates.IN_PLAY;
            this.ClearMessages();
            redoStack.Clear();
            undoStack.Clear();
            busTubStack.Clear();
            GameBoardEnabled = false;

            tmr.Enabled = false;
            foreach (GamePiece gp in _cells)
            {
                gp.Dispose();
            }
            _cells.Clear();

            int maxSeed = r * c;


            Random ra = new Random();
            int    n  = 0;

            for (int i = 0; i < r; i++)
            {
                for (int j = 0; j < c; j++)
                {
                    GameConstants.PieceValues pv = GameConstants.PieceValues.NOMINE;
                    _cells.Add(new GamePiece(this, n++, i, j, pv));
                }
            }
            // Plant the Mines
            int nMinesPlanted = 0;

            while (nMinesPlanted < mines)
            {
                int       nNextMinePlace = ra.Next(0, maxSeed);
                GamePiece gp             = (GamePiece)_cells[nNextMinePlace];
                while (gp.ActualValue == GameConstants.PieceValues.MINE)
                {
                    nNextMinePlace = ra.Next(0, maxSeed);
                    gp             = (GamePiece)_cells[nNextMinePlace];
                }
                gp.ActualValue = GameConstants.PieceValues.MINE;
                ++nMinesPlanted;
            }

            //Set Neighbor Values
            for (int i = 0; i < r; i++)
            {
                for (int j = 0; j < c; j++)
                {
                    if (Item(i, j).ActualValue != GameConstants.PieceValues.MINE)
                    {
                        GameConstants.PieceValues pv  = GameConstants.PieceValues.NOMINE;
                        List <GamePiece>          Lst = (List <GamePiece>)Neighbors(i, j);
                        int nMines = Lst.Count(gp => gp.ActualValue == GameConstants.PieceValues.MINE);
                        pv = (GameConstants.PieceValues)((int)GameConstants.PieceValues.NOMINE + nMines);
                        GamePiece gItem = Item(i, j);
                        gItem.ActualValue = pv;
                    }
                }
            }
            Rows             = r;
            Columns          = c;
            Mines            = thisGamesMines = mines;
            Time             = 0;
            GameState        = GameConstants.GameStates.NOT_STARTED;
            GameBoardEnabled = true;
            soundAdornment.NewGame();
            ShowGame();
        }