Exemple #1
0
        public void TestEquality()
        {
            var hp1 = new Potion();

            hp1.SetKind(PotionKind.Health);

            var hp2 = new Potion();

            hp2.SetKind(PotionKind.Health);

#pragma warning disable
            Assert.True(hp1 == hp1);
#pragma warning restore
            Assert.True(hp1.Equals(hp1));
            Assert.True(hp1.Equals(hp2));

            var mp1 = new Potion();
            mp1.SetKind(PotionKind.Mana);
            Assert.False(hp1.Equals(mp1));
            Assert.False(hp1 == mp1);

            var game = CreateGame();
            game.Hero.Inventory.Add(hp1);
            Assert.AreEqual(game.Hero.Inventory.ItemsCount, 1);
            game.Hero.Inventory.Add(hp2);
            Assert.AreEqual(game.Hero.Inventory.ItemsCount, 1);

            game.Hero.Inventory.Add(mp1);
            Assert.AreEqual(game.Hero.Inventory.ItemsCount, 2);

            game.GameManager.Save();
            game.Hero.Inventory.Items.Clear();
            Assert.AreEqual(game.Hero.Inventory.ItemsCount, 0);
            Assert.False(game.Hero.Inventory.Contains(hp1));

            game.GameManager.Load(game.Hero.Name);
            Assert.AreEqual(game.Hero.Inventory.ItemsCount, 2);

            Assert.True(game.Hero.Inventory.Contains(hp1));
            Assert.True(game.Hero.Inventory.Contains(hp2));

            var hp3 = new Potion();
            hp3.SetKind(PotionKind.Health);
            Assert.True(game.Hero.Inventory.Contains(hp3));
            game.Hero.Inventory.Add(hp3);

            Assert.AreEqual(game.Hero.Inventory.ItemsCount, 2);
        }
Exemple #2
0
    private void BrewPotion(Potion currentPotion)
    {
        Potion newPotion;

        if (currentPotion.Equals(corrosivePotion))
        {
            newPotion = corrosivePotion;
            successParticles.Play();
            successSound.Play();
        }
        else if (currentPotion.Equals(growPlantPotion))
        {
            newPotion = growPlantPotion;
            successParticles.Play();
            successSound.Play();
        }
        else if (currentPotion.Equals(burnPotion))
        {
            newPotion = burnPotion;
            successParticles.Play();
            successSound.Play();
        }
        else if (currentPotion.Equals(freezePotion))
        {
            newPotion = freezePotion;
            successParticles.Play();
            successSound.Play();
        }
        else if (currentPotion.Equals(explodePotion))
        {
            newPotion = explodePotion;
            successParticles.Play();
            successSound.Play();
        }
        else
        {
            newPotion = new Potion("Bad potion");
            failureParticles.Play();
            failureSound.Play();
        }

        Debug.Log("New potion is determined on line 87 of Couldron.cs: " + newPotion.name);
        Brewed(newPotion.name);
    }