示例#1
0
        private void DrawPiece(SpriteBatch spriteBatch, PieceData piece, Vector2 tilePosition)
        {
            spriteBatch.Draw(
                resources.Piece,
                tilePosition - resources.Piece.Bounds.Size.ToVector2() * Scale / 2,
                null,
                Color.White,
                0,
                Vector2.Zero,
                Scale,
                piece.IsPlayerOne ? SpriteEffects.None : SpriteEffects.FlipVertically,
                0
                );

            var piecePrint = Utils.PieceToKanji(piece);

            var piecePrintPosition = tilePosition + (piece.IsPlayerOne ? new Vector2(0, 2) : new Vector2(0, -4)) * Scale;

            // Can not scale the string as the character will become ugly
            spriteBatch.DrawString(
                resources.PieceFont,
                piecePrint,
                piecePrintPosition - resources.PieceFont.MeasureString(piecePrint) / 2,
                piece.Promoted ? Color.Red : Color.Black
                );
        }
示例#2
0
 public MoveTurn(PieceData piece, bool didCheck, bool didPromote, int xFrom, int yFrom, int xTarget, int yTarget, PieceData captured)
 {
     Piece      = piece;
     DidCheck   = didCheck;
     DidPromote = didPromote;
     XFrom      = xFrom;
     YFrom      = yFrom;
     XTarget    = xTarget;
     YTarget    = yTarget;
     Captured   = captured;
 }
示例#3
0
        /// <summary>
        ///   Removes a piece from the HeldPiece property and puts it on the board.
        /// </summary>
        public bool PlacePiece(Point from, Point target, out PieceData captured)
        {
            captured = null;

            if (!Utils.ValidMovesForPiece(new GridRef <PieceData> {
                Data = HeldPiece, Position = from
            }, Data, GameplayState.CurrentPlayer, GameplayState.OpponentPlayer).Contains(target))
            {
                return(false);
            }

            var piece = Data.GetAt(target).Data;

            if (piece != null)
            {
                captured = piece;
            }
            PlacePiece(target);
            return(true);
        }
示例#4
0
        /// <summary>
        ///   Converts the corresponding <see cref="PieceData"/> to the corresponding letter.
        ///   The inverse of <see cref="PieceNotationToPieceType" />
        /// </summary>
        /// <param name="piece">The piece</param>
        /// <returns>
        ///   The correct ASCII letter
        /// </returns>
        public static char PieceToNotationChar(PieceData piece)
        {
            var character = piece.Type switch
            {
                PieceType.Pawn => 'P',
                PieceType.Bishop => 'B',
                PieceType.Rook => 'R',
                PieceType.Lance => 'L',
                PieceType.Knight => 'N',
                PieceType.Silver => 'S',
                PieceType.Gold => 'G',
                PieceType.King => 'K',
                _ => throw new ArgumentException(),
            };

            if (piece.Promoted)
            {
                return(char.ToUpper(character));
            }
            else
            {
                return(char.ToLower(character));
            }
        }
示例#5
0
 /// <summary>
 ///   Converts <paramref name="type"/> to the corresponding Kanji used to identify the piece.
 /// </summary>
 /// <param name="piece">The piece to get the Kanji for</param>
 /// <returns>
 ///   The Kanji corresponding to specified type, player side and promotion options.
 /// </returns>
 public static string PieceToKanji(PieceData piece) => piece.Type switch
 {