public void Test_Act_ContinueFelling()
        {
            Console.WriteLine ("");
            Console.WriteLine ("Preparing test");
            Console.WriteLine ("");

            var context = MockEngineContext.New ();

            var settings = EngineSettings.DefaultVerbose;
            settings.FellingRate = 10;

            var person = new PersonCreator (settings).CreateAdult ();

            var tile = context.World.Tiles[0];
            tile.AddPerson (person);
            tile.AddTrees (new PlantCreator (context.Settings).CreateTrees (2));

            var needEntry = new NeedEntry (ActivityVerb.Fell, ItemType.Wood, PersonVitalType.NotSet, 50, 101);

            var activity = new FellWoodActivity (person, needEntry, settings, new ConsoleHelper(settings));
            activity.Target = tile.Trees [0];

            Console.WriteLine ("");
            Console.WriteLine ("Executing target");
            Console.WriteLine ("");

            activity.Act (person);

            Assert.AreEqual(10, activity.Target.PercentHarvested);
        }
        public GameEnvironmentPopulator(GameEnvironment world)
        {
            World = world;

            // TODO: Should all these creators be consistent with their constructor parameters?
            TileCreator = new TileCreator (world);
            PersonCreator = new PersonCreator (world.Context.Settings);
            PlantCreator = new PlantCreator (world.Context.Settings);
        }
예제 #3
0
        public GameEnvironment(EngineContext context)
        {
            Context = context;

            Populator = new GameEnvironmentPopulator (this);
            PersonCreator = new PersonCreator (context.Settings);
            PlantCreator = new PlantCreator (context.Settings);
            Tiles = new GameTile[]{};
            People = new Person[] {};
            Plants = new Plant[]{ };
            Logic = new GameLogic ();
            Tiles = new GameTile[]{new GameTile(this)};
        }
        public void Test_GetThirstyCollectWaterAndDrink()
        {
            Console.WriteLine ("");
            Console.WriteLine ("Preparing test");
            Console.WriteLine ("");

            var context = MockEngineContext.New ();
            context.Data.IsVerbose = true;

            context.Settings.DefaultCollectWaterRate = 50; // Increase the rate of water collection so the test goes faster
            context.Settings.DefaultDrinkAmount = 20; // Increase the amount the person drinks so the test goes faster
            context.Settings.WaterForThirstRatio = 10;

            // Disabled otherwise the thirst vital will never remain at zero
            //context.World.Logic.AddEffect (new ThirstEffect(context.Settings, context.Console));

            context.World.Logic.AddNeed (new DrinkWaterNeedIdentifier (context.Settings, context.Console));

            context.World.Logic.AddActivity (typeof(CollectWaterActivity));
            context.World.Logic.AddActivity (typeof(DrinkWaterActivity));

            var tile = context.World.Tiles [0];

            tile.Inventory[ItemType.Water] = 200;

            var person = new PersonCreator (context.Settings).CreateAdult(); // TODO: Store the PersonCreator object somewhere else

            person.Vitals[PersonVitalType.Thirst] = 90;

            tile.AddPerson (person);

            context.Player = person;

            Console.WriteLine ("");
            Console.WriteLine ("Executing test");
            Console.WriteLine ("");

            context.Initialize (); // TODO: Should Start be part of the test? Or part of the preparation before the above console output?

            context.Run (10);

            Console.WriteLine ("");
            Console.WriteLine ("Analysing test");
            Console.WriteLine ("");

            Assert.AreEqual (0, person.Vitals[PersonVitalType.Thirst]);
        }
        public void Test_GetHungryCollectFoodAndEat()
        {
            Console.WriteLine ("");
            Console.WriteLine ("Preparing test");
            Console.WriteLine ("");

            var context = MockEngineContext.New ();

            context.Settings.DefaultGatherFoodRate = 50; // Increase the rate of food gathering so the test goes faster
            context.Settings.DefaultEatAmount = 100; // Increase the amount the person eats so the test goes faster

            context.World.Logic.AddNeed (new EatFoodNeedIdentifier (context.Settings, context.Console));
            context.World.Logic.AddActivity (typeof(GatherFoodActivity));
            context.World.Logic.AddActivity (typeof(EatFoodActivity));

            var tile = context.World.Tiles [0];

            tile.Inventory[ItemType.Food] = 200;

            var person = new PersonCreator (context.Settings).CreateAdult(); // TODO: Store the PersonCreator object somewhere else

            person.Vitals[PersonVitalType.Hunger] = 90;

            tile.AddPerson (person);

            context.Player = person;

            Console.WriteLine ("");
            Console.WriteLine ("Executing test");
            Console.WriteLine ("");

            context.Initialize (); // TODO: Should Start be part of the test? Or part of the preparation before the above console output?

            context.Run (5);

            Console.WriteLine ("");
            Console.WriteLine ("Analysing test");
            Console.WriteLine ("");

            Assert.AreEqual (40, person.Vitals[PersonVitalType.Hunger]);
        }
        public void Test_Act_FinishedFelling()
        {
            Console.WriteLine ("");
            Console.WriteLine("Preparing test");
            Console.WriteLine("");

            var context = MockEngineContext.New ();

            var settings = EngineSettings.DefaultVerbose;
            settings.FellingRate = 10;

            var person = new PersonCreator (settings).CreateAdult ();

            var tile = context.World.Tiles[0];
            tile.AddPerson (person);
            tile.AddTrees (new PlantCreator (context.Settings).CreateTrees (2));

            var needEntry = new NeedEntry (ActivityVerb.Fell, ItemType.Wood, PersonVitalType.NotSet, 50, 101);

            person.AddNeed (needEntry);

            var activity = new FellWoodActivity (person, needEntry, settings, new ConsoleHelper(settings));
            activity.Target = tile.Trees [0];
            activity.Target.PercentHarvested = 100;
            activity.TotalWoodFelled = 40; // Add just enough so the activity can finish

            var totalWoodExpected = activity.Target.Size;

            Console.WriteLine ("");
            Console.WriteLine ("Executing test");
            Console.WriteLine ("");

            activity.Act (person);

            Assert.IsTrue (activity.IsFinished);
            Assert.IsNull(activity.Target);
            Assert.AreEqual (totalWoodExpected, person.Inventory.Items [ItemType.Wood]);

            Assert.AreEqual (0, person.Needs.Count);
        }