예제 #1
0
        public YearLocation GetYearLocationByID(int ID)
        {
            YearLocation spl = null;

            // cycle through year locations and return selected

            foreach (YearLocation location in YearLocations)
            {
                if (location.YearLocationID == ID)
                {
                    spl = location;
                }
            }
            // ID was not found in the Future
            if (spl == null)
            {
                ConsoleUtil.DisplayMessage($" The Year Location ID {ID} does not exist in the Future.");
            }
            return(spl);
        }
예제 #2
0
        /// <summary>
        /// get and validate the player's Year destination
        /// </summary>
        /// <returns>Space-Time Location object</returns>
        public YearLocation DisplayGetTravelersNewYear()
        {
            bool         validResponse = false;
            int          locationID;
            YearLocation nextYearTimeLocation = new YearLocation();

            while (!validResponse)
            {
                //
                // display header
                //
                ConsoleUtil.HeaderText = " Initialize Time Traveler Year Location";
                ConsoleUtil.DisplayReset();

                //
                // display a table of year locations
                //
                DisplayYearDestinationsTable();

                //
                // get and validate user's response for a year location
                //
                ConsoleUtil.DisplayPromptMessage("Choose the Year you want to travel to by entering the ID number: ");

                //
                // validate user's response for integer
                //
                if (int.TryParse(Console.ReadLine(), out locationID))
                {
                    ConsoleUtil.DisplayMessage("");

                    //
                    // validate user's response for range and accessible
                    //
                    try
                    {
                        nextYearTimeLocation = _gameFuture.GetYearLocationByID(locationID);

                        ConsoleUtil.DisplayReset();
                        ConsoleUtil.DisplayMessage($"You have indicated {nextYearTimeLocation.Year} as the year.");
                        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.");
                            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("Please try again.");
                }

                DisplayContinuePrompt();
            }

            return(nextYearTimeLocation);
        }