• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Java Maze Not Printing Out

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?




 
Sheriff
Posts: 7123
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
Rancher
Posts: 1059
27
Netbeans IDE Oracle MySQL Database Tomcat Server C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 8545
615
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 7123
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Les Morgan wrote:

for a negative test.


Yes, thanks for the correction.
 
Liutauras Vilda
Sheriff
Posts: 8545
615
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Good night. Drive safely. Here's a tiny ad for the road:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic