Results 1 to 2 of 2
Thread: Array help
- 10-12-2012, 06:55 PM #1Member
- Join Date
- Oct 2012
- Rep Power
Ive hit a road block even though I think the solution is probably staring me in the face.
I have 5 static objects and 1 objects which moves (ill call this A).
When the program starts I need A to move to the closest object. Once its there I need it to move to the next closest one, then the next closest one etc. Once it has moved to an object it needs to ignore it for the rest of the run. Once it has moved through all 5 objects the program ends.
The way I have done it is made an array and find the distance to all the balls and store these values in an array.
Next I have made a 2nd array to store the sorted distances.
Then I have a for loop with this in it
if(eculDist[i] == eculDistSort)
Now my program currently moves A to the closest object but once its there I have no idea how to get it to then move again to the next closest one.
I have usedJava Code:
Sorry for the wall of text.
Thanks for any help.
- 10-12-2012, 07:06 PM #2
Re: Array help
Well, you can do a couple different things. Either make sure you only create that array once instead of updating it constantly, or you can update it constantly but keep track of which Objects you've already visited (either as a part of the Object itself or in a separate data structure). Which one you go with is dependent upon exactly what you want the program to do.
- By thewrongsyntax in forum New To JavaReplies: 3Last Post: 12-28-2013, 10:39 PM
- By jtothemax in forum New To JavaReplies: 15Last Post: 05-14-2012, 01:42 PM
- By jonathan920 in forum NetBeansReplies: 0Last Post: 05-12-2011, 08:04 PM
- By asmodean in forum New To JavaReplies: 23Last Post: 09-07-2010, 09:12 PM
- By javanew in forum New To JavaReplies: 2Last Post: 09-06-2010, 02:03 AM