aboutsummaryrefslogtreecommitdiff
path: root/Week14 Route 66/src/OO14route66/Car.java
diff options
context:
space:
mode:
authorCamil Staps2015-05-28 23:50:19 +0200
committerCamil Staps2015-05-28 23:50:19 +0200
commita8281523e2bbee4a1b4688f175896fe9c6b30c55 (patch)
treef519960e5c48f215edf8a4f1a75917200f329eb4 /Week14 Route 66/src/OO14route66/Car.java
parentStart w14 (diff)
This does seem to work a bit... kindof...
Diffstat (limited to 'Week14 Route 66/src/OO14route66/Car.java')
-rw-r--r--Week14 Route 66/src/OO14route66/Car.java27
1 files changed, 25 insertions, 2 deletions
diff --git a/Week14 Route 66/src/OO14route66/Car.java b/Week14 Route 66/src/OO14route66/Car.java
index 4448a27..6ebb863 100644
--- a/Week14 Route 66/src/OO14route66/Car.java
+++ b/Week14 Route 66/src/OO14route66/Car.java
@@ -1,5 +1,6 @@
package OO14route66;
+import com.camilstaps.route66.Driver;
import java.awt.Color;
import java.awt.Graphics;
import java.util.Random;
@@ -26,25 +27,47 @@ public class Car
private int location; // current location on the road
private final Color color; // color of this car
private final Random random; // here to ensure that every car gets a new
+ private final Driver driver;
+ private final Model model;
/**
* The constructor
* @param number of the car
*/
- public Car(int number) {
+ public Car(int number, Model model) {
this.number = number;
random = new Random();
speed = MINCARSPEED + random.nextInt(MAXCARSPEED - MINCARSPEED + 1);
direction = Direction.intToDirection(number);
location = RoadView.WINDOWSIZE - 2 - (number/Model.DIRECTIONS) * (CARLENGTH + MINCARSPACE);
color = carColors[number % carColors.length];
+ driver = new Driver(this);
+ this.model = model;
+ }
+
+ public Driver getDriver() {
+ return driver;
+ }
+
+ public Direction getDirection() {
+ return direction;
+ }
+
+ public int getNumber() {
+ return number;
+ }
+
+ public int getNewLocation() {
+ return (location + speed) % RoadView.WINDOWSIZE;
}
/**
* move this car one step
*/
public void step() {
- location = (location + speed) % RoadView.WINDOWSIZE;
+ location = getNewLocation();
+ Regelaar.getInstance().setLocation(this, location);
+ model.update();
}
/**