This is a very simple Java code and I want to write a code that counts how many times the step method is called. Essentially, this code will draw a blob and count how many "steps" the blob takes. If the step number is equal to the Max, then the blob will take a new dx/dy e.g. a new velocity.
The Blob class is not that important, so I didn't attach it. However, the PurposefulWanderer class is called by another class, specifically a GUI
I tried making a static variable called current and I increment it by one under the step method, but this isn't working. It still says that the current variable is still 0.
public class PurposefulWanderer extends Blob {
private int TOTAL;
private static int current = 0;
public PurposefulWanderer (double x, double y) {
super (x, y);
this.TOTAL = (int) (Math.random()*10)+10;
}
@Override
public void step() {
++current;
// Choose a new step between -1 and +1 in each of x and y
if (current == this.TOTAL)
dx = 2 * (Math.random()-0.5);
dy = 2 * (Math.random()-0.5);
x += dx;
y += dy;
current = 0
}
}