// Given an increment of movement defined by an xStep and a yStep, // returns the list of GridLocations that exist in that direction, // up to the edge of an 8x8 board. public IList <IGridLocation> LocationsInDirection(sbyte xStep, sbyte yStep) { IList <IGridLocation> destinations = new List <IGridLocation>(); IGridLocation currentLocation = new GridLocation(XCoord, YCoord); currentLocation = currentLocation.RelativeLocation(xStep, yStep); while (currentLocation.OnBoard()) { // Add this square to the list of destinations and go on to the next one. destinations.Add(currentLocation); currentLocation = currentLocation.RelativeLocation(xStep, yStep); } // If blocked by the edge, return the list of squares we reached return(destinations); }
// Given the coordinates of a square, returns the PieceType associated with that square at initital setup. public ISquare CreateSquare(GridLocation location) { byte i = location.XCoord; byte j = location.YCoord; if (j > 1 && j < 6) { return(new Square(location)); } if (j == 1) { return(new Square(location, PieceType.Pawn, PieceColour.Black)); } if (j == 6) { return(new Square(location, PieceType.Pawn, PieceColour.White)); } PieceColour colour = j > 3 ? PieceColour.White : PieceColour.Black; switch (i) { case 0: case 7: return(new Square(location, PieceType.Rook, colour)); case 1: case 6: return(new Square(location, PieceType.Knight, colour)); case 2: case 5: return(new Square(location, PieceType.Bishop, colour)); case 3: return(new Square(location, PieceType.Queen, colour)); case 4: return(new Square(location, PieceType.King, colour)); default: return(new Square(location, PieceType.None, colour)); } }
public PieceBox(GridLocation location) : base() { DoubleBuffered = true; GridLocation = location; }