/// <summary> /// get a SpaceTimeLocation object using an ID /// </summary> /// <param name="ID">space-time location ID</param> /// <returns>requested space-time location</returns> public SpaceTimeLocation GetSpaceTimeLocationByID(int ID) { SpaceTimeLocation spt = new SpaceTimeLocation(); // // run through the space-time location list and grab the correct one // foreach (SpaceTimeLocation location in SpaceTimeLocations) { if (location.SpaceTimeLocationID == ID) { spt = location; } } // // the specified ID was not found in the universe // throw and exception // if (spt == null) { string feedbackMessage = $"The Space-Time Location ID {ID} does not exist in the current Universe."; throw new ArgumentException(ID.ToString(), feedbackMessage); } return(spt); }
/// <summary> /// get and validate the player's TARDIS destination /// </summary> /// <returns>Space-Time Location object</returns> public SpaceTimeLocation DisplayGetTravelersNewDestination() { bool validResponse = false; int locationID; SpaceTimeLocation nextSpaceTimeLocation = new SpaceTimeLocation(); while (!validResponse) { // // display header // ConsoleUtil.HeaderText = "TARDIS Destination"; ConsoleUtil.DisplayReset(); // // display a table of space-time locations // DisplayTARDISDestinationsTable(); // // get and validate user's response for a space-time location // // // validate user's response for integer // if (int.TryParse(Console.ReadLine(), out locationID)) { ConsoleUtil.DisplayMessage(""); // // validate user's response for range and accessible // try { } // // user's response was not in the correct range // catch (ArgumentOutOfRangeException ex) { } } // // user's response was not an integer // else { } DisplayContinuePrompt(); } return(nextSpaceTimeLocation); }
/// <summary> /// get and validate the player's TARDIS destination /// </summary> /// <returns>space-time location</returns> public SpaceTimeLocation DisplayGetTravelersNewDestination() { bool validResponse = false; int locationID; SpaceTimeLocation nextSpaceTimeLocation = new SpaceTimeLocation(); while (!validResponse) { // // display header // ConsoleUtil.HeaderText = "TARDIS Destination"; ConsoleUtil.DisplayReset(); // // display a table of space-time locations // DisplayTARDISDestinationsTable(); // // get and validate user's response for a space-time location // ConsoleUtil.DisplayPromptMessage("Choose the TARDIS destination by entering the ID: "); // // user's response is an integer // if (int.TryParse(Console.ReadLine(), out locationID)) { ConsoleUtil.DisplayMessage(""); try { nextSpaceTimeLocation = _gameUniverse.GetSpaceTimeLocationByID(locationID); ConsoleUtil.DisplayReset(); ConsoleUtil.DisplayMessage($"You have indicated {nextSpaceTimeLocation.Name} as your TARDIS destination."); ConsoleUtil.DisplayMessage(""); if (nextSpaceTimeLocation.Accessable == true) { validResponse = true; ConsoleUtil.DisplayMessage("You will be transported immediately."); } else { ConsoleUtil.DisplayMessage("It appears this destination is not available to you at this time."); 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 location 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 location ID."); ConsoleUtil.DisplayMessage("Please try again."); } DisplayContinuePrompt(); } return(nextSpaceTimeLocation); }