// Returns whether we could do it. bool TryMovePiece(int x, int y) { Coordinate forcastedLocation = new Coordinate(currentPieceLocation.X + x, currentPieceLocation.Y + y); FourCoordinates forcastedCoordinates = GetPieceCoordinates(forcastedLocation, currentPieceType, currentPieceRotation); if (CanPlacePieceAt(forcastedCoordinates)) { currentPieceLocation = forcastedLocation; return(true); } return(false); }
public bool TryRotatePiece() { int forcastedIndex = (currentPieceRotation + 1) % 4; int forcastedRotation = forcastedIndex % pieceLayouts[currentPieceType].EachRotation.Count; FourCoordinates forcastedCoordinates = GetPieceCoordinates(currentPieceLocation, currentPieceType, forcastedRotation); if (CanPlacePieceAt(forcastedCoordinates)) { currentPieceRotation = forcastedIndex; return(true); } return(false); }
private FourCoordinates GetPieceCoordinates(Coordinate pieceLocation, int pieceType, int pieceRotation) { int effectiveRotation = pieceRotation % pieceLayouts[pieceType].EachRotation.Count; FourCoordinates r = new FourCoordinates(pieceLayouts[pieceType].EachRotation[effectiveRotation]); for (int i = 0; i < 4; ++i) { r.Location[i].X += pieceLocation.X; r.Location[i].Y += pieceLocation.Y; } return(r); }
bool CommitCurrentPiece() { FourCoordinates currentPieceCoordinates = GetCurrentPieceCoordinates(); for (int i = 0; i < 4; i++) { if (!SetCell(currentPieceCoordinates.Location[i], currentPieceType, false)) { return(false); } } score += maxForceDropThisPiece; return(true); }
bool CanPlacePieceAt(FourCoordinates coordinates) { for (int i = 0; i < 4; i++) { var l = coordinates.Location[i]; // No comparison for y < 0, since pieces are allowed to hang off the top. if (l.X < 0 || l.X >= gridWidth || l.Y >= gridHeight) { return(false); } int cell = GetCell(l.X, l.Y); if (cell != -1) { return(false); } } return(true); }
public FourCoordinates(FourCoordinates other) { Location = (Coordinate[])other.Location.Clone(); }