|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hey,
I've got this really hard assignment to do that i just cant crack.. I have to get a destination list from a file Map 04. Then the user moves to another location via input, but that location has to be connected to the original location list (which in turn has to be connected to the specified start location. It's step six on the file below. http://www.cs.auckland.ac.nz/compsci101s1c/assignments/A3/A3.pdf I cant seem to find how to only allow valid destinations to be 'moved' to... Im really stuck any would appreciate any help. Thanks, Heaps Ash /* File::Maze.java Author: Ashley Matthews ID: 3434322 UPI: amat064 Latest Step Completed: Step Six */ import java.io.*; import java.util.StringTokenizer; public class MazeStepSix { public static void main(String[] args) throws IOException { BufferedReader stdin = new BufferedReader( new InputStreamReader(System.in)); final String BORDER = "*********** "; final String TITLE = " MAZE GAME "; String locationOne = ""; String locationTwo = ""; String input = ""; String destinations = ""; String secondDestinations = ""; String destinationsList = ""; String secondDestinationsList = ""; String tempString = ""; String newTemp = ""; String newTempTwo = ""; String currentLetter = ""; String otherLetter = ""; String currentToken = ""; String validDest = ""; String entry; int tempInt = 0; int index; int indexOfLetter = 0; int tokenValid = 0; boolean validDestination = false; Map04 map = new Map04(); entry = map.getEntry(); StringTokenizer st1 = new StringTokenizer(map.getConnections(), ","); StringTokenizer dest = new StringTokenizer(map.getConnections(), ","); System.out.println(BORDER + BORDER + BORDER); System.out.println(BORDER + TITLE + " " + BORDER); System.out.println(BORDER + BORDER + BORDER); System.out.println("\n\nMap04 Connections are:"); while (st1.hasMoreTokens()) { System.out.println(st1.nextToken()); } System.out.println("Start: " + entry); while ((dest.hasMoreTokens())) { String loopString = dest.nextToken(); int loopInt = loopString.indexOf("-"); locationOne = loopString.substring(loopInt - 1,loopInt); locationTwo = loopString.substring(2); if (((locationOne.equalsIgnoreCase(entry))) && ((!locationTwo.equalsIgnoreCase(entry)))) { destinations = locationTwo; destinationsList = destinationsList + destinations + ","; } if (((locationTwo.equalsIgnoreCase(entry))) && ((!locationOne.equalsIgnoreCase(entry)))) { destinations = locationOne; destinationsList = destinationsList + destinations + ","; } } System.out.println("Destinations List: " + destinationsList); System.out.print("Enter the Destination: "); input = stdin.readLine(); input = input.toUpperCase(); StringTokenizer valid = new StringTokenizer(destinationsList, ","); while (!input.equalsIgnoreCase("EXIT")){ StringTokenizer loopDest = new StringTokenizer(map.getConnections(), ","); StringTokenizer secondDest = new StringTokenizer(map.getConnections(), ","); System.out.println("Map04 Connections are: "); while (loopDest.hasMoreTokens()) { System.out.println(loopDest.nextToken()); } while (secondDest.hasMoreTokens()) { currentToken = secondDest.nextToken(); indexOfLetter = (currentToken.lastIndexOf(input)); if (indexOfLetter == 2) { secondDestinations = currentToken.substring(0,1); } if (indexOfLetter == 0) { secondDestinations = currentToken.substring(2); } if ((indexOfLetter == 0) || (indexOfLetter == 2)) { secondDestinationsList = secondDestinationsList + secondDestinations + ","; } else { System.out.print("Enter the Destination:"); currentToken = stdin.readLine(); currentToken = currentToken.toUpperCase(); } System.out.println("Destinations List: " + secondDestinationsList); } System.out.print("Enter the destinationlast: "); input = stdin.readLine(); input = input.toUpperCase(); } } } MAP 04 /** * @author Andrew Luxton-Reilly * @version 22/03/04 * * The Map class is used to hold the map used for the Maze application. The map is represented as * a String containing a series of comma delimited connections. Each connection (path) takes the form of * <MAP_IDENTIFIER>-<MAP_IDENTIFIER>. * * The identifiers used to name each location in the maze can be any length, but must be all in UPPER CASE. * * Map04 consists of multiple connections. An Entry point for the maze is also defined. It must be one * of the <MAP_INDENTIFIER> which make up the connections. */ public class Map04 { private final String CONNECTIONS = "A-B,A-C,C-D,D-E,E-A"; private final String ENTRY = "A"; public String getConnections(){ return CONNECTIONS; } public String getEntry(){ return ENTRY; } } |
![]() |
| Viewing: Dev Articles Community Forums > Programming > Java Development > Newbie Help PLEASE! |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|