From a68fa3c3c96c38b811755022089cb8aee2f5521c Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Fri, 29 May 2015 12:06:42 +0200 Subject: Intermediate commit: works partially, but sometimes cars go over each other (Crossing.isAllowed() is not synchronized) --- Week14 Route 66/src/OO14route66/Car.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'Week14 Route 66/src/OO14route66/Car.java') 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 -- cgit v1.2.3