public async Task <IEnumerable <TimeOfDayState> > GetTimeOfDayStates() { IEnumerable <string> stateFiles = this.storageService.GetAllFilesByExtension(".tods", "TimeOfDayStates"); var states = new List <TimeOfDayState>(); foreach (string file in stateFiles) { var state = new TimeOfDayState(); state.Name = await this.storageService.LoadValueFromKeyAsync(file, state.GetPropertyName(p => p.Name)); state.StateStartTime.Hour = Convert.ToInt32(await this.storageService.LoadValueFromKeyAsync( file, state.StateStartTime.GetPropertyName(p => p.Hour))); state.StateStartTime.Minute = Convert.ToInt32(await this.storageService.LoadValueFromKeyAsync( file, state.StateStartTime.GetPropertyName(p => p.Minute))); state.StateStartTime.HoursPerDay = Convert.ToInt32(await this.storageService.LoadValueFromKeyAsync( file, state.StateStartTime.GetPropertyName(p => p.HoursPerDay))); states.Add(state); } return(states); }
/// <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); }