public void BoardFloodFills()
        {
            var board = new MineSweeperBoard();

            board.Start(BoardSize.Large);
            var blankTile = GetTilesWithPositions(board).Where(x => x.Tile.AdjacentTileCount == 0).First();

            Trace.WriteLine($"TilePos- y: {blankTile.Position.Item1}  x:{blankTile.Position.Item2}");

            TraceBoard(board.BoardTiles, true);
            board.OnClick(blankTile.Position.Item2, blankTile.Position.Item1);
            TraceBoard(board.BoardTiles, false);
        }
 IEnumerable <TileWithPosition> GetTilesWithPositions(MineSweeperBoard board)
 {
     for (int y = 0; y < board.BoardTiles.GetLength(0); y++)
     {
         for (int x = 0; x < board.BoardTiles.GetLength(1); x++)
         {
             yield return(new TileWithPosition()
             {
                 Position = new Tuple <int, int>(y, x), Tile = board.BoardTiles[y, x]
             });
         }
     }
 }
예제 #3
0
        //Bind Mouse Clicks
        private void Grid_Button_MouseDown(object sender, MouseEventArgs e)
        {
            Button ClickedButton  = (Button)sender;
            Point  ButtonLocation = (Point)ClickedButton.Tag;
            int    x        = ButtonLocation.X;
            int    y        = ButtonLocation.Y;
            Cell   ThisCell = MineSweeperBoard.Grid[x, y];

            StartTimer();

            //Left Mouse Button Click
            if (e.Button == MouseButtons.Left)
            {
                if (ThisCell.Visited == false && ThisCell.Flagged == false)
                {
                    MineCheck(MineSweeperBoard.MinePresent(x, y));
                    MineSweeperBoard.VisitBlocksWithNoLiveNeighbors(x, y);
                    ThisCell.Visited = true;
                }
            }

            //Right Mouse Button Click
            if (e.Button == MouseButtons.Right)
            {
                if (ThisCell.Flagged == false && ThisCell.Visited == false)
                {
                    ThisCell.Flagged = true;
                    MinesLeft--;
                    lbl_mines.Text = MinesLeft.ToString();
                }
                else if (ThisCell.Flagged)
                {
                    ThisCell.Flagged = false;
                    MinesLeft++;
                    lbl_mines.Text = MinesLeft.ToString();
                }
            }

            //Double Mouse Button Click
            if (((Control.MouseButtons & MouseButtons.Right) == MouseButtons.Right) &&
                ((Control.MouseButtons & MouseButtons.Left) == MouseButtons.Left))
            {
                if (ThisCell.Visited == true)
                {
                    MineCheck(MineSweeperBoard.ClearSimilarLiveNeighbors(x, y));
                }
            }
            RefreshBoard(MineSweeperBoard);
            CheckWin(MineSweeperBoard);
        }
예제 #4
0
 public GameController()
 {
     this.GameView  = new MineSweeperView();
     this.GameBoard = new MineSweeperBoard();
 }