Example #1
0
        //Init
        public override void Initialize(int row, int column, int mine, Window window)
        {
            //Call the base Init - from the abstruct class
            base.Initialize(row, column, mine, window);
            //Set background colour
            gameBoard.Background = new SolidColorBrush(Colors.LightGray);

            //Create rows
            for (int i = 0; i < row; i++)
            {
                RowDefinition rowDef = new RowDefinition();
                rowDef.Height = new GridLength(blockSize);
                gameBoard.RowDefinitions.Add(rowDef);
                // Create Columns
                for (int j = 0; j < column; j++)
                {
                    ColumnDefinition columnDef = new ColumnDefinition();
                    columnDef.Width = new GridLength(blockSize);
                    gameBoard.ColumnDefinitions.Add(columnDef);
                    Tile tile = new SP_Tile(i, j, this);
                    tiles.Add(tile);
                }
            }
            //Randomly place the mines
            SetMine(RandomNumber(mine), tiles);

            //Add the gameboard to the canvas
            gameCanvas.Children.Add(this.gameBoard);
            //Display the canvas
            gameWindow.Content = this.gameCanvas;
            //Window size to content
            gameWindow.SizeToContent = SizeToContent.WidthAndHeight;
        }
Example #2
0
 //Override this function, Check a group of tile
 public override void InvokeGroupOfTile(List <int> numbers)
 {
     //First check if the surrounding tiles have mine
     foreach (int i in numbers)
     {
         //cast the tile stored tile to single player tile
         SP_Tile temp = gameBoard.Tiles[i] as SP_Tile;
         //if has mine and is not checked
         if (temp.hasMine && !temp.isFinish)
         {
             //fire event, return from the function so it does not check for the number of mines for the rest of the tile
             temp.button.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
             return;
         }
     }
     //Then check for each tile, how many mines are nearby
     foreach (int i in numbers)
     {
         SP_Tile temp = gameBoard.Tiles[i] as SP_Tile;
         temp.button.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
     }
 }