-
Notifications
You must be signed in to change notification settings - Fork 7
/
Program.cs
36 lines (33 loc) · 920 Bytes
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System;
namespace TrafficLightControlledIntersection
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
public class TrafficLight
{
private int curRoad = 1;
public TrafficLight()
{
}
public void CarArrived(
int carId, // ID of the car
int roadId, // ID of the road the car travels on. Can be 1 (road A) or 2 (road B)
int direction, // Direction of the car
Action turnGreen, // Use turnGreen() to turn light to green on current road
Action crossCar // Use crossCar() to make car cross the intersection
)
{
if (roadId != curRoad)
{
curRoad = roadId;
turnGreen();
}
crossCar();
}
}
}