private void UpdateView() { this.ShowTurn(); this.UpdateDeadPiecesViews(); //updating board. for (int i = 0; i < this.buttonArray.Length; i++) { for (int j = 0; j < this.buttonArray.Length; j++) { BoardButton presentButton = this.buttonArray[i][j]; BoardSpace presentSpace = this.boardModel.GetBoardSpace(i, j); //MAYBE REPLACE BY GETTER if (mode == 0) //if mode is now chose piece, we clear the possible destinations. { presentButton.ClearValue(BoardButton.BackgroundProperty); //clears background color presentSpace.IsPossibleDestination = false; } if (presentSpace.IsPossibleDestination) { presentButton.Background = Brushes.Red; } if (!presentSpace.IsPossibleDestination && (!presentSpace.Occupied || presentSpace.Piece.Color != this.turn)) { presentButton.IsEnabled = false; } else { presentButton.IsEnabled = true; } //Condition in case we're in chose destination mode //only destinations and the pressed button are enabled if (this.mode == 1 && !presentSpace.IsPossibleDestination && !presentButton.Equals(this.lastPressed)) { presentButton.IsEnabled = false; } presentButton.Content = presentSpace.GetBoardSpaceChar(); Debug.WriteLine(presentSpace.ToString());//REMOVE } } }
private void UpdateView() { this.ShowTurn(); this.UpdateDeadPiecesViews(); //aktualizowanie planszy for (int i = 0; i < this.buttonArray.Length; i++) { for (int j = 0; j < this.buttonArray.Length; j++) { BoardButton presentButton = this.buttonArray[i][j]; BoardSpace presentSpace = this.boardModel.GetBoardSpace(i, j); if (mode == 0) //pokazuje mozliwe miejsca docelowe figury. { presentButton.ClearValue(BoardButton.BackgroundProperty); presentSpace.IsPossibleDestination = false; } if (presentSpace.IsPossibleDestination) { presentButton.Background = Brushes.Green; } if (!presentSpace.IsPossibleDestination && (!presentSpace.Occupied || presentSpace.Piece.Color != this.turn)) { presentButton.IsEnabled = false; } else { presentButton.IsEnabled = true; } //w chwili wybrania figury //tylko przycisk i miejsca docelowe sa pokazane if (this.mode == 1 && !presentSpace.IsPossibleDestination && !presentButton.Equals(this.lastPressed)) { presentButton.IsEnabled = false; } presentButton.Content = presentSpace.GetBoardSpaceChar(); Debug.WriteLine(presentSpace.ToString()); } } }
private void boardButton_Click(object sender, RoutedEventArgs e) { //throw new NotImplementedException(); BoardButton clickedButton = sender as BoardButton; Debug.WriteLine(clickedButton.Name);//REMOVE int x = clickedButton.PosX; int y = clickedButton.PosY; BoardSpace clickedSpace = this.boardModel.GetBoardSpace(x, y); if (this.mode == 0) //mode 0 --> chose piece { clickedSpace.Piece.SetDestinations(x, y); this.mode = (this.mode + 1) % 2; this.lastPressed = clickedButton; } else // other mode is chose destinations { if (!clickedButton.Equals(this.lastPressed)) //if button clicked is not the same as before { this.MovePiece(clickedSpace); this.lastPressed = null; //we promote pawns getting to the end fo board if ((y == 0 || y == 7) && clickedSpace.Piece.Type == "pawn") { this.Promote(clickedSpace); } clickedSpace.Piece.PlayedOnce(); //techically redundant, but no harm to efficiency. this.turn = (this.turn + 1) % 2; //. only change turn after destination chosen. } this.mode = (this.mode + 1) % 2; //always change mode. } this.UpdateView(); Debug.WriteLine(this.boardModel.ToString());//REMOVE int winner = this.GameWon(); this.AskForNewGame(winner); }
private void boardButton_Click(object sender, RoutedEventArgs e) { //throw new NotImplementedException(); BoardButton clickedButton = sender as BoardButton; Debug.WriteLine(clickedButton.Name);//REMOVE int x = clickedButton.PosX; int y = clickedButton.PosY; BoardSpace clickedSpace = this.boardModel.GetBoardSpace(x, y); if (this.mode == 0) { clickedSpace.Piece.SetDestinations(x, y); this.mode = (this.mode + 1) % 2; this.lastPressed = clickedButton; } else { if (!clickedButton.Equals(this.lastPressed)) { this.MovePiece(clickedSpace); this.lastPressed = null; //zmiana piona po dojsciu do konca planszy if ((y == 0 || y == 7) && clickedSpace.Piece.Type == "pawn") { this.Promote(clickedSpace); } clickedSpace.Piece.PlayedOnce(); this.turn = (this.turn + 1) % 2;//zmiana ruchu po wybraniu miejsca } this.mode = (this.mode + 1) % 2; } this.UpdateView(); Debug.WriteLine(this.boardModel.ToString()); int winner = this.GameWon(); this.AskForNewGame(winner); }