aboutsummaryrefslogtreecommitdiff
path: root/Week14 Route 66/src/com/camilstaps/route66/Crossing.java
diff options
context:
space:
mode:
Diffstat (limited to 'Week14 Route 66/src/com/camilstaps/route66/Crossing.java')
-rw-r--r--Week14 Route 66/src/com/camilstaps/route66/Crossing.java61
1 files changed, 0 insertions, 61 deletions
diff --git a/Week14 Route 66/src/com/camilstaps/route66/Crossing.java b/Week14 Route 66/src/com/camilstaps/route66/Crossing.java
deleted file mode 100644
index 65e2527..0000000
--- a/Week14 Route 66/src/com/camilstaps/route66/Crossing.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright (c) 2015 Camil Staps
- */
-package com.camilstaps.route66;
-
-import OO14route66.Direction;
-import OO14route66.Model;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- *
- * @author camilstaps
- */
-public class Crossing {
-
- private final Model model;
- private Direction allowed;
- private boolean crossingWaiting = false;
- private int requests = 0;
-
- public Crossing(Model model, Direction allowed) {
- this.model = model;
- this.allowed = allowed;
- }
-
- public Direction getAllowed() {
- return allowed;
- }
-
- public synchronized void doSwitch() {
- crossingWaiting = true;
- while (!model.isCarsOnCrossing());
- System.err.println("Switching");
- if (allowed == Direction.East || allowed == Direction.West) {
- allowed = Direction.North;
- } else {
- allowed = Direction.East;
- }
- requests = 0;
- System.err.println("Switched to " + allowed);
- crossingWaiting = false;
- //notifyAll();
- }
-
- public boolean isAllowed(Direction direction) {
- return !crossingWaiting && (direction == allowed || Direction.opposite(direction) == allowed);
- }
-
- public boolean doRequest() {
- //if (++requests >= 2) {
- if (crossingWaiting) {
- return false;
- }
- doSwitch();
- return true;
- //}
- //return false;
- }
-
-}