Advertisement
Guest User

Untitled

a guest
Aug 29th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.11 KB | None | 0 0
  1. namespace Engine
  2. {
  3. public class Game
  4. {
  5. public Player player;
  6.  
  7. public Game()
  8. {
  9.  
  10. player = new Player(10, 10, 20, 0, 1);
  11. player.inventory.Add(World.ItemByID(World.ITEM_ID_RUSTY_SWORD));
  12. MoveTo(World.LocationByID(World.LOCATION_ID_HOME));
  13.  
  14. }
  15.  
  16. private void moveNorth()
  17. {
  18. MoveTo(player.currentLocation.locToNorth);
  19. }
  20. private void moveSouth()
  21. {
  22. MoveTo(player.currentLocation.locToSouth);
  23. }
  24.  
  25. private void moveWest()
  26. {
  27. MoveTo(player.currentLocation.locToWest);
  28. }
  29.  
  30. private void moveEast()
  31. {
  32. MoveTo(player.currentLocation.locToEast);
  33. }
  34.  
  35. public void MoveTo(Location newLocation)
  36. {
  37. if (newLocation.locationKey != null)
  38. {
  39. bool playerHasRequiredItem = false;
  40.  
  41. foreach (Item item in player.inventory) //Thorws null reference unhandled
  42. {
  43. if (item.id == newLocation.locationKey.id)
  44. {
  45. playerHasRequiredItem = true;
  46. break;
  47. }
  48. }
  49. if (!playerHasRequiredItem)
  50. {
  51. Console.WriteLine("You must have {0} to enter this location", newLocation.locationKey.name);
  52. return;
  53. }
  54. }
  55. player.currentLocation = newLocation;
  56. GetDesc();
  57. GetDirections( player.currentLocation);
  58.  
  59. }
  60.  
  61. public void GetDesc()
  62. {
  63. Console.WriteLine(player.currentLocation.description);
  64. }
  65.  
  66. public void GetDirections(Location thisLocation)
  67. {
  68. thisLocation = player.currentLocation;
  69.  
  70. Console.WriteLine("Directions:");
  71. if (thisLocation.locToNorth != null)
  72. {
  73. Console.WriteLine(" N ");
  74. }
  75. if (thisLocation.locToSouth != null)
  76. {
  77. Console.WriteLine(" S ");
  78. }
  79. if (thisLocation.locToWest != null)
  80. {
  81. Console.WriteLine(" W ");
  82. }
  83. if (thisLocation.locToEast != null)
  84. {
  85. Console.WriteLine(" E ");
  86. }
  87. }
  88.  
  89.  
  90.  
  91. public Dictionary<string, Func<Location>> commands = new Dictionary<string, Func<Location>>(); //trying to pretty up my old commands code which I'll post below
  92.  
  93. public void GetCommand()
  94. {
  95. commands.Add("move", (Func<Location>)MoveTo(player.newLocation));
  96. }
  97.  
  98. /* public void Commands()
  99. {
  100. List<string> command = new List<string>();
  101. command.AddRange(Console.ReadLine().Split(' '));
  102. Console.WriteLine("\n");
  103.  
  104. if (command.Count == 0)
  105. {
  106. Console.WriteLine("Please enter a valid command");
  107. }
  108.  
  109. if (command.Count >= 1)
  110. {
  111. switch (command[0])
  112. {
  113. case "move":
  114. if (command.Count == 1)
  115. {
  116. Console.WriteLine("Command: Move (direction)");
  117. }
  118.  
  119. if (command.Count == 2)
  120. {
  121. if (command[1] == "n" && player.currentLocation.locToNorth != null)
  122. {
  123. moveNorth();
  124. command.Clear();
  125.  
  126. }
  127.  
  128. else if (command[1] == "s" && player.currentLocation.locToSouth != null)
  129. {
  130. moveSouth();
  131. command.Clear();
  132. }
  133.  
  134. else if (command[1] == "w" && player.currentLocation.locToWest != null)
  135. {
  136. moveWest();
  137. command.Clear();
  138. }
  139.  
  140. else if (command[1] == "e" && player.currentLocation.locToEast != null)
  141. {
  142. moveEast();
  143. command.Clear();
  144. }
  145. else
  146. {
  147. Console.WriteLine("Invalid direction. The valid directions are: ");
  148. GetDirections(player.currentLocation);
  149. }
  150. }
  151.  
  152. break;
  153. case "attack":
  154. if (command.Count == 1)
  155. {
  156. Console.WriteLine("Invalid target");
  157. }
  158. else
  159. {
  160. Console.WriteLine("You attack.");
  161. }
  162. break;
  163. case "quaff":
  164. if (command.Count == 1)
  165. {
  166. Console.WriteLine("Which potion?");
  167. }
  168. else
  169. {
  170. Console.WriteLine("You potion.");
  171. }
  172. break;
  173. case "quit":
  174. {
  175. Console.WriteLine("You have quit.");
  176. Environment.Exit(0);
  177. break;
  178. }
  179. case "stats":
  180. Console.WriteLine("Health {0}/{1} Gold: {2} XP: {3} level: {4}", player.currentHp, player.maxHp, player.gold, player.xp, player.level);
  181. break;
  182. case "inventory":
  183. Console.WriteLine("Player Inventory\n****************");
  184. foreach (Item item in player.inventory)
  185. {
  186. Console.WriteLine(item.name + "\n");
  187. }
  188. break;
  189. case "quests":
  190. Console.WriteLine("Player Quests\n*************");
  191. break;
  192. case "givexp":
  193. if (command.Count == 1)
  194. {
  195. Console.WriteLine("givexp PLAYER XPVALUE");
  196. }
  197. else if (command.Count == 2)
  198. {
  199. Console.WriteLine("enter a valid xp ammount");
  200. }
  201. else
  202. {
  203. player.xp = Int32.Parse(command[2]);
  204. }
  205. break;
  206. }
  207. }
  208. }
  209.  
  210. */
  211. }
  212. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement