-2

I am writing a game with java. I have more then one classes. I notice that if I am not changing the name of functions or variables. When I compile the code from the class includes main function it is not compiling the other classes and running the old version. For example I have below function which is can't return 1 in my opinion. But it is returning value 1 because the old version of this function returns 1. Not just this, I experienced this so many times. I am compiling from terminal with javac command. Here is my function:

public class CollisionMaker{
        public int makeCollision(GameObject a,GameObject b){
                int minxa = a.getx();
                int maxxa = a.getx()+a.getwidth();
                int minya = a.gety();
                int maxya = a.gety()+a.getheight();

                int minxb = b.getx();
                int maxxb = b.getx()+b.getwidth();
                int minyb = b.gety();
                int maxyb = b.gety()+b.getheight();

                int d1x = minxb-maxxa;
                int d1y = minyb-maxya;
                int d2x = minxa-maxxb;
                int d2y = minya-maxyb;

                int highest = d1x;
                int highest_id = 0;
                if(d1x >= highest){highest = d1x;highest_id = 2;}
                if(d1y > highest){highest = d1y;highest_id = 2;}
                if(d2x > highest){highest = d2x;highest_id = 3;}
                if(d2y > highest){highest = d2y;highest_id = 4;}

                if(d1x > 0 || d1y > 0){return 0;}
                else if(d2x > 0 || d2y > 0){return 0;}
                else{return highest_id;}
        }
}
sepp2k
  • 363,768
  • 54
  • 674
  • 675
Baran
  • 131
  • 8
  • 2
    How do you compile classes? If you are compiling them with `javac` one-by-one, you will have to compile each java class where code change is done. Then only new class file will get generated – AbhiN Mar 31 '20 at 09:18
  • You *think*? Don't you kinow? Doesn't the compiler tell you anything? – user207421 Mar 31 '20 at 09:20
  • 1
    You can compile them with "javac *.java" if all your source files are in the same directory. – NomadMaker Mar 31 '20 at 10:14
  • @user207421 doesn't tell anything – Baran Mar 31 '20 at 13:30
  • @AbhiN I am just compiling the main function. I wasn't know that I have to compile them one by one. I will try thanks. – Baran Mar 31 '20 at 13:31

1 Answers1

1

There are several ways to make sure you compile all (changes) classes. Please check out the answers to javac option to compile all java files under a given directory recursively

sveinni
  • 26
  • 4