Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Maze Not Printing Out  RSS feed

 
Liam Mass
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I have been tasked to create a program that allows a user to choose any one of three premade mazes, and then move an "o" on the screen to solve it. X's represent walls. I think I have a most of, if not all of the advanced looping parts done that allows the user to enter multiple commands instead of just one, and also interprets a single input with many commands such as "urrl" (Where "u" is up, "r" is right, etc.)

It is okay for the maze to reprint each time they move the "o," it does not have to be a GUI project.

However, when I added the necessary loops to achieve this goal, now the maze won't even print out the first time. I'm using eclipse and it says the program was terminated before the maze was printed out even once. What did I do wrong with printing the maze?




 
Knute Snortum
Sheriff
Posts: 4091
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at this line:

You probably don't mean to assign false to IsMazeComplete. but even this:

is not really correct, because there is no need to test for false -- in fact, this can lead to the very error you encountered. Instead just write:
 
Les Morgan
Rancher
Posts: 768
19
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:Take a look at this line:

You probably don't mean to assign false to IsMazeComplete. but even this:

is not really correct, because there is no need to test for false -- in fact, this can lead to the very error you encountered. Instead just write:


for a negative test.
 
Liutauras Vilda
Marshal
Posts: 4670
320
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch Liam, nice to see you around

Code is hardly readable at the moment.

1. You have got method "displayMaze(int mapchoice)", but it does complete different thing. Either method name is incorrect, or method content within the body is incorrect.
2. Line 94. Look carefully and see what is wrong.
From that you should learn, that never write == true, == false, but instead, write if (something), while(!something), but never if (something == true), so you'll avoid mistakes as you did now.
3. What x and y mean on line 72 and 73?

Sorry, indentation is inconsistent too. Too much code, you really need to split it up.

 
Liam Mass
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your help! By the way, the x and y on lines 72 and 73 are integers that are supposed to be the coordinates of where the user starts on the maze with the "o" character. They are different based on the maze chosen
 
Knute Snortum
Sheriff
Posts: 4091
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Les Morgan wrote:

for a negative test.

Yes, thanks for the correction.
 
Liutauras Vilda
Marshal
Posts: 4670
320
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Liam Mass wrote:By the way, the x and y on lines 72 and 73 are integers that are supposed to be the coordinates of where the user starts on the maze with the "o" character.

And based on that knowledge, how would you rename those x and y variables, so no one else would ever ask you that question again?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!