The code shown below is my main method of a maze game I am creating.
In this main method I have a while loop that goes on until the game is finished.
In the while loop I print the maze then ask the user which direction they want to move their character.
I am having a crazy problem, the prompt to the user asking for the key, wont display.
The output just prints the maze and then waits for user input.
do
{
maze.printArray();
//Asks the user which direction they wish to move THIS LINE NEVER SHOWS UP!
System.out.print ("Enter U,L,D,R to indicate move direction: ");
//Gets the string from user, and changes it to a char, then converts it to an uppercase
direction = read.next().charAt(0);
direction = Character.toUpperCase(direction);
//Moves the character and increments the invalidMoves counter if the move was not legal
if(maze.move(direction) == false)
invalidMoves++;
//Increment the move count regardless of its validity
moves++;
}
while(maze.isFinished() == false);
This is the printArray method which is called before the print.
public void printArray()
{
for (char [] x : mazeArray)
{
for (char y : x)
{
//Print the characters for the row
System.out.print (y);
}
//linebreak to go to next row
System.out.println ();
}
System.out.println ();
}
The 2D array holds a maze pattern which is displayed to the screen as such
XXXXXXXXXX
XO-------X
XX-XXX-XXX
XX---X---X
XXXX-X-X-X
X----X-XXX
X-XXXX--$X
XXXXXXXXXX
Try
printlninstead ofprint…