Exemplo n.º 1
0
        private int GetCoinValue(CoinTypes coin)
        {
            Type      coinType           = typeof(CoinTypes);
            FieldInfo coinInType         = coinType.GetField(coin.ToString());
            var       coinValueAttribute = coinInType.GetCustomAttribute <CoinValueAttribute>(false);

            //hi
            return(coinValueAttribute.Value);
        }
Exemplo n.º 2
0
        public void GiveChange()
        {
            for (int i = 1; i < 5; i++)
            {
                CoinTypes coinType  = (CoinTypes)i;
                int       coinValue = GetCoinValue(coinType);

                int counter = 0;
                while (Cents / coinValue > 0 && CoinInventory[coinType] > 0)
                {
                    Cents -= coinValue;
                    CoinInventory[coinType]--;
                    counter++;
                }
                Console.WriteLine($"Here is {counter} {coinType.ToString()}");
            }
        }
Exemplo n.º 3
0
    void OnTriggerEnter2D(Collider2D col)
    {
        CoinControler coin = col.gameObject.GetComponent <CoinControler>();

        if (col.tag == "Coin" && !completed)
        {
            if (gm.difficulty == GameManager.Difficulty.Beginner)
            {
                if (coin.coinTypes.ToString() == coinTypes.ToString())
                {
                    sprite.color             = Color.green;
                    correctSprite.spriteName = "Correct";
                    correctSprite.alpha      = 1f;
                    gm.PlayMatchAudio(true);

                    gm.activeCoins--;
                    gm.correctNum++;
                    SetComplete();

                    coin.matched = true;
                }
                else
                {
                    coinSprite.alpha         = 0f;
                    sprite.color             = Color.red;
                    correctSprite.spriteName = "Incorrect";
                    correctSprite.alpha      = 1f;
                    gm.PlayMatchAudio(false);
                    gm.incorrectNum++;
                }
            }
            else if (gm.difficulty == GameManager.Difficulty.Advanced)
            {
                if (targetValue + coin.value <= 100)
                {
                    sprite.color             = Color.green;
                    correctSprite.spriteName = "Correct";
                    correctSprite.alpha      = 1f;
                    gm.PlayMatchAudio(true);
                    targetValue += coin.value;

                    if (targetValue == 100)
                    {
                        gm.correctNum++;
                        SetComplete();
                    }

                    coin.matched = true;
                }
                else
                {
                    sprite.color             = Color.red;
                    correctSprite.spriteName = "Incorrect";
                    correctSprite.alpha      = 1f;
                    gm.PlayMatchAudio(false);
                    gm.incorrectNum++;
                }
            }
            else if (gm.difficulty == GameManager.Difficulty.Expert)
            {
                if (currentValue + coin.value <= targetValue)
                {
                    sprite.color             = Color.green;
                    correctSprite.spriteName = "Correct";
                    correctSprite.alpha      = 1f;
                    gm.PlayMatchAudio(true);
                    currentValue += coin.value;

                    if (currentValue == targetValue)
                    {
                        gm.correctNum++;
                        SetComplete();
                    }

                    coin.matched = true;
                }
                else
                {
                    sprite.color             = Color.red;
                    correctSprite.spriteName = "Incorrect";
                    correctSprite.alpha      = 1f;
                    gm.PlayMatchAudio(false);
                    gm.incorrectNum++;
                }
            }

            UpdateLabel();
        }
    }