Пример #1
0
        /// <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);
        }
Пример #2
0
        /// <summary>
        /// get the action choice from the user
        /// </summary>
        public TravelerAction DisplayGetTravelerActionChoice()
        {
            TravelerAction travelerActionChoice = TravelerAction.None;
            bool           usingMenu            = true;

            while (usingMenu)
            {
                //
                // set up display area
                //
                ConsoleUtil.HeaderText = "Traveler Action Choice";
                ConsoleUtil.DisplayReset();
                Console.CursorVisible = false;

                //
                // display the menu
                //
                ConsoleUtil.DisplayMessage("What would you like to do (Type Letter).");
                Console.WriteLine();
                Console.WriteLine(
                    "\t" + "**************************" + Environment.NewLine +
                    "\t" + "Traveler Actions" + Environment.NewLine +
                    "\t" + "**************************" + Environment.NewLine +
                    "\t" + "A. Look Around" + Environment.NewLine +
                    "\t" + "B. Look At" + Environment.NewLine +
                    "\t" + "C. Pick Up Item" + Environment.NewLine +
                    "\t" + "D. Pick Up Treasure" + Environment.NewLine +
                    "\t" + "E. Put Down Item" + Environment.NewLine +
                    "\t" + "F. Put Down Treasure" + Environment.NewLine +
                    "\t" + "G. Travel" + Environment.NewLine +
                    "\t" + Environment.NewLine +
                    "\t" + "**************************" + Environment.NewLine +
                    "\t" + "Traveler Information" + Environment.NewLine +
                    "\t" + "**************************" + Environment.NewLine +
                    "\t" + "H. Display General Traveler Info" + Environment.NewLine +
                    "\t" + "I. Display Traveler Inventory" + Environment.NewLine +
                    "\t" + "J. Display Traveler Treasure" + Environment.NewLine +
                    "\t" + Environment.NewLine +
                    "\t" + "**************************" + Environment.NewLine +
                    "\t" + "Game Information" + Environment.NewLine +
                    "\t" + "**************************" + Environment.NewLine +
                    "\t" + "K. Display All TARDIS Destinations" + Environment.NewLine +
                    "\t" + "L. Display All Game Items" + Environment.NewLine +
                    "\t" + "M. Display All Game Treasures" + Environment.NewLine +
                    "\t" + Environment.NewLine +
                    "\t" + "**************************" + Environment.NewLine +
                    "\t" + "Q. Quit" + Environment.NewLine);

                //
                // get and process the user's response
                // note: ReadKey argument set to "true" disables the echoing of the key press
                //
                ConsoleKeyInfo userResponse = Console.ReadKey(true);
                switch (userResponse.KeyChar)
                {
                case 'A':
                case 'a':
                    travelerActionChoice = TravelerAction.LookAround;
                    usingMenu            = false;
                    break;

                case 'B':
                case 'b':
                    travelerActionChoice = TravelerAction.LookAt;
                    usingMenu            = false;
                    break;

                case 'C':
                case 'c':
                    travelerActionChoice = TravelerAction.PickUpItem;
                    usingMenu            = false;
                    break;

                case 'D':
                case 'd':
                    travelerActionChoice = TravelerAction.PickUpTreasure;
                    usingMenu            = false;
                    break;

                case 'E':
                case 'e':
                    travelerActionChoice = TravelerAction.PutDownItem;
                    usingMenu            = false;
                    break;

                case 'F':
                case 'f':
                    travelerActionChoice = TravelerAction.PutDownTreasure;
                    usingMenu            = false;
                    break;

                case 'G':
                case 'g':
                    travelerActionChoice = TravelerAction.Travel;
                    usingMenu            = false;
                    break;

                case 'H':
                case 'h':
                    travelerActionChoice = TravelerAction.TravelerInfo;
                    usingMenu            = false;
                    break;

                case 'I':
                case 'i':
                    travelerActionChoice = TravelerAction.TravelerInventory;
                    usingMenu            = false;
                    break;

                case 'J':
                case 'j':
                    travelerActionChoice = TravelerAction.TravelerTreasure;
                    usingMenu            = false;
                    break;

                case 'K':
                case 'k':
                    travelerActionChoice = TravelerAction.ListTARDISDestinations;
                    usingMenu            = false;
                    break;

                case 'L':
                case 'l':
                    travelerActionChoice = TravelerAction.ListItems;
                    usingMenu            = false;
                    break;

                case 'M':
                case 'm':
                    travelerActionChoice = TravelerAction.ListTreasures;
                    usingMenu            = false;
                    break;

                case 'Q':
                case 'q':
                    travelerActionChoice = TravelerAction.Exit;
                    usingMenu            = false;
                    break;

                default:
                    Console.WriteLine(
                        "It appears you have selected an incorrect choice." + Environment.NewLine +
                        "Press any key to continue or the ESC key to quit the application.");

                    userResponse = Console.ReadKey(true);
                    if (userResponse.Key == ConsoleKey.Escape)
                    {
                        usingMenu = false;
                    }
                    break;
                }
            }
            Console.CursorVisible = true;

            return(travelerActionChoice);
        }
Пример #3
0
        /// <summary>
        /// method to manage the application setup and control loop
        /// </summary>
        private void ManageGameLoop()
        {
            PlayerAction travelerActionChoice;

            _gameConsoleView.DisplayWelcomeScreen();

            InitializeMission();

            //
            // game loop
            //
            while (_usingGame)
            {
                int health = _gamePlayer.Health;

                // get a menu choice from the ConsoleView object
                //
                travelerActionChoice = _gameConsoleView.DisplayGetPlayerActionChoice();
                if (health <= 0)
                {
                    ConsoleUtil.DisplayReset();
                    Console.WriteLine();
                    ConsoleUtil.DisplayMessage("The last goblin attack was too much for your level of health.");
                    ConsoleUtil.DisplayMessage("Game Over");
                    _gameConsoleView.DisplayContinuePrompt();
                    break;
                }
                //
                // choose an action based on the user's menu choice
                //
                switch (travelerActionChoice)
                {
                case PlayerAction.NONE:
                    break;

                case PlayerAction.BuyItem:
                    _gameConsoleView.BuyItem();
                    break;

                case PlayerAction.LookAround:
                    _gameConsoleView.DisplayLookAround();
                    break;

                case PlayerAction.LookAtItem:
                    _gameConsoleView.DisplayLookAtItems();
                    break;

                case PlayerAction.LookAtTreasure:
                    _gameConsoleView.DisplayLookAtTreasure();
                    break;

                case PlayerAction.PickUpItem:
                    _gameConsoleView.DisplayPickUpItem();
                    break;

                case PlayerAction.PickUpTreasure:
                    _gameConsoleView.DisplayPickUpTreasure();
                    break;

                case PlayerAction.PutDownItem:
                    _gameConsoleView.DisplayPutDownItem();
                    break;

                case PlayerAction.PutDownTreasure:
                    _gameConsoleView.DisplayPutDownTreasure();
                    break;

                case PlayerAction.Travel:
                    _gamePlayer.RoomID = _gameConsoleView.DisplayGetPlayersNewDestination().RoomID;
                    break;

                case PlayerAction.SpeakToNPC:
                    _gameConsoleView.DisplaySpeakToNPC();
                    break;

                case PlayerAction.PlayerInfo:
                    _gameConsoleView.DisplayTravelerInfo();
                    break;

                case PlayerAction.PlayerItems:
                    _gameConsoleView.DisplayPlayerItemInventory();
                    break;

                case PlayerAction.PlayerTreasure:
                    _gameConsoleView.DisplayPlayerTreasureInventory();
                    break;

                case PlayerAction.ListCastleRooms:
                    _gameConsoleView.DisplayListAllCastleRooms();
                    break;

                case PlayerAction.ListItems:
                    _gameConsoleView.DisplayListAllGameItems();
                    break;

                case PlayerAction.ListTreasures:
                    _gameConsoleView.DisplayListAllGameTreasures();
                    break;

                case PlayerAction.Exit:
                    _usingGame = false;
                    break;

                default:
                    break;
                }
            }

            _gameConsoleView.DisplayExitPrompt();

            //
            // close the application
            //
            Environment.Exit(1);
        }