Correction ship direction

master 9
Lisa 7 years ago
parent 5a98026252
commit 8e6b4e5a7b

@ -38,7 +38,11 @@ public class Ship extends Observable {
}
public void turnLeft() {
heading = (heading - 90) % 180;
if (heading - 90 < 0) {
heading = 360 + ((heading - 90) % 360);
} else {
heading = (heading - 90) % 360;
}
this.setChanged();
notifyObservers(ShipEvent.TURN_LEFT);
}

@ -20,11 +20,15 @@ public class ShipLog implements Observer {
System.out.println("Cannons fired.");
break;
case TURN_LEFT:
heading = (heading - 90) % 180;
if (heading - 90 < 0) {
heading = 360 + ((heading - 90) % 360);
} else {
heading = (heading - 90) % 360;
}
System.out.println("Turned left. New heading " + heading + " degrees.");
break;
case TURN_RIGHT:
heading = (heading + 90) % 180;
heading = (heading + 90) % 360;
System.out.println("Turned right. New heading " + heading + " degrees.");
break;
}

Loading…
Cancel
Save