Peter Steglich

Greenhorn
+ Follow
since Jul 18, 2009
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Peter Steglich

Hey,

thanks to your answer and the tutorial I was now able to change the code so it works.

Thank you so much.
14 years ago

pete stein wrote:

David Newton wrote:If you don't want to modify the original instance then you'll need to make a copy of it.



Which is what I believe my code example did.



As far as I understand it your code creates a copy pete and so does mine. But since I have a loop in CheckValueOfMazePoint I would have to give the index-variable to the method, right? The LocCont that I create should be a copy as well or am I wrong there?
It is as I said probably not the cleanest code but works for now.

More urgent is the question about where to put the paint method and how to handle it...

I know you are all very smart ;) please give me an answer.

Thank you so much and enjoy your Sunday!
14 years ago
Hi,
thanks for the answer.
I changed my code into:

and it works. But I am not sure whether this is what you meant by make a copy. I am very open for any cleaner approach^^

I have another problem with my maze, but am not sure whether I should start a new topic...So here it goes ;)
I am drawing my maze[][]-Array onto a JPanel. This is initialized by the mazeGUI.java as follows:


Then it calls createMaze.java which part of it I already posted:


As you can see I have the createPath() from the first question in the paint method, which I now know is stupid. Right now every time the program paints on the JPanel it also produces a new Maze, right?
The examples I found online all used the paint method so I guess that is the way to go. But how do I change the code so that whenever the maze[][]-content is changed it also draws a new maze on the JPanel. I have read something about a repaint method which is called in that case. But how do I define it and where do I have to put the createPath()?

Thank you very much although it is admittedly a fairly large chunk of code.

14 years ago
Thank you very much for your reply. I now at least understand what the problem is.

Your solution does not solve it, though. "goAhead" actually runs in a loop so when I execute it more than once I get the same problem with the reference.

My question is probably how can I create a Vector/List/Array (whatever is best) that holds the Points I give it. They shall not change upon changing the Point Loc of the method which is change constantly throughout the program.

Thank you again!
14 years ago
Hey everybody,

I try to write an algorithm for creating a maze (or more precise the path through the maze). My idea is that I have a loop that will crawl trough the array from a start Point. From every point the path reaches it can crawl in a random amount of directions and set the value for the maze = 1 (which stands for the path and 0 for a wall).

My problem now is that I have to save the old points in a ArrayList when I go from one point into multiple directions so I can later read from the list to come back and to some more crawling form that point which will go to several new points which then will be saved in the list and so on.
But whenever I save a new point in the ArrayList and then change the Point back to its original value (since I may have to go to more directions from this point) it changes the Value of the Point saved in the List as well. I am pretty sure that my whole understanding of who has which access rights here is mixed up.
How can I change the code so that the line 29 does not change the value of the point in the ArrayList.
I hope I make a little bit of sense.
Thank you very much for your help.

14 years ago