コード例 #1
0
ファイル: GamePiece.cs プロジェクト: kathleenasheltra/Sweeper
 public GamePiece(int nItem, GameConstants.PieceValues pv)
 {
     linearIndex = nItem;
     // IsPlayed = false;
     value = pv;
 }
コード例 #2
0
ファイル: GamePiece.cs プロジェクト: kathleenasheltra/Sweeper
        public GamePiece(ViewModels.SweeperViewModel sweeperViewModel, int p, int r, int c, GameConstants.PieceValues actualValue)
        {
            this.sweeperViewModel = sweeperViewModel;
            linearIndex           = p;
            this.r = r;
            this.c = c;
            value  = GameConstants.PieceValues.BUTTON;
            if (gameBoard == null)
            {
                gameBoard = sweeperViewModel;
            }
            //this._GridBorderBrush = sweeperViewModel.GridBorderBrush;
            //this._HiGridBorderBrush = sweeperViewModel.HiGridBorderBrush;

            App.ChangeThemeEvent += App_ChangeThemeEvent;
        }
コード例 #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();
        }