Example #1
0
    public static bool HasMatch()
    {
        List <BaseComponent> matchableComponents = Pool.Instance.ComponentsForType(typeof(MatchableComponent));
        MatchableComponent   target = null;
        bool hasMatch = true;

        foreach (MatchableComponent mac in matchableComponents)
        {
            ColorableComponent cac = mac.GetComponent <ColorableComponent>();

            if (target == null)
            {
                target = mac;
                continue;
            }

            Color targetColor = target.GetComponent <ColorableComponent>().color;
            if (targetColor != cac.color)
            {
                hasMatch = false;
            }
        }

        return(hasMatch);
    }
Example #2
0
    protected void SetupRound(int round)
    {
        GameController gc = GameController.Instance;

        if (round > 1)
        {
            gc.previousColor = gc.currentColor;
        }
        gc.currentColor = NextColor();
        gc.Target.GetComponent <ColorableComponent>().color = gc.currentColor;
        gc.Player.GetComponent <ColorableComponent>().color = gc.previousColor;

        int index       = 0;
        int lowerBound  = 0;
        int upperBound  = NumberOfButtonsUpperbound();
        int targetIndex = lowerBound + Utils.RandomInt(upperBound - lowerBound);

        Debug.Log(string.Format("Color is at location {0}", targetIndex));
        foreach (GameObject go in gc.ColorButtons)
        {
            ColorableComponent cac = go.GetComponent <ColorableComponent>();
            cac.color = Color.clear;
        }
        foreach (GameObject go in gc.ColorButtons)
        {
            ColorableComponent cac = go.GetComponent <ColorableComponent>();
            Color buttonColor      = Color.clear;

            if (index == targetIndex)
            {
                buttonColor = gc.currentColor;
            }
            else if (index >= lowerBound && index < upperBound)
            {
                buttonColor = SimilarColor(gc.currentColor, index);
            }

            if (buttonColor != Color.clear)
            {
                cac.color = buttonColor;
                ShowIfInactive(go);
            }
            else
            {
                HideIfActive(go);
            }
            index++;
        }

        if (ShouldShowAd(round))
        {
            gc.gameObject.AddComponent <AdComponent>();
        }
        gc.lastMatchTime = Time.time;
        Debug.Log(string.Format("Difficulty {0}", gc.difficulty));
        gc.PlayParticleForDifficulty();
    }
Example #3
0
    private void ClearCubes()
    {
        GameController gc           = GameController.Instance;
        Color          currentColor = gc.Target.GetComponent <ColorableComponent>().color;

        gc.Target.GetComponent <ColorableComponent>().color = Color.clear;
        gc.Player.GetComponent <ColorableComponent>().color = Color.clear;
        foreach (GameObject go in gc.ColorButtons)
        {
            ColorableComponent cac = go.GetComponent <ColorableComponent>();
            cac.color = Color.clear;
        }
    }
Example #4
0
    /*
     * - Start, set last color and therefore set background
     * - game should exist but all game objects should be inactive
     * - on start, we initialize the game w/ prev color and next color, show game objects
     * - play
     * - on end game, we hide all the things and then turn off the game objects
     * - on restart, we start game again w/ prev color and next color, show game objects
     * - on end total, we hide all the things and then turn off the game objects
     *
     * - tutorial
     * - inherit from roundsystem with tutorialroundsystem, overriding some things
     * - use queue of colors, or hardcode them per level in color chooser function
     */

    public override void Update()
    {
        GameController gc = (Controller() as GameController);

        if (!gc.isPlaying)
        {
            return;
        }
        if (gc.initializeGame)
        {
            gc.initializeGame = false;
            GameObject.Destroy(RoundSystem.GetExistingMatch());
            ClearCubes();
            Reset(gc.round);
        }

        if (GetExistingMatch() != null)
        {
            return;
        }

        List <BaseComponent> matchableComponents = Pool.Instance.ComponentsForType(typeof(MatchableComponent));
        MatchableComponent   target = null;
        bool hasMatch = true;

        foreach (MatchableComponent mac in matchableComponents)
        {
            ColorableComponent cac = mac.GetComponent <ColorableComponent>();

            if (target == null)
            {
                target = mac;
                continue;
            }

            Color targetColor = target.GetComponent <ColorableComponent>().color;
            if (targetColor != cac.color)
            {
                hasMatch = false;
            }
        }

        if (target)
        {
            if (hasMatch)
            {
                BaseObject.AddComponent <MatchComponent>();
            }
        }
    }
 public override void OnComponentAdded(BaseComponent c)
 {
     if (c is TouchComponent)
     {
         GameController     gameController = GameController.Instance;
         ColorableComponent cac            = c.gameObject.GetComponent <ColorableComponent>();
         if (cac.color != Color.clear)
         {
             gameController.Player.GetComponent <ColorableComponent>().color = cac.color;
             OnTouch();
         }
         GameObject.Destroy(c);
     }
 }
Example #6
0
    private void Reset(int round)
    {
        GameController gc           = GameController.Instance;
        Color          currentColor = gc.Target.GetComponent <ColorableComponent>().color;
        Color          randomColor  = Utils.RandomColor();
        Color          bgColor      = currentColor == Color.clear ? gc.background.GetComponent <SpriteRenderer>().color : currentColor;

        gc.background.GetComponent <SpriteRenderer>().color = bgColor;
        gc.Target.GetComponent <ColorableComponent>().color = randomColor;
        gc.Player.GetComponent <ColorableComponent>().color = bgColor;

        int index       = 0;
        int lowerBound  = 0;
        int upperBound  = Mathf.Min(gc.numberOfButtons, gc.ColorButtons.Count);
        int targetIndex = lowerBound + Utils.RandomInt(upperBound - lowerBound);

        Debug.Log(targetIndex);
        foreach (GameObject go in gc.ColorButtons)
        {
            Color buttonColor = Color.clear;
            if (index == targetIndex)
            {
                buttonColor = randomColor;
            }
            else if (index >= lowerBound && index < upperBound)
            {
                buttonColor = SimilarColor(randomColor);
            }

            if (buttonColor != Color.clear)
            {
                ColorableComponent cac = go.GetComponent <ColorableComponent>();
                cac.color = buttonColor;
            }
            index++;
        }

        if (gc.firstAdLevel == round)
        {
            gc.gameObject.AddComponent <AdComponent>();
        }
        gc.lastMatchTime = Time.time;
        Debug.Log(string.Format("Difficulty {0}", gc.difficulty));
        gc.PlayParticleForDifficulty();
    }
    // FIXME: ContextMenu doesn't work.
    //[ContextMenu("Initialize targetObj & targetCC")]
    protected void InitTargets()
    {
        if (targetCC == null)
        {
            if (targetObj == null)
            {
                targetObj = gameObject;
            }

            targetCC = Colorable.GetComponent(targetObj);
        }

        UnityEngine.Assertions.Assert.IsNotNull(
            targetCC,
            "No suitable Colorable Component was found in " + gameObject.name
            + " to be used by " + this.GetType().FullName
            );
    }
Example #8
0
    public override void Update()
    {
        GameController gc = (Controller() as GameController);

        if (!IsPlaying())
        {
            return;
        }

        if (GetExistingMatch() != null)
        {
            return;
        }

        List <BaseComponent> matchableComponents = Pool.Instance.ComponentsForType(typeof(MatchableComponent));
        MatchableComponent   target = null;
        bool hasMatch = true;

        foreach (MatchableComponent mac in matchableComponents)
        {
            ColorableComponent cac = mac.GetComponent <ColorableComponent>();

            if (target == null)
            {
                target = mac;
                continue;
            }

            Color targetColor = target.GetComponent <ColorableComponent>().color;
            if (targetColor != cac.color)
            {
                hasMatch = false;
            }
        }

        if (target)
        {
            if (hasMatch)
            {
                BaseObject.AddComponent <MatchComponent>();
            }
        }
    }
Example #9
0
    protected virtual bool IsSimilarToExistingColor(Color c, float minDiff)
    {
        GameController gc = (Controller() as GameController);

        foreach (GameObject go in gc.ColorButtons)
        {
            ColorableComponent cc = go.GetComponent <ColorableComponent>();
            if (cc.color == Color.clear)
            {
                continue;
            }
            if (Similarity(c, cc.color) < minDiff)
            {
                return(true);
            }
        }

        return(false);
    }
Example #10
0
    protected override Color SimilarColor(Color c, int index)
    {
        if (index >= _maxNumberButtons)
        {
            return(Color.clear);
        }
        GameController gc           = (Controller() as GameController);
        List <Color>   randomColors = new List <Color> {
            Color.red,
            Color.blue,
            Color.yellow,
            Color.green,
            Color.cyan,
            Color.magenta,
            Color.grey,
            //Color.white,
            //Color.black,
        };
        List <Color> usedColors = new List <Color> {
            c, gc.previousColor
        };

        foreach (GameObject go in gc.ColorButtons)
        {
            ColorableComponent cc = go.GetComponent <ColorableComponent>();
            usedColors.Add(cc.color);
        }
        Color ret;

        do
        {
            int i = Utils.RandomInt(randomColors.Count);
            ret = randomColors[i];
        } while (usedColors.Contains(ret));

        return(ret);
    }