Exemplo n.º 1
0
        public void BasicWorld()
        {
            Resource res;

            PlarfGame.Instance.Initialize(new Size(50, 50));

            // resources
            res = PlarfGame.Instance.World.AddPlaceable(PlarfGame.Instance.ResourceTemplates["Stones"], new Location(0, 0)) as Resource;
            PlarfGame.Instance.World.MarkResourceForHarvest(res);

            ExtraAssert.Throws <LocationAlreadyInUseException>(() => PlarfGame.Instance.World.AddPlaceable(
                                                                   PlarfGame.Instance.ResourceTemplates["Stones"], new Location(0, 1)));

            res = PlarfGame.Instance.World.AddPlaceable(PlarfGame.Instance.ResourceTemplates["Tree"], new Location(0, 2)) as Resource;
            PlarfGame.Instance.World.MarkResourceForHarvest(res);
            res = PlarfGame.Instance.World.AddPlaceable(PlarfGame.Instance.ResourceTemplates["Tree"], new Location(1, 2)) as Resource;
            PlarfGame.Instance.World.MarkResourceForHarvest(res);

            res = PlarfGame.Instance.World.AddPlaceable(PlarfGame.Instance.ResourceTemplates["Stones"], new Location(0, 3)) as Resource;
            PlarfGame.Instance.World.MarkResourceForHarvest(res);

            ExtraAssert.Throws <LocationAlreadyInUseException>(() => PlarfGame.Instance.World.AddPlaceable(
                                                                   PlarfGame.Instance.ResourceTemplates["Stones"], new Location(0, 4)));

            // storage
            PlarfGame.Instance.World.AddPlaceable(PlarfGame.Instance.BuildingClasses["Storage"], new Location(5, 0), new Size(3, 5));

            // some basic bounds tests
            for (int x = 0; x <= 1; ++x)
            {
                for (int y = 0; y <= 1; ++y)
                {
                    Assert.IsTrue(PlarfGame.Instance.World.GetPlaceables(x, y).Cast <Resource>().Single().Name == "Stones");
                }
            }
            Assert.IsTrue(PlarfGame.Instance.World.GetPlaceables(0, 2).Cast <Resource>().Single().Name == "Tree");

            // actors
            var h = PlarfGame.Instance.World.AddActor(PlarfGame.Instance.HumanTemplate, "H", new Location(2, 2)) as Human;

            //Game.Instance.World.AddActor(Game.Instance.HumanTemplate, new Location(0, 2));

            // simulation loop
            for (int cnt = 0; cnt < 50000; ++cnt)
            {
                PlarfGame.Instance.Run(TimeSpan.FromMilliseconds(1000.0 / 30));
            }
        }