hey guys
I am a new member will you please help me with this question?
Design a program that creates a virtual world you can “walk” around in, based on text. The user should be able to type in N,E,S,W to move North, East, South, and West.
The world can be represented with a two dimensional array. Based on where the user wants to move, you can increment or decrement the first or second dimension of the array.
Print the user’s position after each move, in X/Y coordinates
here is the code which i made
package chapt10;
import java.util.Scanner;
public class walk {
/**
* @param is
*/
public static void main(int[][] is) {
// TODO Auto-generated method stub
main(new int [10][10]);
Scanner sc = new Scanner (System.in);
String choice = "Y";
while (!choice.equalsIgnoreCase(choice))
System.out.println("Enter 'N' to move north, 'S' to move south, 'E' to move east, or 'W' to move west");
int currentX = 5;
int currentY = 5;
boolean quitGame = false;
while (!quitGame)
{
System.out.println("Enter 'N' to move north, 'S' to move south, 'E' to move east, or 'W' to move west");
System.out.println("Enter 'Q' to quit the game.");
String userInput = sc.nextLine();
if (userInput == "N")
{
currentY = currentY + 1; // move the player one unit north.
}
else if (userInput == "S")
{
currentX--; // move the player one unit south.
}
else if (userInput == "E")
{
currentY--; // move the player one unit east.
}
else if (userInput == "W")
{
currentX--; // move the player one unit west
}
else if (userInput == "Q")
{
quitGame = true;
continue;
}
else
{
System.out.println("I didn't recongnize that comman,Please try again.");
}
System.out.println("Tou are at the position" + currentY + "," + currentY + ",");
}
}
}