public Light() { int radius = 3; this.currentPattern = 3; bulbs = new Bulb[3]; Bulb red = new Bulb(ConsoleColor.Red, radius); Bulb orange = new Bulb(ConsoleColor.Yellow, radius); Bulb green = new Bulb(ConsoleColor.Green, radius); bulbs[0] = red; bulbs[1] = orange; bulbs[2] = green; //Light Signal pattern int[] stopPattern = { 0 }; int[] readyPattern = { 0, 1 }; int[] goPattern = { 2 }; int[] waitPattern = { 1 }; LightSignal stop = new LightSignal(stopPattern, 10); LightSignal ready = new LightSignal(readyPattern, 3); LightSignal go = new LightSignal(goPattern, 10); LightSignal wait = new LightSignal(waitPattern, 3); LightSignal[] tmp = { stop, ready, go, wait }; switchingOrder = tmp; }
public void switchPattern() { Console.Clear(); this.currentPattern = (++this.currentPattern % 4); LightSignal nextPattern = switchingOrder[currentPattern]; //Turn off all the bulbs foreach (Bulb b in this.bulbs) { b.On = false; } foreach (int bulbOn in nextPattern.BulbsOn) { this.bulbs[bulbOn].On = true; } //Show bulbs foreach (Bulb b in this.bulbs) { b.showBulb(); Console.WriteLine(); } System.Threading.Thread.Sleep(nextPattern.DurationInSeconds * 1000); }
void OnGUI() { //if connection has not been made, display button to connect if (myTCP.socketReady == false) { if (GUILayout.Button("Connect")) { //try to connect Debug.Log("Attempting to connect.."); myTCP.setupSocket(); } } //once connection has been made, display editable text field with a button to send that string to the server (see function below) if (myTCP.socketReady == true) { LightSignal testSignal = new LightSignal("PrimaryTrigger", "1.1", true); string serverMessage = JsonUtility.ToJson(testSignal); if (GUILayout.Button("Write to server", GUILayout.Height(30))) { Console.WriteLine(serverMessage); SendToServer(serverMessage); } } }
public void TriggerSignal(string lightID, int triggerID, bool triggerBool) { string type; if (triggerID == 1) { type = "PrimaryTrigger"; } else { type = "SecondaryTrigger"; } LightSignal newSignal = new LightSignal(type, lightID, triggerBool); string newSignalJSON = JsonUtility.ToJson(newSignal); SendToServer(newSignalJSON); }