Advertisement
Guest User

Untitled

a guest
Oct 25th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.09 KB | None | 0 0
  1. public sealed class Version01_MutableLocation
  2. {
  3. public string Name { get; set; }
  4. public string Description { get; set; }
  5. public Version01_MutableLocation North { get; set; }
  6. public Version01_MutableLocation South { get; set; }
  7. public Version01_MutableLocation East { get; set; }
  8. public Version01_MutableLocation West { get; set; }
  9.  
  10. /// <summary>
  11. /// This instance method is a pure function, but it's dependency - the class instance - is referenced via the 'this' operator
  12. /// </summary>
  13. public string Narrate()
  14. {
  15. string narration = string.Empty;
  16.  
  17. { // This block constructs the string that is the description
  18. // of the location that is displayed onscreen to the game player.
  19. string northExit =
  20. null != this.North ? " North" : string.Empty;
  21.  
  22. string southExit =
  23. null != this.South ? " South" : string.Empty;
  24.  
  25. string eastExit =
  26. null != this.East ? " East" : string.Empty;
  27.  
  28. string westExit =
  29. null != this.West ? " West" : string.Empty;
  30.  
  31. string allExits =
  32. string.Empty != string.Concat(northExit, southExit, eastExit, westExit)
  33. ? $"{Environment.NewLine}Exits:{northExit}{southExit}{eastExit}{westExit}"
  34. : string.Empty;
  35.  
  36. string separator = new string('-', this.Name.Length);
  37.  
  38. narration =
  39. $"{this.Name}{Environment.NewLine}" +
  40. $"{separator}{Environment.NewLine}" +
  41. $"{this.Description}{Environment.NewLine}" +
  42. $"{separator}" +
  43. $"{allExits}";
  44. }
  45.  
  46. return narration;
  47. }
  48.  
  49. public static void Main(string[] args)
  50. {
  51. var kitchen = new Version01_MutableLocation();
  52. kitchen.Name = "Kitchen";
  53. kitchen.Description = "You are in a messy kitchen.";
  54.  
  55. var library = new Version01_MutableLocation();
  56. kitchen.Name = "Library";
  57. kitchen.Description = "You are in the library.";
  58.  
  59. var office = new Version01_MutableLocation();
  60. office.Name = "Office";
  61. office.Description = "You are in the office. There's a computer on the desk.";
  62.  
  63. kitchen.North = library;
  64. library.South = kitchen;
  65. library.North = office;
  66. office.South = library;
  67.  
  68. Console.WriteLine($"{kitchen.Narrate()}");
  69. Console.WriteLine($"{library.Narrate()}");
  70. Console.WriteLine($"{office.Narrate()}");
  71. }
  72. }
  73.  
  74. public sealed class Version02_MutableLocation
  75. {
  76. public string Name { get; set; }
  77. public string Description { get; set; }
  78. public Version02_MutableLocation North { get; set; }
  79. public Version02_MutableLocation South { get; set; }
  80. public Version02_MutableLocation East { get; set; }
  81. public Version02_MutableLocation West { get; set; }
  82.  
  83. /// <summary>
  84. /// This static method is a pure function, and all of its dependencies are passed in the function's argument list.
  85. /// </summary>
  86. public static string Narrate(Version02_MutableLocation location)
  87. {
  88. string narration = string.Empty;
  89.  
  90. { // This block constructs the string that is the description
  91. // of the location that is displayed onscreen to the game player.
  92. string northExit =
  93. null != location.North ? " North" : string.Empty;
  94.  
  95. string southExit =
  96. null != location.South ? " South" : string.Empty;
  97.  
  98. string eastExit =
  99. null != location.East ? " East" : string.Empty;
  100.  
  101. string westExit =
  102. null != location.West ? " West" : string.Empty;
  103.  
  104. string allExits =
  105. string.Empty != string.Concat(northExit, southExit, eastExit, westExit)
  106. ? $"{Environment.NewLine}Exits:{northExit}{southExit}{eastExit}{westExit}"
  107. : string.Empty;
  108.  
  109. string separator = new string('-', location.Name.Length);
  110.  
  111. narration =
  112. $"{location.Name}{Environment.NewLine}" +
  113. $"{separator}{Environment.NewLine}" +
  114. $"{location.Description}{Environment.NewLine}" +
  115. $"{separator}" +
  116. $"{allExits}";
  117. }
  118.  
  119. return narration;
  120. }
  121.  
  122. public static void Main(string[] args)
  123. {
  124. var kitchen = new Version02_MutableLocation();
  125. kitchen.Name = "Kitchen";
  126. kitchen.Description = "You are in a messy kitchen.";
  127.  
  128. var library = new Version02_MutableLocation();
  129. kitchen.Name = "Library";
  130. kitchen.Description = "You are in the library.";
  131.  
  132. var office = new Version02_MutableLocation();
  133. office.Name = "Office";
  134. office.Description = "You are in the office. There's a computer on the desk.";
  135.  
  136. kitchen.North = library;
  137. library.South = kitchen;
  138. library.North = office;
  139. office.South = library;
  140.  
  141. Console.WriteLine($"{Version02_MutableLocation.Narrate(kitchen)}");
  142. Console.WriteLine($"{Version02_MutableLocation.Narrate(library)}");
  143. Console.WriteLine($"{Version02_MutableLocation.Narrate(office)}");
  144. }
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement