help me with some java please ?

Associate
Joined
20 Jul 2007
Posts
1,364
Well for our course we have to make a battleships game...

At the moment ive got the grid, and various shaped rectangles to represent ships.

But i want them to snap to the grid, to do this i compare 2 lines and take away where the mouse is currently. For example, if theres a line at 100 and 150 and you click at 120, itd work out 100 -120, and 150-120. (it then squares to remove any negative sign and divides again to a reasonable number).

This then goes through a basic bubble sort to find the lowest number, which should then be the nearest line which it should snap to. Thing is....it dosn's work.

For some reason its not seeming to fill the array thats sorted, think im doing something very wrong.

This is the sort formula:
public void sortX()
{

for ( int pass = 1; pass < mxCalculated.length; pass++ ) // passes

for ( int count = 0; count < mxCalculated.length - 1; count++ ) // one pass

if ( mxCalculated[ count ] > mxCalculated[ count + 1 ] )
{ // one comparison
temporaryStore = mxCalculated[count]; // one swap
mxCalculated[ count ] = mxCalculated[ count + 1 ];
mxCalculated[ count + 1 ] = temporaryStore ;
}


}


This is what should fill the array "mxCalculated":
for(int Index=0;Index < 10; Index++)
{

mxTemp[Index] =( mxLine[Index] - mx);
mxCalculated[Index] = ((mxTemp[Index])*(mxTemp[Index]));//squares to remove negative
mxCalculated[Index] =((mxCalculated[Index])/(mxCalculated[Index])); //devides to regain correct number
sortX();


}


I know im missing something ludicrously simplel......just cant see what.
 
Back
Top Bottom