ive been working on this side project trying to make a battle ship game from some time now. I have come across a few things I do not know how to do. I was wondering if anyone knew how I could make each of the five ships with their appropriate lengths and then randomize their location on the boards.

I draw the two boards like this in my void setup()

 //drawing grid
  for(int i = 0; i < 10; i++){
     for(int j = 0; j <10; j++){
      squares.add(new ObjGame( 20+50*i,75+50*j));
      squares.add(new ObjGame( 580+50*i,75+50*j));

here is where I create the matrix for the ships and the hit icons. I do it in their own class in order to try and keep my main kinda clean

ObjGame(int xi, int yi){
   ship = random(5)<.5;

   x = xi;
   y = yi;
  void draw(){

        if(!ship && clicked){
         fill(255); //white circle for miss);
        else if(ship && clicked){
          fill(255,0,0); //red circle for hit

      void attacked(){
        if(mouseX <= 500){
        if(mouseX> x && mouseX< x+ 50 && mouseY > y && mouseY < y+50){
         clicked = true;
         println(x+" "+y);

i am also trying to print out their coordinates but I want them to print out 0 - 9 instead of their actual x and y coordinates, is there an easy way to fix that or should I just be switching them?

  • \$\begingroup\$ thank you for moving your question from stackoverflow.com/questions/59169235/… +1 \$\endgroup\$ – Martin Frank Dec 4 '19 at 8:20
  • \$\begingroup\$ @Tim Holt thank you for pointing out the differences between java and processing - since the details on stackoverflow are more helpful than these on gamedev i know now what was wrong with my anser and i'll withdraw it. \$\endgroup\$ – Martin Frank Dec 10 '19 at 5:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.