Example #1
0
            // 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);
            }
Example #2
0
            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);
            }
Example #3
0
            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);
            }
Example #4
0
            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);
            }
Example #5
0
            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);
            }
Example #6
0
 public FourCoordinates(FourCoordinates other)
 {
     Location = (Coordinate[])other.Location.Clone();
 }