Esempio n. 1
0
        private int GetNorthMinesCount(int currentRow, GameBoard gameboard, int currentCol)
        {
            if (currentRow != 0)
            {
                if (gameboard.IsMineAtCell[currentRow - 1, currentCol])
                {
                    return 1;
                }
            }

            return 0;
        }
Esempio n. 2
0
        private int GetEastMinesCount(int currentCol, GameBoard gameboard, int currentRow)
        {
            if (currentCol != gameboard.ColsCount - 1)
            {
                if (gameboard.IsMineAtCell[currentRow, currentCol + 1])
                {
                    return 1;
                }
            }

            return 0;
        }
Esempio n. 3
0
        private int GetNorthEastMinesCount(int currentRow, int currentCol, GameBoard gameboard)
        {
            if (currentRow != 0 && currentCol != gameboard.ColsCount - 1)
            {
                if (gameboard.IsMineAtCell[currentRow - 1, currentCol + 1])
                {
                    return 1;
                }
            }

            return 0;
        }
Esempio n. 4
0
        public void GeneratedMinesCountTest()
        {
            GameBoard gameboard = new GameBoard(LevelOptions.RowsCount, LevelOptions.ColsCount, LevelOptions.MinesCount);
            int expectedMinesCount = LevelOptions.MinesCount;
            int actualMinesCount = 0;

            foreach (var mine in gameboard.IsMineAtCell)
            {
                if (mine)
                {
                    actualMinesCount++;
                }
            }

            Assert.AreEqual(expectedMinesCount, actualMinesCount);
        }
Esempio n. 5
0
        public void SurroundingMinesCountTest()
        {
            GameBoard gameboard = new GameBoard(LevelOptions.RowsCount, LevelOptions.ColsCount, LevelOptions.MinesCount);
            int expectedSurroundingMinesCount;
            int actualSurroundingMinesCount;

            for (int row = 0; row < gameboard.RowsCount; row++)
            {
                for (int col = 0; col < gameboard.ColsCount; col++)
                {
                    actualSurroundingMinesCount = gameboard.CountOfSurroudingMines[row, col];
                    expectedSurroundingMinesCount = GetSurroundingMinesCountAtPosition(gameboard, row, col);
                    Assert.AreEqual(expectedSurroundingMinesCount, actualSurroundingMinesCount);
                }
            }
        }
        private void CreateGameGrid(GameBoard board)
        {
            grid.ColumnDefinitions.Clear();
            grid.Children.Clear();
            grid.RowDefinitions.Clear();


            this.board = board;

            this.buttonGrid = new GridButton[board.Height, board.Width];

            //Create rows, columns
            for (int i = 0; i < board.Width; i++)
            {
                grid.ColumnDefinitions.Add(new ColumnDefinition());
            }

            for (int i = 0; i < board.Height; i++)
            {
                grid.RowDefinitions.Add(new RowDefinition());
            }

            //Create buttons
            for (int r = 0; r < board.Height; r++)
            {
                for (int c = 0; c < board.Width; c++)
                {
                    var info = new ButtonInfo()
                    {
                        Column = c,
                        Row    = r
                    };

                    if (board.IsMine(r, c))
                    {
                        info.IsMine = true;
                    }
                    else
                    {
                        int adjacentMines = board.GetNumMines(r, c);
                        info.Value  = adjacentMines;
                        info.IsMine = false;
                    }

                    GridButton button = new GridButton();
                    button.SetValue(Grid.RowProperty, r);
                    button.SetValue(Grid.ColumnProperty, c);
                    button.InitializeButton(info);
                    grid.Children.Add(button);

                    buttonGrid[r, c] = button;
                }
            }

            //Initialize Game
            MinesLeft       = board.TotalMines;
            actualMinesLeft = board.TotalMines;
            triggeredMines  = 0;

            CellsLeft = board.Width * board.Height;

            //Set Handlers
            GridButton.SetHandlers(
                OnClick,
                Flag,
                AutoClick
                );

            InGame = true;
        }
        internal void CreateGame(int rows, int columns, int mines)
        {
            GameBoard board = GameBoard.CreateBoard(rows, columns, mines);

            CreateGameGrid(board);
        }
Esempio n. 8
0
        private int GetWestMinesCount(int currentCol, GameBoard gameboard, int currentRow)
        {
            if (currentCol != 0)
            {
                if (gameboard.IsMineAtCell[currentRow, currentCol - 1])
                {
                    return 1;
                }
            }

            return 0;
        }
Esempio n. 9
0
        private int GetSurroundingMinesCountAtPosition(GameBoard gameboard, int currentRow, int currentCol)
        {
            int count = GetNortWestMinesCount(currentRow, currentCol, gameboard) +
                        GetNorthMinesCount(currentRow, gameboard, currentCol) +
                        GetNorthEastMinesCount(currentRow, currentCol, gameboard) +
                        GetWestMinesCount(currentCol, gameboard, currentRow) +
                        GetEastMinesCount(currentCol, gameboard, currentRow) +
                        GetSouthWestMinesCount(currentRow, gameboard, currentCol) +
                        GetSouthMinesCount(currentRow, gameboard, currentCol) +
                        GetSouthEastMinesCount(currentRow, gameboard, currentCol);

            return count;
        }
Esempio n. 10
0
        private int GetSouthWestMinesCount(int currentRow, GameBoard gameboard, int currentCol)
        {
            if (currentRow != gameboard.RowsCount - 1 && currentCol != 0)
            {
                if (gameboard.IsMineAtCell[currentRow + 1, currentCol - 1])
                {
                    return 1;
                }
            }

            return 0;
        }
        public void Render(GameBoard gameBoard)
        {
            var gameBoardString = ParseGameBoardToString(gameBoard);

            Console.Write(gameBoardString);
        }
Esempio n. 12
0
 public void InitNewGame()
 {
     this.displayBoard = true;
     this.board = new GameBoard(LevelOptions.RowsCount, LevelOptions.ColsCount, LevelOptions.MinesCount);
 }