Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I need help fixing the spacing. Changing line 157 to a print instead of println. Three experts have tried to explain the difference between print
I need help fixing the spacing. Changing line 157 to a print instead of println. Three "experts" have tried to explain the difference between print and println, thats not what I need.
This project has you writing a text adventure game. In this game you will be presenting a maze to a player via text descriptions and allows them to navigate the maze. An example transcript is below: Enter a map file name: map99.txt You are in location row: 0 col: There are exits to the: ES Which way do you want to move? e You are in location row: 0 col:1 There are exits to the: ESW Which way do you want to move? s You are in location row: 1 col:1 There are exits to the: NESW You feel a breeze. Which way do you want to move? e AAAARGH! You have fallen into a pit! You have died! Game over! Each maze is stored in a map with a specific format, which is loaded by a prompt to the user. The file map99. txt used above has the following contents: The first line is the size of the map - in this case a 44 maze. Each line shows a comma-separated list of "rooms" that the player can move through. A player can go in any direction from a room so long as they aren't walking off the edge of the map. - A 0 in the file indicates a room with nothing in it. - A1 in the file indicates where the ravenous Bugbladder Beast lurks - if the player enters its square they lose as the Beast devours them. - A2 in the file indicates a pit - if the player enters a pit square they fall in and die. - A 3 in the file indicates a treasure - if the player enters the square with the treasure they win the game. YOU WILL WANT TO LOAD THIS INTO A 2-D ARRAY. See chapter 5.9 in the zybooks text for some details and sample problems on using a 2-D array. The game works by first prompting the user for a map to load. If the program cannot find the map file, it should exit gracefully with an error message instead of crashing: Enter a map file name: map90.txt ERROR - Cannot load file map90.txt Once the map is loaded the game tells the player their location - designated by the row and column they are in. Rows start at 0 and count down, columns start at 0 and count from left to right. The game starts with the player at row 0 , column 0 : Enter a map file name: map99.txt You are in location row: 0 col: 0 There are exits to the: ES Which way do you want to move? Note that it lists the available exits - North is "up" on the map given above. If a player would walk off the map that exit is not listed (so at row 0,col0 there are You are in location row: 3 col: 3 There are exits to the: NESW Which way do you want to move? If a player tries to move in a direction they are not allowed to move they should be told that they are not allowed to go that way: You are in location row: 0 col: 0 There are exits to the: ES Which way do you want to move? n You can't go that way. Which way do you want to move? w You can't go that way. Which way do you want to move? e You are in location row: 0 col:1 There are exits to the: ESW Which way do you want to move? Just randomly falling into pits or stepping into the jaws of a ravenous beast would not make for a fun game, so the game provides hints for the player when they are in a room next to the monster or a pit. For example in the map above there is a pit in row 1 . column 2 . If the player is in any of the rooms to the north, east, south or west of this room they will sense a breeze in that room: You are in location row: 1 col: 1 There are exits to the: NESW You feel a breeze. Which way do you want to move? Similarly, if they are in a room that leads into the room with the Ravenous Bugblatter Beast (marked with a 1 on the man) theiv will heac it making noises: Similarly, if they are in a room that leads into the room with the Ravenous Bugblatter Beast (marked with a 1 on the map) they will hear it making noises: You are in location row: 3 col: 3 There are exits to the: NW You hear a growling noise. Which way do you want to move? End Of Game There are three ways the game can end. If the player moves into a room with the gold in it (marked with a 3 on the map), they win the game: You are in location row: 2 col:0 There are exits to the: NES You feel a breeze. Which way do you want to move? s You have found the gold! You have won! Congratulations! If they player moves into a room with a pit in it (marked with a 2 on the map), they fall into the pit and lose: You are in location row: 1 col: 1 There are exits to the: NESW You feel a breeze. Which way do you want to move? e AAAARGH! You have fallen into a pit! You have died! Finally if the player moves into a room with the Ravenous Bugblatter Beast in it, it devours them and they also lose: You are in location row: 3 col:3 There are exits to the: NW You hear a growling noise. Which way do you want to move? w Oh no! You have run into a ravenous Bugblatter Beast! You have died! Game over! There are three maps total provided here for you to use when debugging. The contents of the other two map files are: map33.txt 60,0,0,0,0,00,0,2,0,0,03,0,0,0,0,10,0,0,2,0,00,2,0,0,0,00,0,0,0,0,2 map66.txt 50,0,0,0,00,2,0,0,00,3,0,0,00,0,0,2,00,0,2,0,1 NOTE: We have provided an empty class named Maze. java if you would like to create a class to model the maze. There is no requirement that you use this class - it is only here to provide an option if you There are exits to the: ES Which way do you want to move? You are in location row: 1 col:0 There are exits to the: NES Which way do you want to move? Your output You are in location row: 2 col:0 There are exits to the: NES You feel a breeze. Which way do you want to move? You have found the gold! You have won! Congratulations! Enter a map file name: You are in location row: 0 col:0 There are exits to the: ES Which way do you want to move? You are in location row: 1 col: 0 There are exits to the: NES Which way do you want to move? You are in location row: 2 col:0 There are exits to the: NES You feel a breeze. Which way do you want to move? You have found the gold! 1/ store the whole line in str String strasc. nextline(); I/split the string using separator, and store the values in string array named strs String strs[]=str, split(", "); /loop from j= to size-1 for (int j=;j exits new while(lvalid(exits, direction)) \{ //print the error message and again take input of direction System.out.println( "You can't go that way. "); System.out.print("Which way do you want to move? "); direction=sc. next() ) touppercase () . charAt(); \} I/if the direction entered by user is N if ( direction = ' N) \{ 1/ than decrement the currentRow by 1 currentRow=currentRow 1; \}/lelse if direction entered is 5 else if(direction=-' S ') f //increment the currentRow by 1 currentRow currentRow+1; \}/lelse if direction entered is W else if(direction=w ' W ') \} 1/ decrement the currentcol by 1 currentcol=currentCol-1; \}/lelse if direction entered is E else if (direction=" ' E) //increment the currentcol by 1 currentCol=currentCol+1; \} //update the current block (flag) flag=maze [currentRow] [currentcol]; Whand of whilo Iann (fame has andad) if (flag==1) //print the following mmessages System.out.println("Oh nol You have run into a ravenous Bugblatter Beast!"); System.out. println(" You have died! Game over!"); Y/lelse if current block is 2 (fallen into pit) else if (flag=2) \{ I/print the following mmessages System, out.println( "AAAARGH! You have fallen into a pit!"); System.out.println("'nYou have died! Game over!"); \} else/lelse (found the room with gold) \{ //print the following messages System, out. println ("You have found the gold1"); system, out. println(" You have won! Congratulations!"); \} \}//end of try block //to catch FileNotFoundexception catch(FileNotFoundException e) \{ //if FileNotfoundexception occurs print the following message System,out, println("ERROR - Cannot load file "+fileName); System.exit ( ); \} 3 //function to check if given direction (char) exists in the given Arraylist of chars static boolean valid(AnravList Chacacter exits, char direction) System.out.println(" You have won! Congratulations!"); 3 \}/lend of try block //to catch FileNotFoundException catch(FileNotFoundException e) \{ //if FileNotFoundException occurs print the following message System,out.println("ERROR - Cannot load file "+fileName); System,exit(0); \} \} //function to check if given direction (char) exists in the given Arraylist of chars static boolean valid(Arraylist exits, char direction) \{ I/loop to iterate Arraylist elements for(int i=; i;i++) \{ //if direction is available in the Arraylist if ( exits .get (i)== direction ) \{ //than return true return true; \} 3 l/if direction not found in Arraylist than return false return false Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started