Ejemplo n.º 1
0
        public static void Draw(Board board)
        {
            Console.WriteLine("   1 2 3 4 5 6 7 8 9 10");

            Console.WriteLine();

            for (int row = 0; row < board.NumRow; row++)
            {
                if (row + 1 < 10) Console.Write(row + 1 + "  ");
                else Console.Write(row + 1 + " ");

                for (int col = 0; col < board.NumCol; col++)
                {
                    if (board.Cells[row, col].Visibility == CellVisibility.Revealed)
                    {
                        if (board.Cells[row, col].IsMine)
                        {
                            Console.Write("M ");
                        }
                        else
                        {
                            Console.Write(board.Cells[row, col].MinesAround + " ");
                        }
                    }
                    else
                    {
                        Console.Write("- ");
                    }
                }
                Console.WriteLine();
            }
            Console.WriteLine();
            //Console.WriteLine(cellsRevealed + " cells cleared");
            Console.WriteLine();
        }
Ejemplo n.º 2
0
 private void CountMinesAround(Cell cell, Board board)
 {
     if (cell.IsMine)
     {
         MinesAround++;
     }
 }
Ejemplo n.º 3
0
        private static void Main(string[] args)
        {
            Console.WriteLine("Starting the game");
            Console.WriteLine(); 
            
            var board = new Board();
            Draw(board);

            while (!board.GameOver) //todo check number of cells left to reveal
            {
                var row = ReadRow();
                var col = ReadColumn();
                
                Console.WriteLine();
                
                if (!board.TreatUserInput(row, col))
                    Console.WriteLine("This cell has already been cleared");
                
                Console.WriteLine();

                Draw(board);
            }

            Console.WriteLine(board.GameOver ? "GameOver" : "You won !");
            Console.WriteLine("Press any key to exit");
            Console.ReadKey();

        }
Ejemplo n.º 4
0
 private void Reveal(Cell cell, Board board)
 {
     if (MinesAround == 0)
     {
         cell.Reveal(board);
     }
 }
Ejemplo n.º 5
0
 public void Reveal(Board board)
 {
     if (!IsMine)
     {
         BrowseAllCells(board, CountMinesAround);
         BrowseAllCells(board, Reveal);
     }
     Visibility = CellVisibility.Revealed;
 }
Ejemplo n.º 6
0
 public void BrowseAllCells2(Board board)
 {
     for (int rowIndex = Math.Max(_row - 1, 0); rowIndex <= Math.Min(_row + 1, board.NumRow - 1); rowIndex++)
     {
         for (int columnIndex = Math.Max(_col - 1, 0); columnIndex <= Math.Min(_col + 1, board.NumCol - 1); columnIndex++)
         {
             CellAction2(board.Cells[rowIndex, columnIndex], board);
         }
     }
 }
Ejemplo n.º 7
0
 public void Reveal2(Board board)
 {
     CellAction2 += CountMinesAround;
     CellAction2 += Reveal;
     
     if (!IsMine)
     {
         BrowseAllCells2(board);
     }
     Visibility = CellVisibility.Revealed;
 }
Ejemplo n.º 8
0
        private object Generate(int nrows, int ncols, int height, int width, int rest)
        {
            Board board = new Board(nrows, ncols);
            board.SetEmpty(height, width);
            board.SetClick(0, 0);

            int y = 0;
            int x = width;

            while (rest >= 2 && y + 1 < height && x < ncols)
            {
                board.SetEmptyCell(y, x);
                board.SetEmptyCell(y + 1, x);
                rest -= 2;
                x++;

                if (x >= ncols)
                {
                    y += 2;
                    x = width;

                    if (y >= height)
                        break;
                }
            }

            if (rest > 0 && y == 0)
            {
                y = 2;
                x = width;
            }

            while (rest > 0 && y < height && x < ncols)
            {
                board.SetEmptyCell(y, x++);
                rest--;

                if (x >= ncols)
                {
                    y++;
                    x = width;
                }
            }

            return board.ToLines();
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            board = new Board(10, 10, 5);

            for (int x = 0; x < board.Width; ++x)
                cellGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(40) });
            for (int y = 0; y < board.Height; ++y)
                cellGrid.RowDefinitions.Add(new RowDefinition {Height = new GridLength(40)});

            for (int y = 0; y < board.Height; ++y)
                for (int x = 0; x < board.Width; ++x)
                {
                    var button = new Button {Background = new SolidColorBrush(Colors.Purple), Content = " "};
                    button.SetValue(Grid.ColumnProperty, x);
                    button.SetValue(Grid.RowProperty, y);
                    button.Click += ButtonClick;
                    cellGrid.Children.Add(button);
                }
        }
Ejemplo n.º 10
0
 public Form1()
 {
     InitializeComponent();
     _board = new Board();
 }
Ejemplo n.º 11
0
 static void Main(string[] args)
 {
     Board game = new Board();
     //game.PrintBoard();
     game.Act(Console.ReadLine(), true);
     while (true)//game isnt over
     {
         game.Act(Console.ReadLine());
     }
     string move = Console.ReadLine();
     game.Act(move);
     Console.WriteLine("ok");
     Console.ReadKey();
 }
Ejemplo n.º 12
0
 private static void InitializeGameBoard()
 {
     board = new Board(maxRows, maxColumns, maxMines);
 }
Ejemplo n.º 13
0
        private static void InitializeGameBoard()
        {
            board = new Board(maxRows, maxColumns, maxMines);

        }