diff options
author | Camil Staps | 2015-05-29 12:06:42 +0200 |
---|---|---|
committer | Camil Staps | 2015-05-29 12:06:42 +0200 |
commit | a68fa3c3c96c38b811755022089cb8aee2f5521c (patch) | |
tree | ef1463ba40bffedfb22aeca5547c7129c2dc3aca /Week14 Route 66/src/OO14route66/Car.java | |
parent | Overviewer without Map (diff) |
Intermediate commit: works partially, but sometimes cars go over each other (Crossing.isAllowed() is not synchronized)
Diffstat (limited to 'Week14 Route 66/src/OO14route66/Car.java')
-rw-r--r-- | Week14 Route 66/src/OO14route66/Car.java | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/Week14 Route 66/src/OO14route66/Car.java b/Week14 Route 66/src/OO14route66/Car.java index 97d7b33..c12291a 100644 --- a/Week14 Route 66/src/OO14route66/Car.java +++ b/Week14 Route 66/src/OO14route66/Car.java @@ -1,7 +1,6 @@ package OO14route66; import com.camilstaps.route66.Driver; -import com.camilstaps.route66.Overviewer; import java.awt.Color; import java.awt.Graphics; import java.util.Random; @@ -47,9 +46,8 @@ public class Car { direction = Direction.intToDirection(number); location = RoadView.WINDOWSIZE - 2 - (number/Model.DIRECTIONS) * (CARLENGTH + MINCARSPACE); colour = carColours[number % carColours.length]; - driver = new Driver(this); + driver = new Driver(this, model); this.model = model; - Overviewer.getInstance().hello(this); } /** @@ -97,8 +95,17 @@ public class Car { */ public void step() { location = getNewLocation(); + //System.err.println("Car "); model.update(); } + + public boolean isInFrontOfCrossing() { + return location < RoadView.getStartCrossing() && getNewLocation() >= RoadView.getStartCrossing(); + } + + public boolean isOnCrossing() { + return location > RoadView.getStartCrossing() && location - CARLENGTH < RoadView.getEndCrossing(); + } /** * Paint this car |