private static void ShowTarget(LightBoard lights, string id) { Console.WriteLine("Showing target " + id); lights.SetValue(GetChannelsForTarget(id), 0xFF); }
private static void SetGenaralColor(LightBoard lights, byte r, byte g, byte b) { Action<int> setFixture = (chan) => { lights[chan + 0] = 0; lights[chan + 1] = 255; lights[chan + 2] = 0; for (int i = 0; i < 4; ++i) { lights[chan + 3 + 3 * i] = r; lights[chan + 3 + 3 * i + 1] = g; lights[chan + 3 + 3 * i + 2] = b; } }; setFixture(278); setFixture(293); lights.SetValues(); }
private static void RecordHit(LightBoard lights, string id) { PlayAudio(@"..\..\..\NerfTargets\content\sounds\hit.wav"); var channels = GetChannelsForTarget(id); for (int i = 0; i < 3; ++i) { lights.SetValue(channels, 0x00); Thread.Sleep(100); lights.SetValue(channels, 0xFF); Thread.Sleep(100); } lights.SetValue(channels, 0x00); }
static void Main(string[] args) { HubConnection hubConnection; //if (Debugger.IsAttached) { // hubConnection = new HubConnection("http://localhost:11796/"); } // else { hubConnection = new HubConnection("http://nerf.azurewebsites.net/"); } IHubProxy targetProxy = hubConnection.CreateHubProxy("TargetHub"); hubConnection.Start(); using (var lights = new LightBoard()) { SetGenaralColor(lights, 0, 0, 0); //LevelEnd(lights, "2"); targetProxy.On<string>("ShowTarget", t => ShowTarget(lights, t)); targetProxy.On<string>("HideTarget", t => HideTarget(lights, t)); targetProxy.On<string, bool>("RecordHit", (t, success) => { if (success) RecordHit(lights, t); }); targetProxy.On<string>("LevelStart", t => LevelStart(lights, t)); targetProxy.On<string>("LevelEnd", t => LevelEnd(lights, t)); var allLights = Enumerable.Range(1, 10).Select(t => t.ToString()).ToList(); while (true) { var command = Console.ReadLine(); if (command == null) continue; if (command == "quit") break; if (command.StartsWith("hit")) { var id = command.Substring("hit".Length + 1); RecordHit(lights, id); } if (command.StartsWith("start")) { var id = command.Substring("start".Length + 1); LevelStart(lights, id); } if (command.StartsWith("end")) { var id = command.Substring("end".Length + 1); LevelStart(lights, id); } } } }
private static void LevelStart(LightBoard lights, string level) { PlayAudio(@"..\..\..\NerfTargets\content\voice\" + level + "intro.wav"); if (level == "part1") { SetGenaralColor(lights, 20, 20, 20); } else if (level == "part2") { SetGenaralColor(lights, 0, 0, 20); } }
private static void HideTarget(LightBoard lights, string id) { Console.WriteLine("Hiding target " + id); lights.SetValue(GetChannelsForTarget(id), 0x00); }