Пример #1
0
        public async Task ClickSingleSquareAsync(MineSquareCP thisSquare)
        {
            if (thisSquare.IsFlipped == true || thisSquare.Flagged == true)
            {
                return;
            }
            // if flaged, you have to unflag first.
            // if flipped, too late
            if (thisSquare.IsMine == true)
            {
                BlowUp();
                await ProcessGameStateAsync(EnumGameStates.Lost);

                return; // you lost now.
            }
            thisSquare.IsFlipped = true;
            if (thisSquare.NeighborMines == 0)
            {
                FlipAllNeighbors(thisSquare);
            }
            if (NumberOfMines == CountUnflippedSquares())
            {
                await ProcessGameStateAsync(EnumGameStates.Won);

                return;
            }
        }
Пример #2
0
 public MineSquareWPF(MineSquareCP thisSquare)
 {
     CommandParameter = thisSquare;
     Name             = nameof(MinesweeperMainViewModel.MakeMoveAsync);
     _thisSquare      = thisSquare;
     _thisDraw        = new SKElement();
     Content          = _thisDraw;
 }
Пример #3
0
 public void FlagSingleSquare(MineSquareCP thisSquare)
 {
     if (thisSquare.IsFlipped == true)
     {
         return;
     }
     thisSquare.Flagged = !thisSquare.Flagged;
     //ThisMod.NumberOfMinesLeft = GetMinesLeft();
 }
Пример #4
0
 public async Task MakeMoveAsync(MineSquareCP square)
 {
     if (IsFlagging)
     {
         _mainGame.FlagSingleSquare(square);
         NumberOfMinesLeft = _mainGame.GetMinesLeft();
         return;
     }
     await _mainGame.ClickSingleSquareAsync(square);
 }
Пример #5
0
        private void CreateSquares()
        {
            CustomBasicList <int> arr_Mines = new CustomBasicList <int>();
            int int_Square;
            int int_SquareCount = 1;

            _arr_Squares = new CustomBasicList <MineSquareCP>();
            while (arr_Mines.Count < NumberOfMines)
            {
                int_Square = GetRandomInteger((NumberOfRows * NumberOfColumns));
                if ((!(arr_Mines.Contains(int_Square))) & (int_Square > 0))
                {
                    arr_Mines.Add(int_Square);
                }
            }

            var loopTo = NumberOfRows;

            for (int int_Row = 1; int_Row <= loopTo; int_Row++)
            {
                var loopTo1 = NumberOfColumns;
                for (int int_Col = 1; int_Col <= loopTo1; int_Col++)
                {
                    var obj_TempSquare = new MineSquareCP(int_Col, int_Row);

                    if ((arr_Mines.Contains(int_SquareCount)))
                    {
                        obj_TempSquare.IsMine = true;
                    }

                    _arr_Squares.Add(obj_TempSquare);

                    int_SquareCount += 1;
                }
            }

            // *** Get numbers for each of the non-mine squares
            foreach (var obj_TempSquare in _arr_Squares)
            {
                obj_TempSquare.NeighborMines = CountNeighborMines(obj_TempSquare);
            }


            // needs a subscription
            // because from this point, the ui needs to do the ui portions.
            //Aggregator.Publish(new SubscribeGameBoardEventModel());
        }
Пример #6
0
        private int CountNeighborMines(MineSquareCP obj_TempSquare)
        {
            int int_Count = 0;

            for (var int_X = -1; int_X <= 1; int_X++)
            {
                for (var int_Y = -1; int_Y <= 1; int_Y++)
                {
                    if ((SquareHasMine(obj_TempSquare.Column + int_X, obj_TempSquare.Row + int_Y)))
                    {
                        int_Count += 1;
                    }
                }
            }

            return(int_Count);
        }
Пример #7
0
        private void FlipAllNeighbors(MineSquareCP obj_TempSquare)
        {
            MineSquareCP obj_Flip;

            for (var int_X = -1; int_X <= 1; int_X++)
            {
                for (var int_Y = -1; int_Y <= 1; int_Y++)
                {
                    obj_Flip = GetSquare(obj_TempSquare.Column + int_X, obj_TempSquare.Row + int_Y);
                    if (!(obj_Flip == null))
                    {
                        if ((!obj_Flip.Flagged) & (!obj_Flip.IsFlipped))
                        {
                            obj_Flip.IsFlipped = true;

                            if (obj_Flip.NeighborMines == 0)
                            {
                                FlipAllNeighbors(obj_Flip);
                            }
                        }
                    }
                }
            }
        }
 public MineSquareXF(MineSquareCP thisSquare)
 {
     _thisSquare      = thisSquare;
     CommandParameter = thisSquare;
     this.SetName(nameof(MinesweeperMainViewModel.MakeMoveAsync));
 }