Beispiel #1
0
    public void GetNextPiece()
    {
        CurrentSelectedPiece = null;
        CurrentPieceRotation = (BasePiece.RotationDirection)Random.Range(0, (int)BasePiece.RotationDirection.Count); //BasePiece.RotationDirection.Normal;

        List <BoardGridLocation> availableLocations = new List <BoardGridLocation>();

        int xLength = BoardGridLocations.GetLength(0);
        int yLength = BoardGridLocations.GetLength(1);

        for (int x = 0; x < xLength; x++)
        {
            for (int y = 0; y < yLength; y++)
            {
                BoardGridLocation checkLocation = BoardGridLocations[x, y];

                if (checkLocation == null || checkLocation.InUse)
                {
                    continue;
                }

                availableLocations.Add(checkLocation);
            }
        }

        int targetCategory = 0;
        int totalTiles     = xLength * yLength;
        int availableTiles = availableLocations.Count;

        if (availableTiles > ((float)totalTiles * 0.8f))
        {
            targetCategory = 2;
        }
        else if (availableTiles > (float)(totalTiles * 0.5f))
        {
            targetCategory = 1;
        }
        else
        {
            targetCategory = 0;
        }


        List <int> checkPieces = GetPieceIndexesForCategory(targetCategory);
        int        pieceIndex  = 0;

        if (checkPieces != null && checkPieces.Count > 0)
        {
            pieceIndex = checkPieces[Random.Range(0, checkPieces.Count)];
        }

        UpdatePiece(pieceIndex);

        if (availableLocations.Count > 0)
        {
            BoardGridLocation randomStartingPlace = availableLocations[Random.Range(0, availableLocations.Count)];
            MoveCurrentPieceToBoardLocation(randomStartingPlace);
        }
    }
Beispiel #2
0
    public void ChangeRotation(int dir)
    {
        int nextRotationIndex = ((int)CurrentPieceRotation + dir + (int)BasePiece.RotationDirection.Count) % (int)BasePiece.RotationDirection.Count;

        CurrentPieceRotation = (BasePiece.RotationDirection)nextRotationIndex;

        if (CurrentSelectedPiece != null)
        {
            CurrentSelectedPiece.RotatePiece(CurrentPieceRotation);
            SFXManager.instance.PlayAudioClip(RotateAudioClip);
        }
    }