private void Show() { BrainPad.Display.Clear(); while (BrainPad.Looping) { PrepareRound(); while (PlayRound()) { ; } BrainPad.LightBulb.TurnOff(); BrainPad.WriteDebugMessage("Round finished. Score: " + score); if (score > -2) { if (score > 0 && (score < bestScore || bestScore < 0)) { bestScore = score; bestPlayer = currentPlayer; } currentPlayer = (currentPlayer + 1) % players; } BrainPad.Display.DrawText(5, 85, "Left - Exit, Right - Next", BrainPad.Color.Red); while (BrainPad.Looping) { BrainPad.Wait.Milliseconds(100); if (BrainPad.Button.IsRightPressed()) { break; } if (BrainPad.Button.IsLeftPressed()) { if (PromptExit()) { DestroyActivity(); return; } else { break; } } } } }
/// <summary> /// Turn on a color. /// </summary> /// <param name="color">Red, Yellow or Green</param> public static void TurnOn(BrainPad.Color.Palette color) { switch (color) { case BrainPad.Color.Palette.Red: _ryg[0].DutyCycle = 1; _ryg[0].Start(); break; case BrainPad.Color.Palette.Yellow: _ryg[1].DutyCycle = 1; _ryg[1].Start(); break; case BrainPad.Color.Palette.Green: _ryg[2].DutyCycle = 1; _ryg[2].Start(); break; default: throw new Exception("color must be Red, Yellow or Green"); } }
/// <summary> /// Sets the brightness level of a color. /// </summary> /// <param name="color">The color to set.</param> /// <param name="level">Value between 0 and 1. Zero is off, 0.5 is half, one is full brightness.</param> public static void SetLevel(BrainPad.Color.Palette color, double level) { if (level < 0 | level > 1) throw new Exception("level must be a value between 0 and 1."); TurnOff(color); switch (color) { case BrainPad.Color.Palette.Red: _ryg[0].DutyCycle = level; _ryg[0].Start(); break; case BrainPad.Color.Palette.Yellow: _ryg[1].DutyCycle = level; _ryg[1].Start(); break; case BrainPad.Color.Palette.Green: _ryg[2].DutyCycle = level; _ryg[2].Start(); break; default: throw new Exception("color must be Red, Yellow or Green"); } }