public override void OnResponse(Server.Network.NetState sender, RelayInfo info) { PawnPromotion type = PawnPromotion.None; switch (info.ButtonID) { case 0: return; // This fixes a crash when staff deletes the pawn being promoted case 1: type = PawnPromotion.Queen; break; case 2: type = PawnPromotion.Rook; break; case 3: type = PawnPromotion.Knight; break; case 4: type = PawnPromotion.Bishop; break; case 5: type = PawnPromotion.None; break; } m_Game.OnPawnPromoted(type); }
public bool Move(int locationX, int locationY, int toX, int toY) { ChessPiece movingPiece = this[locationX, locationY]; if (CheckMove(locationX, locationY, toX, toY) && movingPiece.Color == CurrentTurn) { this[locationX, locationY] = null; this[toX, toY] = movingPiece; CurrentTurn = CurrentTurn == PieceColor.L ? PieceColor.D : PieceColor.L; if (movingPiece.Piece == Pieces.P && (toY == 7 || toY == 0)) { PawnPromotion promotionWindow = new PawnPromotion(); promotionWindow.ShowDialog(); this[toX, toY] = new ChessPiece(promotionWindow.ChosenPiece, movingPiece.Color, new BitmapImage( new Uri($"../Resources/{promotionWindow.ChosenPiece.ToString()}_{movingPiece.Color.ToString()}.png", UriKind.Relative))); } return(true); } return(false); }
public override string Move(Cell Target, Board ChessBoard) { MoveHistory.Add(Pos.GetBoardPosition() + " => " + Target.Figure.Pos.GetBoardPosition()); if ((this.Color.Equals(ChessColor.White) && Target.Figure.Pos.Y == 0) || (this.Color.Equals(ChessColor.Black) && Target.Figure.Pos.Y == 7)) { PawnPromotion NewPP = new PawnPromotion(this); NewPP.Owner = Application.Current.MainWindow; NewPP.ShowDialog(); ChessBoard.cells[Pos.X, Pos.Y].Figure = (BaseFigure)Activator.CreateInstance(NewPP.PromotionType, Pos, Color); } Position TempPos = Target.Figure.Pos; Target.Figure = ChessBoard.cells[Pos.X, Pos.Y].Figure; ChessBoard.cells[Pos.X, Pos.Y].Figure = new BaseFigure(Pos); Target.Figure.Pos = TempPos; return(MoveHistory[MoveHistory.Count - 1]); }
/// <summary> /// A pawn has been promoted and should be changed on the board /// </summary> /// <param name="pawn">The pawn that has been promoted</param> /// <param name="to">The type of piece it should be promoted to</param> public void OnPawnPromoted(BaseChessPiece pawn, PawnPromotion to) { BaseChessPiece promoted = null; switch (to) { case PawnPromotion.Queen: promoted = new Queen(this, pawn.Color, pawn.Position); break; case PawnPromotion.Rook: promoted = new Rook(this, pawn.Color, pawn.Position); break; case PawnPromotion.Knight: promoted = new Knight(this, pawn.Color, pawn.Position); break; case PawnPromotion.Bishop: promoted = new Bishop(this, pawn.Color, pawn.Position); break; } if (promoted != null) { m_Table[pawn.Position] = promoted; pawn.Die(false); } PushGame(pawn.EnemyColor, null); }
/// <summary> /// The user decided to promote a pawn /// </summary> /// <param name="type">The piece the pawn should promote to</param> public void OnPawnPromoted( PawnPromotion type ) { m_Board.OnPawnPromoted( m_PromotedPawn, type ); m_PromotedPawn = null; }
/// <summary> /// A pawn has been promoted and should be changed on the board /// </summary> /// <param name="pawn">The pawn that has been promoted</param> /// <param name="to">The type of piece it should be promoted to</param> public void OnPawnPromoted( BaseChessPiece pawn, PawnPromotion to ) { BaseChessPiece promoted = null; switch ( to ) { case PawnPromotion.Queen: promoted = new Queen( this, pawn.Color, pawn.Position ); break; case PawnPromotion.Rook: promoted = new Rook( this, pawn.Color, pawn.Position ); break; case PawnPromotion.Knight: promoted = new Knight( this, pawn.Color, pawn .Position ); break; case PawnPromotion.Bishop: promoted = new Bishop( this, pawn.Color, pawn.Position ); break; } if ( promoted != null ) { m_Table[ pawn.Position ] = promoted; pawn.Die( false ); } PushGame( pawn.EnemyColor, null ); }
/// <summary> /// The user decided to promote a pawn /// </summary> /// <param name="type">The piece the pawn should promote to</param> public void OnPawnPromoted(PawnPromotion type) { m_Board.OnPawnPromoted(m_PromotedPawn, type); m_PromotedPawn = null; }