Results 1 to 2 of 2
Thread: Array help
- 10-12-2012, 05:55 PM #1
Member
- Join Date
- Oct 2012
- Posts
- 1
- Rep Power
- 0
Array help
Hello
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
Once this executes, say it gets to i = 3 and that is equal to the smallest distance it then sets 3 as the value for which object I want to move to.Java Code:if(eculDist[i] == eculDistSort[0])
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 usedto see whats happening and the numbers are constantly been updated as A moves closer to the object.Java Code:System.out.println(Arrays.toString(eculDist));
Sorry for the wall of text.
Thanks for any help.
- 10-12-2012, 06: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.
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
Similar Threads
-
[Problem] Enhanced for-loop with 2D arrays (or array in array)
By thewrongsyntax in forum New To JavaReplies: 0Last Post: 10-07-2012, 08:49 PM -
Reading a text file into an Array and spliting the content into another Array
By jtothemax in forum New To JavaReplies: 15Last Post: 05-14-2012, 12:42 PM -
Display Array on another class after extracting from txt file and into array problem
By jonathan920 in forum NetBeansReplies: 0Last Post: 05-12-2011, 07:04 PM -
Variable of an object in an array compared to an element of another array?
By asmodean in forum New To JavaReplies: 23Last Post: 09-07-2010, 08:12 PM -
Trying to make an array list // inserting an element to middle of array
By javanew in forum New To JavaReplies: 2Last Post: 09-06-2010, 01:03 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks