I'm sooooo close to finishing this Java applet I'm working on. I only have three things which I'm struggling to get to work.
#1 The solution
The user presses a button and the applet should run through the solution to the puzzle. I kinda have it working in so much as the applet seems to run through the solution but the display doesn't get refreshed until the solution is finished.
public void solution() {
int solutionSteps = 9;
for (int i = 0; i < solutionSteps; i++) {
doSolutionStep(i);
try {Thread.sleep(1500);}
catch (Exception e) {e.printStackTrace();}
}
}
public void doSolutionStep(int step) {
int y = 0, z = 0;
switch(step) {
case 1 : {
for (int i = z; i < theJeeps.length; i++) {
forward(theJeeps[i]);
try {Thread.sleep(1500);}
catch (Exception e) {e.printStackTrace();}
}
for (int x = 1; x < theJeeps.length; x++) {
theJeeps[y].transfer(theJeeps[x]);
}
home(theJeeps[y]);
y++;
z++;
break;
}
case 2 : {
for (int i = z; i < theJeeps.length; i++) {
forward(theJeeps[i]);
try {Thread.sleep(1500);}
catch (Exception e) {e.printStackTrace();}
}
for (int x = 1; x < theJeeps.length; x++) {
theJeeps[y].transfer(theJeeps[x]);
}
home(theJeeps[y]);
y++;
z++;
break;
}
I don't see why the display shouldn't get refreshed as I'm calling the forward method which refreshes the display so I assumed that everytime the forward method runs the display would get refreshed.
#2 When the user completes the puzzle it's supposed to pop up a dialog box with a congratulatory message. However I can't seem to figure out why it's not working.
protected boolean forward() {
this.desert = desert;
if (won()) {
desert.gameWon();
return false;
}
else {
if (canGoForward()) {
distance += 40;
petrol -= 1;
return true;
}
else {return false;}
}
}
private boolean won() {
if (distance == (9 * 40)) {
return true;
}
else {return false;}
}
The IDE I'm using (eclipse) flags up the line
desert.gameWon(); with the following error:
The assignment to variable desert has no effect which I guess is why it's not working but I don't really understand why/how.
#3 The IDE is flagging up all the classes with the following messages:
The serializable class (name of class) does not declare a static final serialVersionUID field of type long I'm not really sure what this means, it doesn't seem to be affecting the running of the applet.
I have attached a zipped copy of the applet & please be gentle with me as I'm still learning Java