Пример #1
0
        public void SaveLoadStacked()
        {
            var game = CreateGame();
            var hero = game.Hero;

            var mush1 = new Mushroom();

            mush1.SetMushroomKind(MushroomKind.Boletus);
            hero.Inventory.Add(mush1);

            var mush2 = new Mushroom();

            mush2.SetMushroomKind(MushroomKind.RedToadstool);
            hero.Inventory.Add(mush2);
            Assert.AreEqual(hero.Inventory.Items.Count, 2);

            var mush3 = new Mushroom();

            mush3.SetMushroomKind(MushroomKind.RedToadstool);
            hero.Inventory.Add(mush3);
            Assert.AreEqual(hero.Inventory.Items.Count, 2);

            Assert.AreEqual(hero.Inventory.GetStackedCount(mush1), 1);
            Assert.AreEqual(hero.Inventory.GetStackedCount(mush2), 2);

            var plant1 = new Plant();

            plant1.SetKind(PlantKind.Thistle);
            hero.Inventory.Add(plant1);
            Assert.AreEqual(hero.Inventory.Items.Count, 3);

            var plant2 = new Plant();

            plant2.SetKind(PlantKind.Thistle);
            hero.Inventory.Add(plant2);
            Assert.AreEqual(hero.Inventory.Items.Count, 3);
            Assert.AreEqual(hero.Inventory.GetStackedCount(plant2), 2);

            game.GameManager.Save();
            game.GameManager.Load(hero.Name);

            var heroLoaded = game.GameManager.Hero;

            Assert.AreEqual(heroLoaded.Inventory.GetStackedCount(mush1), 1);
            Assert.AreEqual(heroLoaded.Inventory.GetStackedCount(mush2), 2);
            Assert.AreEqual(heroLoaded.Inventory.GetStackedCount(plant2), 2);
        }