/* * Copyright (c) 2015 Camil Staps */ 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; /** * * @author camilstaps */ public class Driver implements Runnable { private final Car car; private final Random r; public Driver(Car car) { this.car = car; r = new Random(); } @Override @SuppressWarnings("empty-statement") public synchronized void run() { while (true) { while (!Regelaar.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); } } } }