/// <summary> /// Takes the difficulty selected by the player and assigns values for use in other Finch operations based on that difficulty. /// </summary> /// <param name="difficulty"></param> /// <returns></returns> static FinchOperator DifficultySettings(FinchOperator myFinchOperator) { // Sets certain values depending on the selected difficulty. The default is NORMAL. switch (myFinchOperator.DifficultySetting) { case Difficulty.MERCIFUL: myFinchOperator.vulnerabilityDuration = 6000; myFinchOperator.MotorSpeed = 100; myFinchOperator.HitPoints = 1; myFinchOperator.TimeAvailable = 60; myFinchOperator.ScoreModifier = 5; break; case Difficulty.NORMAL: myFinchOperator.vulnerabilityDuration = 5000; myFinchOperator.MotorSpeed = 175; myFinchOperator.HitPoints = 3; myFinchOperator.TimeAvailable = 120; myFinchOperator.ScoreModifier = 10; break; case Difficulty.RUTHLESS: myFinchOperator.vulnerabilityDuration = 4000; myFinchOperator.MotorSpeed = 255; myFinchOperator.HitPoints = 5; myFinchOperator.TimeAvailable = 120; myFinchOperator.ScoreModifier = 20; break; default: break; } return(myFinchOperator); }
/// <summary> /// Controls whether the Finch can be hurt or not and gives the user a prompt if they have scored a hit. /// </summary> static void DisplayVulnerbilityStatus(Finch myFinch, Monitor hitTracker, FinchOperator myFinchOperator) { // Checks for hits upon entering the method: hitTracker.IsHit = Monitor.HitDetection(myFinch); hitTracker.IsFrozen = Monitor.FreezeDetection(myFinch); // Statment to indicate a hit while shields are up. if (hitTracker.IsHit == true && hitTracker.IsFrozen == false) { Console.WriteLine(); Console.WriteLine("\tThe blast is deflected! You need to freeze him first."); FinchOperator.LEDSettings(myFinch, myFinchOperator); myFinch.wait(1000); } // Statment to indicate a hit while shields are down. if (hitTracker.IsFrozen == true) { Console.WriteLine(); Console.WriteLine("\tThat got him! Strike now while he is stunned!"); // Sets the finch to vulnerable so it can take hits: myFinchOperator.IsVulnerable = true; // Turns off the LED to indicate shields are down. FinchOperator.LEDSettings(myFinch, myFinchOperator); // Enters this method to determine if a hit is suffered or not. ShieldsDown(myFinch, hitTracker, myFinchOperator); } }
/// <summary> /// Processes menu selection for DisplaySetupMenu /// </summary> /// <param name="menuChoice"></param> /// <param name="myFinch"></param> /// <param name="myFinchOperator"></param> static bool SettingsSwitchBoard(string menuChoice, Finch myFinch, FinchOperator myFinchOperator) { // local variables: bool returnToPrevious = false; switch (menuChoice.ToUpper()) { case "1": FinchOperator.EstablishFinchConnection(myFinch); break; case "2": GetDifficultySetting(myFinchOperator); DifficultySettings(myFinchOperator); break; case "3": DisplayWelcomeScreen(); break; case "M": returnToPrevious = true; break; default: Console.WriteLine("'{0}' is not a valid input. Please try again!", menuChoice); DisplayContinuePrompt(); Console.Clear(); break; } return(returnToPrevious); }
/// <summary> /// Gets the desired difficulty from the user. /// </summary> /// <param name="userName"></param> /// <returns></returns> static void GetDifficultySetting(FinchOperator myFinchOperator) { // Local Variables: Difficulty difficulty; DisplayHeader("DARTH FINCH: SELECT DIFFICULTY"); Console.WriteLine(); foreach (var setting in Enum.GetValues(typeof(Difficulty))) { Console.WriteLine("\t" + setting); } Console.WriteLine(); Console.Write("\tSelect Difficulty -> "); while (!Enum.TryParse(Console.ReadLine().ToUpper(), out difficulty)) { Console.WriteLine("\tThat is not a valid difficulty level. Please try again!"); DisplayContinuePrompt(); } myFinchOperator.DifficultySetting = difficulty; Console.WriteLine(); Console.WriteLine("\tYou selected " + $"{myFinchOperator.DifficultySetting}"); DisplayContinuePrompt(); }
/// <summary> /// Setup menu: Allows the user to access Finch connection and difficulty settings. /// </summary> /// <param name="userName"></param> /// <param name="myFinch"></param> /// <param name="myFinchOperator"></param> static void DisplaySetupMenu(string userName, Finch myFinch, FinchOperator myFinchOperator) { // Local Variables: string menuChoice; bool returnToPrevious = false; while (!returnToPrevious) { DisplayHeader("SET UP"); //Display Menu: DisplaySpacer(); Console.WriteLine("\t1.) [Connect to Finch Robot]"); Console.WriteLine("\t2.) [Select Difficulty]"); Console.WriteLine("\t3.) [Change Player Name]"); Console.WriteLine("\tM) Return to Main Menu"); DisplaySpacer(); Console.Write("\tInput -> "); menuChoice = Console.ReadLine(); // Processes menu selection: returnToPrevious = SettingsSwitchBoard(menuChoice, myFinch, myFinchOperator); } }
/// <summary> /// Displays the main menu: Main application screen. /// </summary> /// <param name="userName"></param> /// <param name="myFinch"></param> /// <param name="myFinchOperator"></param> /// <returns></returns> static bool DisplayMainMenu(string userName, Finch myFinch, FinchOperator myFinchOperator) { // Local Variables: bool runApp; string menuChoice; DisplayHeader("DARTH FINCH"); //Display Menu: DisplaySpacer(); Console.WriteLine("\t1.) [PLAY!]"); Console.WriteLine("\t2.) [How to play]"); Console.WriteLine("\t3.) [Setup]"); Console.WriteLine("\t4.) [Save Score]"); Console.WriteLine("\t5.) [Load Scores]"); Console.WriteLine("\t6.) [The Imperial March]"); Console.WriteLine(); Console.WriteLine("\tE) Exit Game"); DisplaySpacer(); Console.Write("\tInput -> "); menuChoice = Console.ReadLine(); // Processes menu selection: runApp = MenuSwitchBoard(userName, menuChoice, myFinch, myFinchOperator); return(runApp); }
static void Main(string[] args) { // Local Variables: Finch myFinch = new Finch(); FinchOperator myFinchOperator = new FinchOperator(); myFinchOperator.DifficultySetting = Difficulty.NORMAL; bool runApp = true; string userName; // Setting up the console: Console.ForegroundColor = ConsoleColor.Red; Console.BackgroundColor = ConsoleColor.Black; Console.Clear(); // Connecting to Finch to make debugging easier: // myFinch.connect(); // Welcome Screen: userName = DisplayWelcomeScreen(); // while (runApp) { runApp = DisplayMainMenu(userName, myFinch, myFinchOperator); } DisplayClosingScreen(userName, myFinch); }
/* MotorSettings: Unfinished Component. Needs more time for testing. * /// <summary> * /// Sets motor behavior for the Finch. * /// </summary> * /// <param name="myFinch"></param> * /// <param name="difficulty"></param> * /// <param name="myFinchOperator"></param> * /// <param name="isDefeated"></param> * public static void MotorSettings(Finch myFinch, FinchOperator myFinchOperator) * { * switch (myFinchOperator.DifficultySetting) * { * case Difficulty.MERCIFUL: * * myFinch.setMotors(myFinchOperator.MotorSpeed, myFinchOperator.MotorSpeed); * myFinch.wait(4000); * myFinch.setMotors(myFinchOperator.MotorSpeed, myFinchOperator.MotorSpeed * -1); * myFinch.wait(1000); * break; * case Difficulty.NORMAL: * * myFinch.setMotors(myFinchOperator.MotorSpeed, myFinchOperator.MotorSpeed); * myFinch.wait(1000); * myFinch.setMotors(myFinchOperator.MotorSpeed, myFinchOperator.MotorSpeed * -1); * myFinch.wait(500); * * break; * case Difficulty.RUTHLESS: * Random ruthless = new Random(); * myFinch.setMotors(myFinchOperator.MotorSpeed, myFinchOperator.MotorSpeed); * myFinch.wait(ruthless.Next() * 100); * myFinch.setMotors(myFinchOperator.MotorSpeed, myFinchOperator.MotorSpeed * -1); * myFinch.wait(ruthless.Next() * 100); * break; * default: * myFinch.setMotors(0, 0); * break; * } * * myFinch.setMotors(myFinchOperator.MotorSpeed, myFinchOperator.MotorSpeed); * * } */ /// <summary> /// Turns the Finch's light on to indicate it is immune to damage (the light saber is active) and turns it off while vulnerable (saber is off). /// </summary> /// <param name="myFinch"></param> /// <param name="isVulnerable"></param> public static void LEDSettings(Finch myFinch, FinchOperator myFinchOperator) { if (myFinchOperator.IsVulnerable == true) { myFinch.setLED(0, 0, 0); } else { myFinch.setLED(255, 0, 0); } }
/// <summary> /// Screen that runs the gameplay: /// </summary> /// <param name="myFinch"></param> /// <param name="myFinchOperator"></param> /// <param name="difficulty"></param> static void DisplayGameInProgress(Finch myFinch, FinchOperator myFinchOperator) { // Instantiates a new hit tracker: Monitor hitTracker = new Monitor(); int timeInLoop = 0; //Variables: myFinchOperator.isDefeated = false; // Resets Finch Operator to default hitpoints. myFinchOperator.HitsSuffered = 0; DisplayHeader("DARTH FINCH"); Console.WriteLine(); Console.WriteLine("\t\tInitializing..."); // Just in case the user attempts to run the game without a Finch - it doesn't crash, but it doesn't make sense either. if (!myFinch.connect()) { DisplayHeader("DARTH FINCH"); Console.WriteLine("\tNo finch detected. Please connect a Finch before proceeding!"); DisplayContinuePrompt(); FinchOperator.EstablishFinchConnection(myFinch); } // Little indicator that the game has begun: FinchOperator.PlayImpMarchShort(myFinch); // Main Gameplay Loop: while (!myFinchOperator.isDefeated && timeInLoop <= myFinchOperator.TimeAvailable) { DisplayHeader("DARTH FINCH:"); Console.WriteLine("\tDarth Finch is active!"); Console.WriteLine("\tTime Remaining:" + $"[{myFinchOperator.TimeAvailable - timeInLoop}]"); DisplayHealthStatus(myFinchOperator); //hitTracker.IsFrozen = Monitor.FreezeDetection(myFinch); //hitTracker.IsHit = Monitor.HitDetection(myFinch); DisplayVulnerbilityStatus(myFinch, hitTracker, myFinchOperator); myFinch.wait(500); myFinchOperator.isDefeated = CheckHealth(myFinchOperator); FinchOperator.LEDSettings(myFinch, myFinchOperator); // FinchOperator.MotorSettings(myFinch, myFinchOperator); Disabling this for the time being. myFinch.wait(500); timeInLoop++; } }
/// <summary> /// Game Over Screen: /// </summary> /// <param name="currentScore"></param> static void DisplayGameOver(PlayerScoreTracker currentScore, Finch myFinch) { DisplayHeader("GAME OVER"); // Displays the player's score. DisplayPlayerScore(currentScore); // Bit of a musical blurb for the user. FinchOperator.PlayGameOverMarch(myFinch); DisplayContinuePrompt(); }
/// <summary> /// Processes menu selection for DisplayMainMenu. /// </summary> /// <param name="userName"></param> /// <param name="menuChoice"></param> /// <returns></returns> static bool MenuSwitchBoard(string userName, string menuChoice, Finch myFinch, FinchOperator myFinchOperator) { //Local Variables: Monitor saberHit = new Monitor(); bool runApp = true; PlayerScoreTracker playerScore = new PlayerScoreTracker(); playerScore.PlayerName = userName; switch (menuChoice.ToUpper()) { case "1": DisplayGameInProgress(myFinch, myFinchOperator); playerScore = CurrentPlayerScore(userName, playerScore, myFinchOperator); DisplayGameOver(playerScore, myFinch); break; case "2": DisplayInformationScreen(userName); break; case "3": DisplaySetupMenu(userName, myFinch, myFinchOperator); break; case "4": DisplaySavePlayerScoreToFile(playerScore); break; case "5": DisplayReadScoreFromFile(); break; case "6": FinchOperator.PlayImpMarch(myFinch); DisplayHeader("END OF SONG"); DisplayContinuePrompt(); break; case "E": runApp = false; break; default: Console.WriteLine("\t'{0}' is not a valid input. Please try again!", menuChoice); DisplayContinuePrompt(); Console.Clear(); break; } return(runApp); }
/// <summary> /// Checks health against hitpoints and returns a bool to desginate the Finch is defeated. /// </summary> /// <param name="myFinchOperator"></param> /// <returns></returns> static bool CheckHealth(FinchOperator myFinchOperator) { bool isDefeated = false; if (myFinchOperator.HitsSuffered >= myFinchOperator.HitPoints) { isDefeated = true; Console.WriteLine("\tDarth Finch has been defeated!"); } return(isDefeated); }
/// <summary> /// Method that controls hits while shields are down. /// </summary> /// <param name="myFinch"></param> /// <param name="hitTracker"></param> /// <param name="myFinchOperator"></param> static void ShieldsDown(Finch myFinch, Monitor hitTracker, FinchOperator myFinchOperator) { myFinch.wait(myFinchOperator.vulnerabilityDuration); hitTracker.IsHit = Monitor.HitDetection(myFinch); if (hitTracker.IsHit == true) { Console.WriteLine(); Console.WriteLine("\tNice hit! He'll feel that for sure."); myFinchOperator.HitsSuffered += 1; myFinch.wait(500); } else { Console.WriteLine(); Console.WriteLine("\tThe moment to strike has passed. Try again!"); myFinch.wait(500); } myFinchOperator.IsVulnerable = false; FinchOperator.LEDSettings(myFinch, myFinchOperator); }
/// <summary> /// Plays the Imperial March on the finch. WARNING: VERY LONG CODE BLOCK - CLOSE WHEN NOT IN USE /// </summary> /// <param name="myFinch"></param> public static void PlayImpMarch(Finch myFinch) { // Just in case the user attempts to run the game without a Finch - it doesn't crash, but it doesn't make sense either. if (!myFinch.connect()) { DisplayHeader("DARTH FINCH"); Console.WriteLine("\tNo finch detected. Please connect a Finch before proceeding!"); DisplayContinuePrompt(); FinchOperator.EstablishFinchConnection(myFinch); } DisplayHeader("DARTH FINCH"); Console.WriteLine("\tDarth Finch is amused by your request, but is willing to humor you."); Console.WriteLine("\t(Please allow the Finch to finish, you will see a continue prompt when it is done)"); // Source for notes: http://llrprt.blogspot.com/2013/11/programming-imperial-march.htmlhttp://llrprt.blogspot.com/2013/11/programming-imperial-march.html myFinch.wait(1000); myFinch.noteOn(440); myFinch.wait(500); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(440); myFinch.wait(500); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(440); myFinch.wait(500); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(349); myFinch.wait(350); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(523); myFinch.wait(150); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(440); myFinch.wait(500); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(349); myFinch.wait(350); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(523); myFinch.wait(150); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(440); myFinch.wait(1000); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(659); myFinch.wait(500); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(659); myFinch.wait(500); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(659); myFinch.wait(500); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(698); myFinch.wait(350); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(523); myFinch.wait(150); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(415); myFinch.wait(500); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(349); myFinch.wait(350); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(523); myFinch.wait(150); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(440); myFinch.wait(1000); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(800); myFinch.wait(500); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(440); myFinch.wait(350); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(440); myFinch.wait(150); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(880); myFinch.wait(500); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(830); myFinch.wait(250); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(784); myFinch.wait(250); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(740); myFinch.wait(125); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(698); myFinch.wait(125); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(740); myFinch.wait(250); myFinch.noteOff(); myFinch.wait(250); myFinch.noteOn(455); myFinch.wait(250); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(622); myFinch.wait(500); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(587); myFinch.wait(250); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(554); myFinch.wait(250); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(523); myFinch.wait(125); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(466); // I wasn't kidding when I said this was long. myFinch.wait(125); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(523); myFinch.wait(250); myFinch.noteOff(); myFinch.wait(250); myFinch.noteOn(349); myFinch.wait(125); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(415); myFinch.wait(500); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(349); myFinch.wait(375); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(440); myFinch.wait(125); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(523); myFinch.wait(500); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(440); myFinch.wait(375); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(523); myFinch.wait(125); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(659); myFinch.wait(1000); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(880); myFinch.wait(500); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(440); myFinch.wait(350); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(440); myFinch.wait(150); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(880); myFinch.wait(500); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(830); myFinch.wait(250); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(784); myFinch.wait(250); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(740); myFinch.wait(125); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(698); myFinch.wait(125); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(740); myFinch.wait(250); myFinch.noteOff(); myFinch.wait(250); myFinch.noteOn(455); myFinch.wait(250); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(622); myFinch.wait(500); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(587); myFinch.wait(250); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(554); myFinch.wait(250); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(523); myFinch.wait(125); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(466); myFinch.wait(125); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(523); myFinch.wait(250); myFinch.noteOff(); myFinch.wait(250); myFinch.noteOn(349); myFinch.wait(250); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(415); myFinch.wait(500); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(349); myFinch.wait(375); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(261); myFinch.wait(125); myFinch.noteOff(); myFinch.wait(10); myFinch.noteOn(475); myFinch.wait(1000); myFinch.noteOff(); myFinch.wait(100); }
/// <summary> /// Keeps track of the current player score and updates the player's score. /// </summary> /// <param name="currentScore"></param> /// <returns></returns> static PlayerScoreTracker CurrentPlayerScore(string userName, PlayerScoreTracker playerScore, FinchOperator myFinchOperator) { playerScore.PlayerScore = myFinchOperator.HitsSuffered * myFinchOperator.ScoreModifier; playerScore.PlayerName = userName; return(playerScore); }
/// <summary> /// Displays current health and how many hits have been sustained. /// </summary> /// <param name="myFinchOperator"></param> static void DisplayHealthStatus(FinchOperator myFinchOperator) { Console.Write("\tCurrent Hitpoints: " + $"{myFinchOperator.HitPoints - myFinchOperator.HitsSuffered}"); }