Reputation: 9
I have my maze and can go north east south west but how do i move ne or sw. if possible can you guys give me examples using my code. thanks its a 4x4 array.
the user interface
//Begin user dialog
System.out.println("Welcome");
input ="";
while(!input.equals("quit"))
{
System.out.println(map.rooms[row][col].name);
System.out.print(">");
input = scan.nextLine().toLowerCase();
switch (input) {
case "n":
if(map.rooms[row][col].isValidExit("n"))
row--;
else
System.out.println("You cant go that way");
break;
case "s":
if(map.rooms[row][col].isValidExit("s"))
row++;
else
System.out.println("You cant go that way");
break;
case "w":
if(map.rooms[row][col].isValidExit("w"))
col--;
else
System.out.println("You cant go that way");
break;
case "e":
if(map.rooms[row][col].isValidExit("e"))
col++;
else
System.out.println("You cant go that way");
break;
Upvotes: 0
Views: 1932
Reputation: 6887
example north-east:
case "ne":
if(map.rooms[row][col].isValidExit("ne")) {
col++;
row--;
}
else {
System.out.println("You cant go that way");
}
break;
Upvotes: 0
Reputation: 21
you need to char-parse your input
while(!input.equals("quit"))
{
System.out.println(map.rooms[row][col].name);
System.out.print(">");
input = scan.nextLine().toLowerCase();
char[] inputArray = input.toCharArray();
for(char c : inputArray){
switch (input) {
case "n":
if(map.rooms[row][col].isValidExit("n"))
row--;
else
System.out.println("You cant go that way");
break;
case "s":
if(map.rooms[row][col].isValidExit("s"))
row++;
else
System.out.println("You cant go that way");
break;
case "w":
if(map.rooms[row][col].isValidExit("w"))
col--;
else
System.out.println("You cant go that way");
break;
case "e":
if(map.rooms[row][col].isValidExit("e"))
col++;
else
System.out.println("You cant go that way");
break;
Upvotes: 1