public Dictionary <Location, IAdventureLocation> Build(AdventureGame game) { var dungeon = new Dictionary <Location, IAdventureLocation>(); try { // Must use a concrete type in instantiating dungeon locations ... var locations = GetType().Assembly.GetTypes().Where(t => typeof(AdventureLocation).IsAssignableFrom(t)); foreach (var type in locations) { if (type.Name == nameof(AdventureLocation)) { continue; } var loc = Activator.CreateInstance(type, game) as AdventureLocation; if (loc != null) { dungeon.Add(loc.LocationId, loc); } } } catch (Exception ex) { Console.WriteLine(ex.Message + ": " + ex.StackTrace); } return(dungeon); }
public Dungeon(AdventureGame game, IDungeonBuilder builder) { Locations = builder.Build(game); }
public CommandHandler(AdventureGame game) { _game = game; _commandRegistry = new AdventureCommandRegistry(game); }