Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public sealed class Version01_MutableLocation
- {
- public string Name { get; set; }
- public string Description { get; set; }
- public Version01_MutableLocation North { get; set; }
- public Version01_MutableLocation South { get; set; }
- public Version01_MutableLocation East { get; set; }
- public Version01_MutableLocation West { get; set; }
- /// <summary>
- /// This instance method is a pure function, but it's dependency - the class instance - is referenced via the 'this' operator
- /// </summary>
- public string Narrate()
- {
- string narration = string.Empty;
- { // This block constructs the string that is the description
- // of the location that is displayed onscreen to the game player.
- string northExit =
- null != this.North ? " North" : string.Empty;
- string southExit =
- null != this.South ? " South" : string.Empty;
- string eastExit =
- null != this.East ? " East" : string.Empty;
- string westExit =
- null != this.West ? " West" : string.Empty;
- string allExits =
- string.Empty != string.Concat(northExit, southExit, eastExit, westExit)
- ? $"{Environment.NewLine}Exits:{northExit}{southExit}{eastExit}{westExit}"
- : string.Empty;
- string separator = new string('-', this.Name.Length);
- narration =
- $"{this.Name}{Environment.NewLine}" +
- $"{separator}{Environment.NewLine}" +
- $"{this.Description}{Environment.NewLine}" +
- $"{separator}" +
- $"{allExits}";
- }
- return narration;
- }
- public static void Main(string[] args)
- {
- var kitchen = new Version01_MutableLocation();
- kitchen.Name = "Kitchen";
- kitchen.Description = "You are in a messy kitchen.";
- var library = new Version01_MutableLocation();
- kitchen.Name = "Library";
- kitchen.Description = "You are in the library.";
- var office = new Version01_MutableLocation();
- office.Name = "Office";
- office.Description = "You are in the office. There's a computer on the desk.";
- kitchen.North = library;
- library.South = kitchen;
- library.North = office;
- office.South = library;
- Console.WriteLine($"{kitchen.Narrate()}");
- Console.WriteLine($"{library.Narrate()}");
- Console.WriteLine($"{office.Narrate()}");
- }
- }
- public sealed class Version02_MutableLocation
- {
- public string Name { get; set; }
- public string Description { get; set; }
- public Version02_MutableLocation North { get; set; }
- public Version02_MutableLocation South { get; set; }
- public Version02_MutableLocation East { get; set; }
- public Version02_MutableLocation West { get; set; }
- /// <summary>
- /// This static method is a pure function, and all of its dependencies are passed in the function's argument list.
- /// </summary>
- public static string Narrate(Version02_MutableLocation location)
- {
- string narration = string.Empty;
- { // This block constructs the string that is the description
- // of the location that is displayed onscreen to the game player.
- string northExit =
- null != location.North ? " North" : string.Empty;
- string southExit =
- null != location.South ? " South" : string.Empty;
- string eastExit =
- null != location.East ? " East" : string.Empty;
- string westExit =
- null != location.West ? " West" : string.Empty;
- string allExits =
- string.Empty != string.Concat(northExit, southExit, eastExit, westExit)
- ? $"{Environment.NewLine}Exits:{northExit}{southExit}{eastExit}{westExit}"
- : string.Empty;
- string separator = new string('-', location.Name.Length);
- narration =
- $"{location.Name}{Environment.NewLine}" +
- $"{separator}{Environment.NewLine}" +
- $"{location.Description}{Environment.NewLine}" +
- $"{separator}" +
- $"{allExits}";
- }
- return narration;
- }
- public static void Main(string[] args)
- {
- var kitchen = new Version02_MutableLocation();
- kitchen.Name = "Kitchen";
- kitchen.Description = "You are in a messy kitchen.";
- var library = new Version02_MutableLocation();
- kitchen.Name = "Library";
- kitchen.Description = "You are in the library.";
- var office = new Version02_MutableLocation();
- office.Name = "Office";
- office.Description = "You are in the office. There's a computer on the desk.";
- kitchen.North = library;
- library.South = kitchen;
- library.North = office;
- office.South = library;
- Console.WriteLine($"{Version02_MutableLocation.Narrate(kitchen)}");
- Console.WriteLine($"{Version02_MutableLocation.Narrate(library)}");
- Console.WriteLine($"{Version02_MutableLocation.Narrate(office)}");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement