Exemple #1
0
    public static Box.Element[] getRandomBoxElements(int quantity, bool rollQuintessentialOnlyOnce = true)
    {
        Box.Element[] result = new Box.Element[quantity];

        bool hasQuint   = (rollQuintessentialOnlyOnce && Random.value < typeWeights[(int)Box.Element.quintessential] / typeWeights.Sum()) ? true : false;
        int  quintIndex = Random.Range(0, quantity);

        int sameCount = 0;

        for (int i = 0; i < quantity; i++)
        {
            if (i == quintIndex && hasQuint)
            {
                result[quintIndex] = Box.Element.quintessential;
            }
            else
            {
                result[i] = (Box.Element)Random.Range(0, System.Enum.GetNames(typeof(Box.Element)).Length - 1);
                if (hasQuint)
                {
                    if (result.ToList().FindAll(x => x == result[i]).Count > 1)
                    {
                        Box.Element repeated  = result[i];
                        int         loopcount = 0;
                        while ((result[i] == repeated || result[i] == Box.Element.quintessential) && loopcount < 100)
                        {
                            result[i] = (Box.Element)Random.Range(0, System.Enum.GetNames(typeof(Box.Element)).Length - 1);
                            loopcount++;
                        }
                    }
                }
                else
                {
                    if (result.ToList().FindAll(x => x == result[i]).Count > 2)
                    {
                        Box.Element repeated  = result[i];
                        int         loopcount = 0;
                        while ((result[i] == repeated || result[i] == Box.Element.quintessential) && loopcount < 100)
                        {
                            result[i] = (Box.Element)Random.Range(0, System.Enum.GetNames(typeof(Box.Element)).Length - 1);
                            loopcount++;
                        }
                    }
                }
            }
        }

        return(result);
    }
Exemple #2
0
    public static Color32 getElementColor(Box.Element el)
    {
        switch (el)
        {
        case Element.ground:
            return(new Color32(205, 140, 74, 255));

            break;

        case Element.fire:
            return(new Color32(231, 76, 60, 255));

            break;

        case Element.water:
            return(new Color32(47, 149, 208, 255));

            break;

        case Element.grass:
            return(new Color32(46, 204, 113, 255));

            break;

        case Element.steel:
            return(new Color32(137, 164, 166, 255));

            break;

        case Element.quintessential:
            return(new Color32(110, 0, 133, 255));

            break;

        default:
            return(new Color32(0, 0, 0, 255));

            break;
        }
    }
Exemple #3
0
    public void Vanish(Sprite newSprite, Box.Element el)
    {
        Sequence vanish = DOTween.Sequence();

        vanish.Append(transform.DOScale(new Vector3(1.2f, 1.2f, 1), boxAnimationTime / 2));
        vanish.Append(transform.DOScale(new Vector3(0, 0, 1), boxAnimationTime / 2));

        // vanish.OnStart(() => { print("startii"); });

        //vanish.OnKill(() => {
        //    GetComponent<Image>().sprite = newSprite;
        //    GetComponent<Image>().color = (el == Box.Element.quintessential) ? Box.quintessentialColor : (Color32)Color.white;
        //    appear();
        //    print("killed"); });

        vanish.OnComplete(() =>
        {
            GetComponent <Image>().sprite = newSprite;
            GetComponent <Image>().color  = (el == Box.Element.quintessential) ? Box.quintessentialColor : (Color32)Color.white;

            appear();
            // print("completed"); });
        });
    }
Exemple #4
0
    public List <Box> getConnectedMatches(UtilityTools.Directions axisDir)
    {
        Box.Element matchElement = this.element;
        List <Box>  result       = new List <Box>();

        int maxLoops = 0;

        if (matchElement == Box.Element.quintessential)
        {
            print("roxo!");
        }

        if (UtilityTools.horizontals.Contains(axisDir))
        {
            if (getNeighbourTile(UtilityTools.Directions.right) == null && getNeighbourTile(UtilityTools.Directions.left) == null)
            {
                return(result);
            }

            //get all connected ones left and right
            List <Box> mixedRight = (getConnectedBoxes(UtilityTools.Directions.right));
            List <Box> mixedLeft  = (getConnectedBoxes(UtilityTools.Directions.left));

            if (this.element == Element.quintessential)
            {
                Element leftElement  = Element.quintessential;
                Element rightElement = Element.quintessential;
                Box     neigh        = getNextNonElementNeighbour(UtilityTools.Directions.right, this.element, ref maxLoops);
                if (neigh != null)
                {
                    rightElement = neigh.GetElement();
                }

                neigh = getNextNonElementNeighbour(UtilityTools.Directions.left, this.element, ref maxLoops);

                if (neigh != null)
                {
                    leftElement = neigh.GetElement();
                }

                //if different, need to check for matches at the left and at the right
                if (leftElement != rightElement)
                {
                    mixedLeft  = mixedLeft.Distinct().OrderBy(x => x.GetPoint().x).ToList();
                    mixedRight = mixedRight.Distinct().OrderBy(x => x.GetPoint().x).ToList();

                    mixedLeft.RemoveAll(x => x.GetElement() != leftElement && x.GetElement() != Box.Element.quintessential);
                    mixedRight.RemoveAll(x => x.GetElement() != rightElement && x.GetElement() != Box.Element.quintessential);
                    mixedLeft  = getFirstConnectedMatches(mixedLeft);
                    mixedRight = getFirstConnectedMatches(mixedRight);

                    bool leftPass  = false;
                    bool rightPass = false;

                    //if (areAllConnected(axisDir, mixedLeft) && mixedLeft.Count >= TheGrid.matchSize)
                    //{
                    //    result.AddRange(mixedLeft);
                    //    leftPass = true;
                    //}
                    //if (areAllConnected(axisDir, mixedRight) && mixedRight.Count >= TheGrid.matchSize)
                    //{
                    //    rightPass = true;
                    //}

                    //if (rightPass)
                    //{
                    //    if ((leftPass && mixedRight.Count > mixedLeft.Count) || leftPass == false)
                    //    {
                    //        result.AddRange(mixedRight);
                    //    }
                    //}
                    //else if (leftPass)
                    //{
                    //    if ((rightPass && mixedRight.Count < mixedLeft.Count) || rightPass == false)
                    //    {
                    //        result.AddRange(mixedRight);
                    //    }
                    //}

                    if (mixedLeft.Count >= TheGrid.matchSize && mixedRight.Count < mixedLeft.Count)
                    {
                        result.AddRange(mixedLeft);
                    }
                    else if (mixedRight.Count >= TheGrid.matchSize && mixedRight.Count > mixedLeft.Count)
                    {
                        result.AddRange(mixedRight);
                    }

                    if (result.Count < TheGrid.matchSize || result.Any(y => y.isMatchable() == false))
                    {
                        result.Clear();
                    }

                    return(result);
                }
                else
                {
                    matchElement = rightElement;
                }
            }

            result.AddRange(mixedLeft.Distinct());
            result.AddRange(mixedRight.Distinct());

            //order them by left to right
            result = result.Distinct().OrderBy(x => x.GetPoint().x).ToList();

            //remove all elements that arent a match (itself or quint)
            result.RemoveAll(x => x.GetElement() != matchElement && x.GetElement() != Box.Element.quintessential);
            result = getFirstConnectedMatches(result);

            //not matches!!!
            if (!areAllConnected(axisDir, result) || result.Count < TheGrid.matchSize || result.Any(y => y.isMatchable() == false))
            {
                result.Clear();
            }

            return(result);
        }
        else if (UtilityTools.verticals.Contains(axisDir))
        {
            if (getNeighbourTile(UtilityTools.Directions.up) == null && getNeighbourTile(UtilityTools.Directions.down) == null)
            {
                return(result);
            }

            //get all connected ones left and right
            List <Box> mixedUp   = (getConnectedBoxes(UtilityTools.Directions.up));
            List <Box> mixedDown = (getConnectedBoxes(UtilityTools.Directions.down));

            if (this.element == Element.quintessential)
            {
                Element downElement = Element.quintessential;
                Element upElement   = Element.quintessential;
                Box     neigh       = getNextNonElementNeighbour(UtilityTools.Directions.up, this.element, ref maxLoops);
                if (neigh != null)
                {
                    upElement = neigh.GetElement();
                }

                neigh = getNextNonElementNeighbour(UtilityTools.Directions.down, this.element, ref maxLoops);

                if (neigh != null)
                {
                    downElement = neigh.GetElement();
                }

                //if different, need to check for matches at the left and at the right
                if (downElement != upElement)
                {
                    mixedDown = mixedDown.Distinct().OrderBy(x => x.GetPoint().y).ToList();
                    mixedUp   = mixedUp.Distinct().OrderBy(x => x.GetPoint().y).ToList();

                    mixedDown.RemoveAll(x => x.GetElement() != downElement && x.GetElement() != Box.Element.quintessential);
                    mixedUp.RemoveAll(x => x.GetElement() != upElement && x.GetElement() != Box.Element.quintessential);
                    mixedDown = getFirstConnectedMatches(mixedDown);
                    mixedUp   = getFirstConnectedMatches(mixedUp);

                    bool downPass = false;
                    bool upPass   = false;
                    //if (areAllConnected(axisDir, mixedDown) && mixedDown.Count >= TheGrid.matchSize)
                    //{
                    //    result.AddRange(mixedDown);
                    //    downPass = true;
                    //}
                    //if (areAllConnected(axisDir, mixedUp) && mixedUp.Count >= TheGrid.matchSize)
                    //{
                    //    upPass = true;
                    //}

                    //if (upPass)
                    //{
                    //    if ((downPass && mixedUp.Count > mixedDown.Count) || downPass == false)
                    //    {
                    //        result.AddRange(mixedUp);
                    //    }
                    //}
                    //else if (downPass)
                    //{
                    //    if ((upPass && mixedUp.Count < mixedDown.Count) || upPass == false)
                    //    {
                    //        result.AddRange(mixedUp);
                    //    }
                    //}

                    if (mixedUp.Count >= TheGrid.matchSize && mixedUp.Count > mixedDown.Count)
                    {
                        result.AddRange(mixedUp);
                    }
                    else if (mixedDown.Count >= TheGrid.matchSize && mixedDown.Count > mixedUp.Count)
                    {
                        result.AddRange(mixedDown);
                    }

                    if (result.Count < TheGrid.matchSize || result.Any(y => y.isMatchable() == false))
                    {
                        result.Clear();
                    }

                    return(result);
                }
                else
                {
                    matchElement = upElement;
                }
            }

            result.AddRange(mixedDown.Distinct());
            result.AddRange(mixedUp.Distinct());

            //order them by left to right
            result = result.Distinct().OrderBy(x => x.GetPoint().y).ToList();

            //remove all elements that arent a match (itself or quint)
            result.RemoveAll(x => x.GetElement() != matchElement && x.GetElement() != Box.Element.quintessential);
            result = getFirstConnectedMatches(result);

            //not matches!!!
            if (!areAllConnected(axisDir, result) || result.Count < TheGrid.matchSize || result.Any(y => y.isMatchable() == false))
            {
                result.Clear();
            }

            return(result);
        }
        else
        {
            return(result);
        }
    }