Advertisement
Guest User

ok

a guest
Apr 23rd, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.69 KB | None | 0 0
  1. import java.io.IOException;
  2. import java.io.File;
  3. import java.io.FileNotFoundException;
  4. import java.util.Scanner;
  5. import java.io.PrintWriter;
  6.  
  7. /**
  8. * Maze Game
  9. *
  10. * INFO1103 Assignment 2
  11. * 2017 Semester 1
  12. *
  13. * The Maze Game.
  14. * In this assignment you will be designing a maze game.
  15. * You will have a maze board and a player moving around the board.
  16. * The player can step left, right, up or down.
  17. * However, you need to complete the maze within a given number of steps.
  18. *
  19. * As in any maze, there are walls that you cannot move through. If you try to
  20. * move through a wall, you lose a life. You have a limited number of lives.
  21. * There is also gold on the board that you can collect if you move ontop of it.
  22. *
  23. * Please implement the methods provided, as some of the marks are allocated to
  24. * testing these methods directly.
  25. *
  26. * @author YOU
  27. * @date April, 2017
  28. *
  29. */
  30. public class MazeGame
  31. {
  32. /* You can put variables that you need throughout the class up here.
  33. * You MUST INITIALISE ALL of these class variables in your initialiseGame
  34. * method.
  35. */
  36.  
  37. // A sample variable to show you can put variables here.
  38. // You would initialise it in initialiseGame method.
  39. // e.g. Have the following line in the initialiseGame method.
  40. // sampleVariable = 1;
  41.  
  42. static String[] board;
  43. static int numberOfLives;
  44. static int numberOfSteps;
  45. static int numberOfGold;
  46. static int numberOfRows;
  47. static int playerRow;
  48. static int playerColumn;
  49. static int rowCount;
  50. static int xCoordinate;
  51. static int yCoordinate;
  52.  
  53. /**
  54. * Initialises the game from the given configuration file.
  55. * This includes the number of lives, the number of steps, the starting gold
  56. * and the board.
  57. *
  58. * If the configuration file name is "DEFAULT", load the default
  59. * game configuration.
  60. *
  61. * NOTE: Please also initialise all of your class variables.
  62. *
  63. * @args configFileName The name of the game configuration file to read from.
  64. * @throws IOException If there was an error reading in the game.
  65. * For example, if the input file could not be found.
  66. */
  67.  
  68. public static void initialiseGame(String configFileName) throws IOException
  69. {
  70.  
  71. }
  72.  
  73. /**
  74. * Save the current board to the given file name.
  75. * Note: save it in the same format as you read it in.
  76. * That is:
  77. *
  78. * <number of lives> <number of steps> <amount of gold> <number of rows on the board>
  79. * <BOARD>
  80. *
  81. * @args toFileName The name of the file to save the game configuration to.
  82. * @throws IOException If there was an error writing the game to the file.
  83. */
  84. public static void saveGame(String toFileName) throws IOException
  85. {
  86.  
  87. /* Scanner keyboard = new Scanner(System.in);
  88. String save = keyboard.next();
  89. toFileName = keyboard.next();
  90.  
  91. if (save.equalsIgnoreCase("save"))
  92. {
  93. try (PrintWriter out = new PrintWriter(toFileName))
  94. {
  95. out.println(mazeArray);
  96. }
  97. catch (FileNotFoundException e){
  98. System.out.println("Error, file not found.");
  99. }
  100. } */
  101.  
  102. }
  103.  
  104. /**
  105. * Gets the current x position of the player.
  106. *
  107. * @return The players current x position.
  108. */
  109. public static int getCurrentXPosition() {
  110.  
  111. return 0;
  112. }
  113.  
  114. /**
  115. * Gets the current y position of the player.
  116. *
  117. * @return The players current y position.
  118. */
  119. public static int getCurrentYPosition() {
  120. // TODO: Implement this method.
  121. return 0;
  122. }
  123.  
  124. /**
  125. * Gets the number of lives the player currently has.
  126. *
  127. * @return The number of lives the player currently has.
  128. */
  129. public static int numberOfLives() {
  130. // TODO: Implement this method.
  131. return 0;
  132. }
  133.  
  134. /**
  135. * Gets the number of remaining steps that the player can use.
  136. *
  137. * @return The number of steps remaining in the game.
  138. */
  139. public static int numberOfStepsRemaining() {
  140.  
  141. return 0;
  142. }
  143.  
  144. /**
  145. * Gets the amount of gold that the player has collected so far.
  146. *
  147. * @return The amount of gold the player has collected so far.
  148. */
  149. public static int amountOfGold() {
  150. // TODO: Implement this method.
  151. return 0;
  152. }
  153.  
  154.  
  155. /**
  156. * Checks to see if the player has completed the maze.
  157. * The player has completed the maze if they have reached the destination.
  158. *
  159. * @return True if the player has completed the maze.
  160. */
  161. public static boolean isMazeCompleted() {
  162. // TODO: Implement this method.
  163. return false;
  164. }
  165.  
  166. /**
  167. * Checks to see if it is the end of the game.
  168. * It is the end of the game if one of the following conditions is true:
  169. * - There are no remaining steps.
  170. * - The player has no lives.
  171. * - The player has completed the maze.
  172. *
  173. * @return True if any one of the conditions that end the game is true.
  174. */
  175. public static boolean isGameEnd() {
  176. // TODO: Implement this method.
  177. return false;
  178. }
  179.  
  180. /**
  181. * Checks if the coordinates (x, y) are valid.
  182. * That is, if they are on the board.
  183. *
  184. * @args x The x coordinate.
  185. * @args y The y coordinate.
  186. * @return True if the given coordinates are valid (on the board),
  187. * otherwise, false (the coordinates are out or range).
  188. */
  189. public static boolean isValidCoordinates(int x, int y) {
  190. // TODO: Implement this method.
  191. return false;
  192. }
  193.  
  194. /**
  195. * Checks if a move to the given coordinates is valid.
  196. * A move is invalid if:
  197. * - It is move to a coordinate off the board.
  198. * - There is a wall at that coordinate.
  199. * - The game is ended.
  200. *
  201. * @args x The x coordinate to move to.
  202. * @args y The y coordinate to move to.
  203. * @return True if the move is valid, otherwise false.
  204. */
  205. public static boolean canMoveTo(int x, int y) {
  206. // TODO: Implement this method.
  207. return false;
  208. }
  209.  
  210. /**
  211. * Move the player to the given coordinates on the board.
  212. * After a successful move, it prints "Moved to (x, y)."
  213. * where (x, y) were the coordinates given.
  214. *
  215. * If there was gold at the position the player moved to,
  216. * the gold should be collected and the message "Plus n gold."
  217. * should also be printed, where n is the amount of gold collected.
  218. *
  219. * If it is an invalid move, a life is lost.
  220. * The method prints: "Invalid move. One life lost."
  221. *
  222. * @args x The x coordinate to move to.
  223. * @args y The y coordinate to move to.
  224. */
  225. public static void moveTo(int x, int y) {
  226. // TODO: Implement this method.
  227. }
  228.  
  229. /**
  230. * Prints out the help message.
  231. */
  232. public static void printHelp() {
  233. // TODO: Implement this method.
  234. }
  235.  
  236. /**
  237. * Prints out the status message.
  238. */
  239. public static void printStatus() {
  240. // TODO: Implement this method.
  241. }
  242.  
  243. /**
  244. * Prints out the board.
  245. */
  246. public static void printBoard() {
  247. // TODO: Implement this method.
  248. }
  249.  
  250. /**
  251. * Performs the given action by calling the appropriate helper methods.
  252. * [For example, calling the printHelp() method if the action is "help".]
  253. *
  254. * The valid actions are "help", "board", "status", "left", "right",
  255. * "up", "down", and "save".
  256. * [Note: The actions are case insensitive.]
  257. * If it is not a valid action, an IllegalArgumentException should be thrown.
  258. *
  259. * @args action The action we are performing.
  260. * @throws IllegalArgumentException If the action given isn't one of the
  261. * allowed actions.
  262. */
  263. public static void performAction(String action) throws IllegalArgumentException {
  264. // TODO: Implement this method.
  265. }
  266.  
  267. /**
  268. * The main method of your program.
  269. *
  270. * @args args[0] The game configuration file from which to initialise the
  271. * maze game. If it is DEFAULT, load the default configuration.
  272. */
  273. public static void main(String[] args)
  274. {
  275. if (args.length < 1)
  276. {
  277. System.out.println("Error: Too few arguments given. Expected 1 argument, found 0.");
  278. System.out.println("Usage: MazeGame [<game configuration file>|DEFAULT]");
  279. return;
  280. }
  281. if (args.length > 1)
  282. {
  283. System.out.println("Error: Too many arguments given. Expected 1 argument, found " +args.length+ ".");
  284. System.out.println("Usage: MazeGame [<game configuration file>|DEFAULT]");
  285. return;
  286.  
  287. }
  288. if (args.length == 1)
  289. {
  290. MazeGame.initiliaseGame(args[0]);
  291.  
  292. }
  293. }
  294. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement