I have a 2D array with JButtons.
Im trying to build a method that starting from a square on last row by clicking another square will check if those both are connected or not (path of specific ImageIcon). Squares that you can stand on called Stones and squares that connect Stones called Bridge. Here is my method so far:
Cordinate is a class that takes two integers (x,y) and add(Cordinate c) takes the current Cordinate element and add it on x and y variables (So if found bridge move to the next square)
Now, my problem. If there is a Bridge element in front (Cordinate(-1,0)) everything working excelent, but if is not then trying to scan others and here something going wrong and never move on. Look System.out debugging i have to understand
If anyone find what going on....then is Mastermind :P
Hello Hunter, thank you for quick reply. I just check what you told me but current position changed anytime player moves to new Stones. Add some more System.out to debug and noticed that if function when doing scanning detect (Bridge) object before the (Bridge) object that connect the current with the destination then start doing what i have above in Console.
For example, if scanning goes UP-LEFT-RIGHT-DOWN and im standing on a Stones that has at the LEFT and DOWN side Bridge and select to go DOWN. Function check UP = no Bridge, then LEFT = there is a Bridge BUT not included in destination's Bridge and here function start acting like crazy. As you can see from above, start scanning again from begining many times
hmm well I'm having trouble understanding what your question is. So the application you are creating searches for a path between a start position and an end? and then uses Bridge objects to cross Stones? is that right?
I am afraid that without seeing any other code, it will be very hard for any of us to help. What Hunter mentioned was correct though: the method you listed seems to always get a Stones object called current with the same values for getColumn() and getRow().
Maybe upload the code to some public svn repository?
Wim suggestion is a good idea, that way we can see the entire code. Also you might consider looking up depth-first search and breadth-first search algorithms, to classic ways to find paths from start to finish.