/// <summary> /// Attacks the specified target. /// </summary> /// <param name="target">The target.</param> /// <returns> /// <c>true</c> if successful, <c>false</c> if not. /// </returns> public override bool Attack(Position target) { if (base.Attack(target)) { this.firstMove = false; return true; } return false; }
/// <summary> /// Initializes a new instance of the <see cref="Bishop"/> class. /// </summary> /// <param name="color">The piece color.</param> /// <param name="gameboard">The gameboard.</param> /// <param name="position">The starting position.</param> public Bishop(IPieceColor color, Gameboard gameboard, Position position) : base(color, gameboard, position) { if (color == IPieceColor.Black) { this.Image = (Brush)App.Current.FindResource("BlackBishop"); } else if (color == IPieceColor.White) { this.Image = (Brush)App.Current.FindResource("WhiteBishop"); } this.Gameboard.MovePiece(position, this); }
/// <summary> /// Initializes a new instance of the <see cref="Pawn"/> class. /// </summary> /// <param name="color">The piece color.</param> /// <param name="gameboard">The gameboard.</param> /// <param name="position">The starting position.</param> public Pawn(IPieceColor color, Gameboard gameboard, Position position) : base(color, gameboard, position) { if (color == IPieceColor.Black) { this.Image = (Brush)App.Current.FindResource("BlackPawn"); } else if (color == IPieceColor.White) { this.Image = (Brush)App.Current.FindResource("WhitePawn"); } this.firstMove = true; this.Gameboard.MovePiece(position, this); }
/// <summary> /// Initializes a new instance of the <see cref="ChessPiece"/> class. /// </summary> /// <param name="color">The piece color.</param> /// <param name="gameboard">The gameboard.</param> /// <param name="position">The starting position.</param> public ChessPiece(IPieceColor color, Gameboard gameboard, Position position) : base(color, gameboard, position) { }
/// <summary> /// Initializes a new instance of the <see cref="King"/> class. /// </summary> /// <param name="color">The piece color.</param> /// <param name="gameboard">The gameboard.</param> /// <param name="position">The starting position.</param> public King(IPieceColor color, Gameboard gameboard, Position position) : base(color, gameboard, position) { this.SetImage(color); this.Gameboard.MovePiece(position, this); }
/// <summary> /// Initializes a new instance of the <see cref="PieceBase"/> class. /// </summary> /// <param name="color">The piece color.</param> /// <param name="gameboard">The gameboard.</param> /// <param name="position">The starting position.</param> public PieceBase(IPieceColor color, Gameboard gameboard, Position position) { this.color = color; this.gameboard = gameboard; this.position = position; }
/// <summary> /// Moves the piece to the destination. /// </summary> /// <param name="destination">The destination.</param> /// <param name="ignoreMoveOptions">if set to <c>true</c> ignores move options.</param> /// <returns> /// <c>true</c> if successful, <c>false</c> if not. /// </returns> protected virtual bool MoveTo(Position destination, bool ignoreMoveOptions) { bool ret = false; if (ignoreMoveOptions || this.MoveOptions.Contains(destination)) { this.Gameboard.MovePiece(destination, this); this.position = destination; ret = true; } return ret; }
/// <summary> /// Moves the piece to the destination. /// </summary> /// <param name="destination">The destination.</param> /// <returns> /// <c>true</c> if successful, <c>false</c> if not. /// </returns> public virtual bool MoveTo(Position destination) { return this.MoveTo(destination, false); }
/// <summary> /// Attacks the specified target. /// </summary> /// <param name="target">The target.</param> /// <returns> /// <c>true</c> if successful, <c>false</c> if not. /// </returns> public virtual bool Attack(Position target) { bool ret = false; if (this.AttackOptions.Contains(target)) { this.Gameboard.Figures[target].Die(this); ret = this.MoveTo(target, true); } return ret; }
/// <summary> /// Moves the piece to the destination. /// </summary> /// <param name="destination">The destination.</param> /// <returns> /// <c>true</c> if successful, <c>false</c> if not. /// </returns> public override bool MoveTo(Position destination) { if (base.MoveTo(destination)) { this.firstMove = false; return true; } return false; }
/// <summary> /// Initializes a new instance of the <see cref="Position"/> struct. Copy constructor. /// </summary> /// <param name="pt">The source position.</param> public Position(Position pt) { this.x = pt.X; this.y = pt.Y; }
/// <summary> /// Calculates the distance between this position and <paramref name="position"/>. /// </summary> /// <param name="position">The position.</param> /// <returns>The distance between the two positions.</returns> public double DistanceFromPosition(Position position) { return Math.Sqrt( Math.Pow((this.X - position.X), 2) + Math.Pow((this.Y - position.Y), 2)); }
/// <summary> /// Calculates the distance between <paramref name="position1"/> and <paramref name="position2"/>. /// </summary> /// <param name="position1">The first position.</param> /// <param name="position2">The second position.</param> /// <returns>The distance between the two positions.</returns> public static double DistanceBetweenPositions(Position position1, Position position2) { return Math.Sqrt( Math.Pow((position1.X - position2.X), 2) + Math.Pow((position1.Y - position2.Y), 2)); }
/// <summary> /// Attacks the specified target. /// </summary> /// <param name="target">The target.</param> /// <returns> /// <c>true</c> if successful, <c>false</c> if not. /// </returns> public override bool Attack(Position target) { bool ret = false; if (this.AttackOptions.Contains(target)) { this.Gameboard.Figures[target].Die(this); target = (2 * (target - this.Position)) + this.Position; ret = this.MoveTo(target, true); } return ret; }
/// <summary> /// Moves the piece to the destination. /// </summary> /// <param name="destination">The destination.</param> /// <param name="ignoreMoveOptions">if set to <c>true</c> ignores move options.</param> /// <returns> /// <c>true</c> if successful, <c>false</c> if not. /// </returns> protected override bool MoveTo(Position destination, bool ignoreMoveOptions) { bool ret = base.MoveTo(destination, ignoreMoveOptions); if (ret) { if ((this.Color == IPieceColor.White && destination.Y == 0) || (this.Color == IPieceColor.Black && destination.Y == 7)) { this.NotifyOfGameEvent(this, GameEventType.Crowned); } } return ret; }