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/RoadView.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'Week14 Route 66/src/OO14route66/RoadView.java') diff --git a/Week14 Route 66/src/OO14route66/RoadView.java b/Week14 Route 66/src/OO14route66/RoadView.java index 1d53269..4495822 100644 --- a/Week14 Route 66/src/OO14route66/RoadView.java +++ b/Week14 Route 66/src/OO14route66/RoadView.java @@ -74,8 +74,8 @@ public class RoadView extends JFrame * @param g graphics to draw on */ private void paintRoad (Graphics g) { - final int left = (WINDOWSIZE / 2) - Car.CARWIDTH - 4; - final int width = 2 * Car.CARWIDTH + 8; + final int left = getStartCrossing(); + final int width = getEndCrossing() - left; g.setColor(Color.white); // background g.fillRect(0, 0, WINDOWSIZE, WINDOWSIZE); g.setColor(Color.darkGray); // streets @@ -84,4 +84,12 @@ public class RoadView extends JFrame g.fillRect(left, 0, width, WINDOWSIZE); } } + + public static int getStartCrossing() { + return (WINDOWSIZE / 2) - Car.CARWIDTH - 4; + } + + public static int getEndCrossing() { + return getStartCrossing() + 2 * Car.CARWIDTH + 8; + } } -- cgit v1.2.3