示例#1
0
    private int GetCountToNextLegalRotation(HackCard hackcard, int startingRotation = 0)
    {
        FindAndStoreAdjacentSquares();

        // We check all four rotations for a match and allow placing the square if there are any
        // If there are, we return the number of rotations necessary for later processing
        // If there are none, we return -1
        // Starting rotation is set to 1 if we want to find the next legal rotation and skip 'no rotation'
        for (int rotations = startingRotation; rotations < 4; rotations++)
        {
            string rotatedLeftCircuit   = hackcard.GetLeftCircuit();
            string rotatedTopCircuit    = hackcard.GetTopCircuit();
            string rotatedRightCircuit  = hackcard.GetRightCircuit();
            string rotatedBottomCircuit = hackcard.GetBottomCircuit();
            for (int i = 0; i < rotations; i++)
            {
                string previousLeftCircuit = rotatedLeftCircuit;
                rotatedLeftCircuit   = rotatedBottomCircuit;
                rotatedBottomCircuit = rotatedRightCircuit;
                rotatedRightCircuit  = rotatedTopCircuit;
                rotatedTopCircuit    = previousLeftCircuit;
            }
            bool isCurrentRotationLegal = CheckRotation(rotatedLeftCircuit, rotatedTopCircuit, rotatedRightCircuit, rotatedBottomCircuit);
            if (isCurrentRotationLegal)
            {
                return(rotations);
            }
        }
        return(-1);
    }
示例#2
0
    private int GetCountToPreviousLegalRotation(HackCard hackcard, int startingRotation = 0)
    {
        FindAndStoreAdjacentSquares();

        for (int rotations = startingRotation; rotations < 4; rotations++)
        {
            string rotatedLeftCircuit   = hackcard.GetLeftCircuit();
            string rotatedTopCircuit    = hackcard.GetTopCircuit();
            string rotatedRightCircuit  = hackcard.GetRightCircuit();
            string rotatedBottomCircuit = hackcard.GetBottomCircuit();
            for (int i = 0; i < rotations; i++)
            {
                string previousLeftCircuit = rotatedLeftCircuit;
                rotatedLeftCircuit   = rotatedTopCircuit;
                rotatedTopCircuit    = rotatedRightCircuit;
                rotatedRightCircuit  = rotatedBottomCircuit;
                rotatedBottomCircuit = previousLeftCircuit;
            }
            bool isCurrentRotationLegal = CheckRotation(rotatedLeftCircuit, rotatedTopCircuit, rotatedRightCircuit, rotatedBottomCircuit);
            if (isCurrentRotationLegal)
            {
                return(rotations);
            }
        }
        return(-1);
    }
    public void AddConnectionsToActiveCard(int number, string color)
    {
        HackCard topCard = cards[0];

        // in circuit array: 0 = left, 1 = top, 2 = right, 3 = bottom
        string[]   circuits              = { topCard.GetLeftCircuit(), topCard.GetTopCircuit(), topCard.GetRightCircuit(), topCard.GetBottomCircuit() };
        List <int> emptyColorIndices     = new List <int>();
        List <int> differentColorIndices = new List <int>();
        List <int> sameColorIndices      = new List <int>();

        for (int i = 0; i < circuits.Length; i++)
        {
            if (circuits[i] == color)
            {
                sameColorIndices.Add(i);
            }
            else if (circuits[i] == "none")
            {
                emptyColorIndices.Add(i);
            }
            else
            {
                differentColorIndices.Add(i);
            }
        }

        for (int i = 0; i < number; i++)
        {
            if (emptyColorIndices.Count > 0)
            {
                int indexToUse = Random.Range(0, emptyColorIndices.Count);
                SetTemporaryCircuit(emptyColorIndices[indexToUse], color);
                emptyColorIndices.RemoveAt(indexToUse);
            }
            else if (differentColorIndices.Count > 0)
            {
                int indexToUse = Random.Range(0, differentColorIndices.Count);
                SetTemporaryCircuit(differentColorIndices[indexToUse], color);
                differentColorIndices.RemoveAt(indexToUse);
            }
        }

        SetTopCard();
    }
    public void SetTopCard()
    {
        Image[]        imageHolders   = GetComponentsInChildren <Image>();
        AllSpikeImages allSpikeImages = FindObjectOfType <AllSpikeImages>();

        if (cards.Count == 0)
        {
            foreach (Image image in imageHolders)
            {
                image.sprite = allSpikeImages.GetEmptyImage();
            }
        }
        else
        {
            HackCard topCard = cards[0];
            foreach (Image image in imageHolders)
            {
                switch (image.name)
                {
                case "HackDeckCardBack":
                    image.sprite = allSpikeImages.GetCardBack();
                    break;

                case "LeftCircuit":
                    string color;
                    if (tempLeftCircuit != null)
                    {
                        color = tempLeftCircuit;
                    }
                    else
                    {
                        color = topCard.GetLeftCircuit();
                    }
                    Sprite currentImage = allSpikeImages.GetCircuitImageByColorAndDirection(color, "left");
                    image.sprite = currentImage;
                    break;

                case "TopCircuit":
                    if (tempTopCircuit != null)
                    {
                        color = tempTopCircuit;
                    }
                    else
                    {
                        color = topCard.GetTopCircuit();
                    }
                    currentImage = allSpikeImages.GetCircuitImageByColorAndDirection(color, "top");
                    image.sprite = currentImage;
                    break;

                case "RightCircuit":
                    if (tempRightCircuit != null)
                    {
                        color = tempRightCircuit;
                    }
                    else
                    {
                        color = topCard.GetRightCircuit();
                    }
                    currentImage = allSpikeImages.GetCircuitImageByColorAndDirection(color, "right");
                    image.sprite = currentImage;
                    break;

                case "DownCircuit":
                    if (tempBottomCircuit != null)
                    {
                        color = tempBottomCircuit;
                    }
                    else
                    {
                        color = topCard.GetBottomCircuit();
                    }
                    currentImage = allSpikeImages.GetCircuitImageByColorAndDirection(color, "bottom");
                    image.sprite = currentImage;
                    break;

                case "TopLeftSpike":
                    Spike  currentspike = topCard.GetTopLeftSpike();
                    string state        = currentspike.GetSpikeState();
                    color        = currentspike.GetSpikeColor();
                    currentImage = allSpikeImages.GetSpikebyColorCornerAndState(color, "topleft", state);
                    image.sprite = currentImage;
                    break;

                case "TopRightSpike":
                    currentspike = topCard.GetTopRightSpike();
                    state        = currentspike.GetSpikeState();
                    color        = currentspike.GetSpikeColor();
                    currentImage = allSpikeImages.GetSpikebyColorCornerAndState(color, "topright", state);
                    image.sprite = currentImage;
                    break;

                case "BottomLeftSpike":
                    currentspike = topCard.GetBottomLeftSpike();
                    state        = currentspike.GetSpikeState();
                    color        = currentspike.GetSpikeColor();
                    currentImage = allSpikeImages.GetSpikebyColorCornerAndState(color, "bottomleft", state);
                    image.sprite = currentImage;
                    break;

                case "BottomRightSpike":
                    currentspike = topCard.GetbottomRightSpike();
                    state        = currentspike.GetSpikeState();
                    color        = currentspike.GetSpikeColor();
                    currentImage = allSpikeImages.GetSpikebyColorCornerAndState(color, "bottomright", state);
                    image.sprite = currentImage;
                    break;

                case "CardImage":
                    image.sprite = topCard.GetCardImage();
                    break;
                }
            }
        }
    }