/// <summary> /// Created the row's squares. /// </summary> /// <param name="rowIndex">The index of this row on the board.</param> private void CreateSquares(int rowIndex) { for (int i = 0; i < Squares.Length; i++) { Squares[i] = new BoardSquare(i, rowIndex); } }
/// <summary> /// Constructor. /// </summary> /// <param name="piece">The piece on the move.</param> /// <param name="destination">The destination of the piece.</param> /// <param name="eaten">The piece being eaten (deleted) by the move. /// </param> public BoardMove(Piece piece, BoardSquare destination, Piece eaten) { Piece = piece; Destination = destination; PieceEaten = eaten; }
/// <summary> /// Get square in a given direction of another square. /// </summary> /// <param name="square">The reference square.</param> /// <param name="direction">The desired direction.</param> /// <returns>The square at the given direction. /// Can be null, meaning no available square exists in that direction. /// </returns> private BoardSquare GetBoardSquareByDirection(BoardSquare square, Direction direction) { Coord pos; BoardSquare result = null; pos = GetNewCoordinates(square, direction); if (GetIsPositionValid(pos)) { result = Rows[pos.Row].Squares[pos.Column]; } return(result); }
/// <summary> /// Calculates the new coordinates that a move in a /// given direction would result in. /// </summary> /// <param name="square">The reference square.</param> /// <param name="direction">The desired direction.</param> /// <returns></returns> private Coord GetNewCoordinates(BoardSquare square, Direction direction) { Coord delta, result, oldCoords = square.Pos; if (oldCoords.Row == 1 || oldCoords.Row == 3) { if (direction == Direction.DownRight || direction == Direction.DownLeft) { direction = Direction.Down; } else if (direction == Direction.UpRight || direction == Direction.UpLeft) { direction = Direction.Up; } } switch (direction) { case Direction.Up: if (oldCoords.Row == 2) { delta = new Coord(-1, 1); } else { delta = new Coord(-1, 0); } break; case Direction.Down: if (oldCoords.Row == 2) { delta = new Coord(1, 1); } else { delta = new Coord(1, 0); } break; case Direction.Right: delta = new Coord(0, 1); break; case Direction.Left: delta = new Coord(0, -1); break; case Direction.UpRight: delta = new Coord(-1, 2); break; case Direction.UpLeft: delta = new Coord(-1, 0); break; case Direction.DownRight: delta = new Coord(1, 2); break; case Direction.DownLeft: delta = new Coord(1, 0); break; default: delta = new Coord(0, 0); break; } result = oldCoords + delta; if (oldCoords.Row != 2 && result.Row == 2) { result = new Coord(2, 0); } return(result); }
/// <summary> /// Sets the reference to the current location of this piece. /// </summary> /// <param name="square">The current square this piece is at.</param> public void SetBoardSquareReference(BoardSquare square) { Square = square; }