aspose file tools*
The moose likes Beginning Java and the fly likes moving in a maze Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "moving in a maze" Watch "moving in a maze" New topic
Author

moving in a maze

Thomas Whalen
Ranch Hand

Joined: Aug 26, 2001
Posts: 123
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.


if you don't know, then ask. if you do know, then share. love is knowledge.
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 986

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.


Please ignore post, I have no idea what I am talking about.
Thomas Whalen
Ranch Hand

Joined: Aug 26, 2001
Posts: 123
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

Joined: Sep 29, 2000
Posts: 8521
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.


"JavaRanch, where the deer and the Certified play" - David O'Meara
Jason Kretzer
Ranch Hand

Joined: May 31, 2001
Posts: 280
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


Jason R. Kretzer<br />Software Engineer<br />System Administrator<br /><a href="http://alia.iwarp.com" target="_blank" rel="nofollow">http://alia.iwarp.com</a>
Thomas Whalen
Ranch Hand

Joined: Aug 26, 2001
Posts: 123
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

Joined: May 31, 2001
Posts: 280
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).]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: moving in a maze