// Method to handle traffic light color changes private void readLights(Packet packet) { int ID = packet.ReadInt(); string color = packet.ReadString(); TrafficLight[] lights = this.trafficPanel.GetAllTiles().Where(tile => tile.GetType() == typeof(TrafficLight)).Cast <TrafficLight>().ToArray(); TrafficLight light = lights.Where(l => l.ID == ID).ToArray()[0]; light.ChangeColour(ColorTranslator.FromHtml(color), this.trafficPanel); }
/// <summary> /// Changes individual light and synced lights to specific colour and sends through proxy to clients /// </summary> /// <param name="colour"></param> /// <param name="light"></param> private static void changeLight(Color colour, TrafficLight light) { light.ChangeColour(colour, Form1.MainForm.trafficPanel); sendLightChange(light); TrafficLight[] lightsSynced = trafficLights.Where((x) => light.GetSyncedLights().Contains(x.ID)).ToArray(); foreach (TrafficLight l in lightsSynced) { l.ChangeColour(colour, Form1.MainForm.trafficPanel); sendLightChange(l); } }