Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

moving in a maze

 
Thomas Whalen
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
will someone give me a very simple example of simulating movement in a maze? i want to try this from the console first (worry about the logic right now), then move it to an applet. or, can doing such a thing only be done within a C++ console? i think a multi-dimensional array is used, with a marker.
 
William Barnes
Ranch Hand
Posts: 986
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well if you have a "maze" class you could have methods like: MoveRight(), MoveLeft(), MoveUp(), MoveDown(). The class would also have a print() method so that you could display the maze and your location in it. A two dimentional array would be the first thing that came to mind to represent the maze.
 
Thomas Whalen
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
that's about as far as I had gotten with it, before I decided to post in the forum about this. my main question is this: can this be done from the console? or, must it be done within an applet?
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course. Anthing that can be done from an Applet can be done from an application. Just add a main method that creates an object of the class, add a constructor that creates a Frame and adds the applet to the Frame and executes the init() and start() methods - that should get you started. To be REALLY cool you would want to replace the browsers functionality in calling stop() and start() by adding listeners to see if the Frame has gotting minimized or covered up etc.
My suggestion: go to javaboutique.com and find an applet or application that has a maze or something close and check out their code.
 
Jason Kretzer
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will also want to use a Stack data structure so that if you hit a dead end you can go back spaces.

Best Regards,
-Jason
 
Thomas Whalen
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
after reading the responses to my question, it appears that I don't have a clue what I am doing. I can mentally see what is happening, I just don't know how to translate this to code.
 
Jason Kretzer
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a very common program for Java students to help them learn recursion. You should try looking in a text book. Go to a local college library or bookstore and look for the programming texts. Look up recursion in the index and they almost always use a maze example.
Alternately, you could just go here. http://math.hws.edu/xJava/other/maze.html
I found this doing a google search for maze source code java.
Hope this helps.

------------------
Jason R. Kretzer
Software Engineer
[This message has been edited by Jason Kretzer (edited December 10, 2001).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic