/// <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);
        }
Beispiel #2
0
        /// <summary>
        /// Adds the given zone to this instance.
        /// </summary>
        /// <param name="zone">The zone.</param>
        /// <exception cref="System.NullReferenceException">Attempted to add a null Zone to the Realm.
        /// or
        /// Adding a Zone to a Realm with a null Rooms collection is not allowed.</exception>
        public void AddZoneToRealm(DefaultZone zone)
        {
            if (zone == null)
            {
                throw new NullReferenceException("Attempted to add a null Zone to the Realm.");
            }

            if (zone.Rooms == null)
            {
                throw new NullReferenceException("Adding a Zone to a Realm with a null Rooms collection is not allowed.");
            }

            zone.Initialize(this);
            this.zones.Add(zone);
        }
Beispiel #3
0
        /// <summary>
        /// Adds the given zone to this instance.
        /// </summary>
        /// <param name="zone">The zone.</param>
        /// <exception cref="System.NullReferenceException">Attempted to add a null Zone to the Realm.
        /// or
        /// Adding a Zone to a Realm with a null Rooms collection is not allowed.</exception>
        public void AddZoneToRealm(DefaultZone zone)
        {
            if (zone == null)
            {
                throw new NullReferenceException("Attempted to add a null Zone to the Realm.");
            }

            if (zone.Rooms == null)
            {
                throw new NullReferenceException("Adding a Zone to a Realm with a null Rooms collection is not allowed.");
            }

            zone.Initialize(this);
            this.zones.Add(zone);
        }
Beispiel #4
0
 /// <summary>
 /// Initializes the room with the given zone.
 /// </summary>
 /// <param name="zone">The zone that represents the owner of this room.</param>
 public virtual void Initialize(DefaultZone zone)
 {
     this.Zone = zone;
 }
Beispiel #5
0
 /// <summary>
 /// Initializes the room with the given zone.
 /// </summary>
 /// <param name="zone">The zone that represents the owner of this room.</param>
 public virtual void Initialize(DefaultZone zone)
 {
     this.Zone = zone;
 }