public MainWindow() { InitializeComponent(); MessageBoxResult choice = MessageBox.Show( "Want to play with Chess960 rules?", "Chess960", MessageBoxButton.YesNo, //button options MessageBoxImage.Question); this.boardModel = new Board(choice == MessageBoxResult.Yes); Debug.WriteLine(this.boardModel.ToString()); //REMOVE WHEN DONE this.mode = 0; //default start by chosing a piece this.turn = 0; //white starts this.ShowTurn(); this.UpdateDeadPiecesViews(); //initializing the buttonArray this.buttonArray = new BoardButton[Board.GameSize][]; //Change Game size for (int i = 0; i < this.buttonArray.Length; i++) { this.buttonArray[i] = new BoardButton[Board.GameSize]; } //creating the buttons for the board. for (int i = 0; i < this.buttonArray.Length; i++) { for (int j = 0; j < this.buttonArray.Length; j++) { string name = "space" + i + j; BoardSpace correspondingSpace = this.boardModel.GetBoardSpace(i, j); BoardButton presentButton = new BoardButton(i, j, name, correspondingSpace); this.buttonArray[i][j] = presentButton; if (!correspondingSpace.Occupied || correspondingSpace.Piece.Color != this.turn) { presentButton.IsEnabled = false; } int realJ = (j - this.buttonArray.Length + 1) * -1; //to fix grid y axis problem Grid.SetColumn(presentButton, i); Grid.SetRow(presentButton, realJ); this.boardGrid.Children.Add(presentButton); presentButton.AddHandler(BoardButton.ClickEvent, new RoutedEventHandler(boardButton_Click)); //Adding eventHandler } } }
public MainWindow() { InitializeComponent(); this.boardModel = new Board(); Debug.WriteLine(this.boardModel.ToString()); //usuń kiedy sie wykona this.mode = 0; this.turn = 0; //białe zaczynają 0 this.ShowTurn(); this.UpdateDeadPiecesViews(); //initializing the buttonArray this.buttonArray = new BoardButton[Board.GameSize][]; //Change Game size for (int i = 0; i < this.buttonArray.Length; i++) { this.buttonArray[i] = new BoardButton[Board.GameSize]; } //inicjowanie przycisku na planszy. for (int i = 0; i < this.buttonArray.Length; i++) { for (int j = 0; j < this.buttonArray.Length; j++) { string name = "space" + i + j; BoardSpace correspondingSpace = this.boardModel.GetBoardSpace(i, j); BoardButton presentButton = new BoardButton(i, j, name, correspondingSpace); this.buttonArray[i][j] = presentButton; if (!correspondingSpace.Occupied || correspondingSpace.Piece.Color != this.turn) { presentButton.IsEnabled = false; } int realJ = (j - this.buttonArray.Length + 1) * -1; Grid.SetColumn(presentButton, i); Grid.SetRow(presentButton, realJ); this.boardGrid.Children.Add(presentButton); presentButton.AddHandler(BoardButton.ClickEvent, new RoutedEventHandler(boardButton_Click)); } } }