I have to code a battleship game on processing. Now im at the point that when i click that the element beneath if should come out. Like if its a part of the ship than it should show it. But i have been busy trying to slove this little problem for weeks now and im not any further and my assignments are within vew days. I am not allowed to use classes tho.
I hope this could help you in some way.--
void mouseClicked ()
{
int mouseShipX = mouseY/CELLSIZE ;
int mouseShipY mouseX/CELLSIZE ;
for (int x = 0; x< NUM_COLS; x++)
{
for (int y = 0; y < NUM_ROWS; Y++)
{
if ( shipX [y] == mouseShipX && shipY [x] == mouseShipY)
{
fill (0);
textSize (CELLSIZE) ;
text ("HIT", (shipHitX [x] * CELLSIZE) , (shipHitY [y] * CELLSIZE) + CELLSIZE/2+textAscent()/2);
shipHitX [x] = shipY [x];
shipHitY [y] = shipX [y];
}
}
}
}
Get Answers For Free
Most questions answered within 1 hours.