diff options
author | Camil Staps | 2015-05-29 08:16:55 +0200 |
---|---|---|
committer | Camil Staps | 2015-05-29 08:16:55 +0200 |
commit | a6183f57e9d432feae273c0b294cf90d3e97d835 (patch) | |
tree | 3e710a81f4da526142e809e5057ee60f782c651b /Week14 Route 66/src/com/camilstaps/route66/Driver.java | |
parent | Added w14 to readme (diff) |
comments; cleanup
Diffstat (limited to 'Week14 Route 66/src/com/camilstaps/route66/Driver.java')
-rw-r--r-- | Week14 Route 66/src/com/camilstaps/route66/Driver.java | 41 |
1 files changed, 26 insertions, 15 deletions
diff --git a/Week14 Route 66/src/com/camilstaps/route66/Driver.java b/Week14 Route 66/src/com/camilstaps/route66/Driver.java index f10bb3a..e2e5a7d 100644 --- a/Week14 Route 66/src/com/camilstaps/route66/Driver.java +++ b/Week14 Route 66/src/com/camilstaps/route66/Driver.java @@ -5,10 +5,7 @@ package com.camilstaps.route66; import OO14route66.Car; import OO14route66.Model; -import OO14route66.Regelaar; import java.util.Random; -import java.util.logging.Level; -import java.util.logging.Logger; /** * @@ -20,29 +17,43 @@ public class Driver implements Runnable { private final Random r; + private boolean running; + private int delay; + public Driver(Car car) { this.car = car; r = new Random(); } + + public void setRunning(boolean value) { + running = value; + } + + public void setDelay(int value) { + delay = value; + } @Override @SuppressWarnings("empty-statement") - public synchronized void run() { + public void run() { + running = true; while (true) { - while (!Regelaar.getInstance().isSafeLocation(car, car.getNewLocation())); + while (!running || !Overviewer.getInstance().isSafeLocation(car, car.getNewLocation())); car.step(); - - try { - int bonus = 0; - if (Math.abs((System.currentTimeMillis() / 1000) % Model.NUMBEROFCARS - car.getNumber()) < 2) { - bonus = -30; - } - Thread.sleep(Math.abs(r.nextInt(50) + 5 + bonus)); - } catch (InterruptedException ex) { - Logger.getLogger(Driver.class.getName()).log(Level.SEVERE, null, ex); - } + + pause(); } } + protected void pause() { + try { + int bonus = 0; + if (Math.abs((System.currentTimeMillis() / 1000) % Model.NUMBEROFCARS - car.getNumber()) < 2) { + bonus = -50; + } + Thread.sleep(Math.abs(r.nextInt(50) + delay + bonus)); + } catch (InterruptedException ex) {} + } + } |