/// <summary> /// display main program loop /// </summary> static void DisplayMainLoop(Generic_Display GD, Generic_Input GI, Generic_Alter GA) { //declare constants // int[,] NOSECOLORS = new int[4, 3] { { 0, 0, 0 }, { 255, 0, 0 }, { 0, 0, 255 }, { 0, 255, 0 } }; int[] SPEEDS = new int[4] { 0, 127, 191, 255 }; GD.DisplayNewScreen("Main App Loop"); //instantiate SuperTina // Finch superTina = InstantiateFinch(); FinchLevel superTinaLevel; Console.WriteLine("\nPlease enter the shield level for Super Tina (1-3)"); superTinaLevel = InputFinchLevelValid(); Console.WriteLine($"\nSuper Tinas shields are at {superTinaLevel} power level"); int[] SuperTinaNoseColor = new int[3]; SuperTinaNoseColor = GA.SpliceIntMultiArray(NOSECOLORS, (int)superTinaLevel, 3); int SuperTinaSpeed = SPEEDS[(int)superTinaLevel]; //declare variables // bool breakLoop = false; //activate SuperTina // Console.WriteLine("\nSuper Tina is ready for battle."); GD.DisplayAnyKey(); superTina.setMotors(SuperTinaSpeed, SuperTinaSpeed); superTina.setLED(SuperTinaNoseColor[0], SuperTinaNoseColor[1], SuperTinaNoseColor[2]); //main loop // while (!breakLoop) { breakLoop = DisplayActivateTim(superTina, NOSECOLORS, SPEEDS, superTinaLevel, GD, GI, GA); } superTina.disConnect(); }
static bool DisplayActivateTim(Finch superTina, int[,] NOSECOLORS, int[] SPEEDS, FinchLevel superTinaLevel, Generic_Display GD, Generic_Input GI, Generic_Alter GA) { double currentTemp, currentLight, ambientTemp, ambientLight, min, max; int[] levelArray = new int[3]; bool breaking = false; ambientTemp = superTina.getTemperature(); ambientLight = AverageLight(superTina); min = ambientTemp - 1; max = ambientLight + 3; Console.WriteLine($"Shields at {superTinaLevel} level."); while (!breaking) { currentTemp = superTina.getTemperature(); currentLight = AverageLight(superTina); superTina.wait(200); switch (superTinaLevel) { case FinchLevel.HIGH: if (currentTemp < min && currentLight > max) //freeze ray and lazer { superTinaLevel--; superTina.setMotors(SPEEDS[(int)superTinaLevel], SPEEDS[(int)superTinaLevel]); Hit(superTina, GA.SpliceIntMultiArray(NOSECOLORS, (int)superTinaLevel, 3)); Console.WriteLine($"Shield levels at {superTinaLevel}!\n"); } break; case FinchLevel.MEDIUM: if (currentLight > max) //just lazer { superTinaLevel--; superTina.setMotors(SPEEDS[(int)superTinaLevel], SPEEDS[(int)superTinaLevel]); Hit(superTina, GA.SpliceIntMultiArray(NOSECOLORS, (int)superTinaLevel, 3)); Console.WriteLine($"Shield levels at {superTinaLevel}!\n"); } break; case FinchLevel.LOW: if (currentTemp < min) //just freeze ray { superTinaLevel--; superTina.setMotors(SPEEDS[(int)superTinaLevel], SPEEDS[(int)superTinaLevel]); Hit(superTina, GA.SpliceIntMultiArray(NOSECOLORS, (int)superTinaLevel, 3)); Console.WriteLine($"Shield levels at {superTinaLevel}!\n"); } else if (currentLight > max) //just lazer { superTinaLevel--; superTina.setMotors(SPEEDS[(int)superTinaLevel], SPEEDS[(int)superTinaLevel]); Hit(superTina, GA.SpliceIntMultiArray(NOSECOLORS, (int)superTinaLevel, 3)); Console.WriteLine($"Shield levels at {superTinaLevel}!\n"); } break; case FinchLevel.EMPTY: breaking = true; break; default: break; } superTina.wait(200); } Console.WriteLine("SuperTina is dead. The world has been destroyed. All is lost, even hope."); GD.DisplayAnyKey(); return(breaking); }