/// <summary> /// get a YearLocation object using an ID /// </summary> /// <param name="ID"> location ID</param> /// <returns>requested location</returns> public YearLocation GetYearTimeLocationByID(int ID) { YearLocation spt = null; // // run through the location list and grab the correct one // foreach (YearLocation location in YearLocations) { if (location.YearTimeLocationID == ID) { spt = location; } } // // the specified ID was not found in the universe // throw and exception // if (spt == null) { string feedbackMessage = $"The location ID {ID} does not exist."; throw new ArgumentException(ID.ToString(), feedbackMessage); } return(spt); }
/// <summary> /// get and validate the player's year destination /// </summary> /// <returns>space-time location</returns> public YearLocation DisplayGetTravelersNewDestination() { bool validResponse = false; int locationID; YearLocation nextYearTimeLocation = new YearLocation(); while (!validResponse) { // // display header // ConsoleUtil.HeaderText = "Year Destination"; ConsoleUtil.DisplayReset(); // // display a table of locations DisplayYearDestinationTable(); // // get and validate user's response for a location // ConsoleUtil.DisplayMessage(""); ConsoleUtil.DisplayPromptMessage("Choose the year destination by entering the ID: "); // // user's response is an integer // if (int.TryParse(Console.ReadLine(), out locationID)) { ConsoleUtil.DisplayMessage(""); try { nextYearTimeLocation = _gameYear.GetYearTimeLocationByID(locationID); ConsoleUtil.DisplayReset(); ConsoleUtil.DisplayMessage($"You have indicated {nextYearTimeLocation.Name} as your destination."); ConsoleUtil.DisplayMessage(""); if (nextYearTimeLocation.Accessable == true) { validResponse = true; ConsoleUtil.DisplayMessage("You have reached 88 miles per hour in the DeLorean. Were off to the Future!"); } else { ConsoleUtil.DisplayMessage("The Flux Capacitor is broke and you can't travel to this year at this time. This could have something to do with your inventory value"); ConsoleUtil.DisplayMessage(""); ConsoleUtil.DisplayMessage("Please make another choice."); } } // // user's response was not in the correct range // catch (ArgumentOutOfRangeException ex) { ConsoleUtil.DisplayMessage("It appears you entered an invalid year ID."); ConsoleUtil.DisplayMessage(ex.Message); ConsoleUtil.DisplayMessage("Please try again."); } } // // user's response was not an integer // else { ConsoleUtil.DisplayMessage("It appears you did not enter a number for the year ID."); ConsoleUtil.DisplayMessage(""); ConsoleUtil.DisplayMessage("Please try again."); } DisplayContinuePrompt(); } return(nextYearTimeLocation); }
/// <summary> /// get and validate the player's year destination /// </summary> /// <returns>-time location</returns> public YearLocation DisplayGetTravelersNewDestination() { bool validResponse = false; int locationID; YearLocation nextYearTimeLocation = new YearLocation(); while (!validResponse) { // // display header // ConsoleUtil.HeaderText = "Year Destination"; ConsoleUtil.DisplayReset(); // // display a table of locations DisplayYearDestinationTable(); // // get and validate user's response for a location // ConsoleUtil.DisplayMessage(""); ConsoleUtil.DisplayPromptMessage("Choose the year destination by entering the ID: "); // // user's response is an integer // if (int.TryParse(Console.ReadLine(), out locationID)) { ConsoleUtil.DisplayMessage(""); try { nextYearTimeLocation = _gameYear.GetYearTimeLocationByID(locationID); ConsoleUtil.DisplayReset(); ConsoleUtil.DisplayMessage($"You have indicated {nextYearTimeLocation.Name} as your destination."); ConsoleUtil.DisplayMessage(""); if (nextYearTimeLocation.Accessable == true) { validResponse = true; ConsoleUtil.DisplayMessage("You have reached 88 miles per hour in the DeLorean. Were off to the Future!"); var myplayer = new System.Media.SoundPlayer(); myplayer.SoundLocation = @"C:\Users\Jennifer\Documents\Visual Studio 2015\Projects\Back To The Future Game [sprint 3]\Project_TARDIS.S2_Starter\sound\workedgreat.wav"; myplayer.Play(); } else if (nextYearTimeLocation.Accessable == false) { ConsoleUtil.DisplayMessage("The Flux Capacitor is broke and you can't travel to this year at this time. This could have something to do with your inventory items"); ConsoleUtil.DisplayMessage(""); ConsoleUtil.DisplayMessage("Please make another choice."); var myplayer = new System.Media.SoundPlayer(); myplayer.SoundLocation = @"C:\Users\Jennifer\Documents\Visual Studio 2015\Projects\Back To The Future Game [sprint 3]\Project_TARDIS.S2_Starter\sound\wrongyear.wav"; myplayer.Play(); } else { } } // // user's response was not in the correct range // catch (ArgumentOutOfRangeException ex) { ConsoleUtil.DisplayMessage("It appears you entered an invalid year ID."); ConsoleUtil.DisplayMessage(ex.Message); ConsoleUtil.DisplayMessage("Please try again."); } } // // user's response was not an integer // else { ConsoleUtil.DisplayMessage("It appears you did not enter a number for the year ID."); ConsoleUtil.DisplayMessage(""); ConsoleUtil.DisplayMessage("Please try again."); } DisplayContinuePrompt(); } return(nextYearTimeLocation); }