Example #1
0
        /// <summary>
        /// Creates a temporary world.
        /// </summary>
        private void CreateTemporaryWorld()
        {
            var world = new DefaultWorld();

            world.Initialize();

            this.Worlds.Add(world);

            // TODO: Create DefaultRealm, DefaultZone and DefaultRoom.
        }
        /// <summary>
        /// Constructs the world.
        /// </summary>
        /// <param name="game">The game.</param>
        private async Task ConstructWorld(IGame game)
        {
            // Set up the Room
            var bedroom = new DefaultRoom {
                IsEnabled = true
            };
            var hallway = new DefaultRoom {
                IsEnabled = true
            };

            // Set up the Zone
            var weatherStates = new List <IWeatherState> {
                new ClearWeather(), new RainyWeather(), new ThunderstormWeather()
            };
            DefaultZone zone = new DefaultZone();

            zone.Name  = "Country Side";
            zone.Rooms = new List <DefaultRoom>()
            {
                bedroom
            };
            zone.WeatherStates          = weatherStates;
            zone.WeatherUpdateFrequency = 6;
            zone.WeatherChanged        += (sender, weatherArgs) => Console.WriteLine($"{zone.Name} zone weather has changed to {weatherArgs.CurrentState.Name}");
            DefaultZone zone2 = new DefaultZone();

            zone2.Name  = "Castle Rock";
            zone2.Rooms = new List <DefaultRoom> {
                hallway
            };
            zone2.WeatherStates          = weatherStates;
            zone2.WeatherUpdateFrequency = 2;
            zone2.WeatherChanged        += (sender, weatherArgs) => Console.WriteLine($"{zone2.Name} zone weather has changed to {weatherArgs.CurrentState.Name}");

            // Set up the World.
            IWorld world = new DefaultWorld();

            world.GameDayToRealHourRatio = 0.4;
            world.HoursPerDay            = 10;
            world.Name = "Sample World";
            world.SetNotificationManager(game.NotificationCenter);

            var morningState = new TimeOfDayState {
                Name = "Morning", StateStartTime = new TimeOfDay {
                    Hour = 2
                }
            };
            var afternoonState = new TimeOfDayState {
                Name = "Afternoon", StateStartTime = new TimeOfDay {
                    Hour = 5
                }
            };
            var nightState = new TimeOfDayState {
                Name = "Night", StateStartTime = new TimeOfDay {
                    Hour = 8
                }
            };

            world.AddTimeOfDayState(morningState);
            world.AddTimeOfDayState(afternoonState);
            world.AddTimeOfDayState(nightState);
            world.TimeOfDayChanged += World_TimeOfDayChanged;

            // Set up the Realm.
            DefaultRealm realm = new DefaultRealm(world, new TimeOfDay {
                Hour = 3, HoursPerDay = 10
            });

            realm.TimeZoneOffset = new TimeOfDay {
                Hour = 3, Minute = 10, HoursPerDay = world.HoursPerDay
            };
            realm.Name = "Realm 1";
            realm.SetNotificationManager(game.NotificationCenter);

            // Initialize the environment.
            Task task = world.Initialize();

            task.Wait();

            await world.AddRealmToWorld(realm);

            realm.AddZoneToRealm(zone);
            realm.AddZoneToRealm(zone2);
            await game.AddWorld(world);
        }