//Constructor public SP_Tile(int row, int column, MineSweeper gameBoard) { //Store values this.column = column; this.row = row; this.gameBoard = gameBoard; this.tileID = column + row * gameBoard.Column; this.isFinish = false; //Cast the gameboard to single player gameboard and store it board = gameBoard as SP_GameBoard; //New button button = new Button(); hasMine = false; //Add Event Handlers to the button button.Click += OnLeftClickTile; button.MouseDoubleClick += OnDoubleClickTile; button.MouseRightButtonDown += OnRightClickTile; //Set button position (Within the grid) System.Windows.Controls.Grid.SetColumn(this.button, column); System.Windows.Controls.Grid.SetRow(this.button, row); //Add button to the grid gameBoard.GameBoard.Children.Add(button); //Add event handler for this tile (On Click the Mine) GameEventHandler += OnCollectObject; }
//Constructor public MP_Tile(int row, int column, MineSweeper gameBoard) { //store the values this.column = column; this.row = row; this.gameBoard = gameBoard; this.tileID = column + row * gameBoard.Column; this.isFinish = false; //Create new button for the tile button = new Button(); hasMine = false; //Give the button Left Click Event Handler button.Click += OnLeftClickTile; button.Background = Brushes.SkyBlue; //Set the position of the button in grid System.Windows.Controls.Grid.SetColumn(this.button, column); System.Windows.Controls.Grid.SetRow(this.button, row); //Add the button to grid gameBoard.GameBoard.Children.Add(button); //Give the tile OnCollectObject Event Handler (On Click Mine) GameEventHandler += OnCollectObject; }