/// <summary>
        /// get a treasure using an ID
        /// </summary>
        /// <param name="ID">game object ID</param>
        /// <returns>requested treasure object</returns>
        public Treasure GetTreasuretByID(int ID)
        {
            Treasure requestedTreasure = null;

            //
            // run through the item list and grab the correct one
            //
            foreach (Treasure treasure in Treasures)
            {
                if (treasure.GameObjectID == ID)
                {
                    requestedTreasure = treasure;
                }
                ;
            }

            //
            // the specified ID was not found in the kingdom
            // throw and exception
            //
            if (requestedTreasure == null)
            {
                string feedbackMessage = $"The treasure ID {ID} does not exist in the current Kingdom.";
                throw new ArgumentException(ID.ToString(), feedbackMessage);
            }

            return(requestedTreasure);
        }
Esempio n. 2
0
        /// <summary>
        /// Display look at object information
        /// </summary>
        /// <param name="gameObject"></param>
        /// <returns></returns>
        public static string LookAt(GameObject gameObject)
        {
            string messageBoxText = "";

            messageBoxText =
                $"{gameObject.Name}\n" +
                " \n" +
                gameObject.Description + " \n" +
                " \n";

            if (gameObject is Item)
            {
                Item item = gameObject as Item;

                messageBoxText += $"The {item.Name} has a value of {item.Value}.";
            }
            else if (gameObject is Treasure)
            {
                Treasure treasure = gameObject as Treasure;

                messageBoxText += $"The {treasure.Name} has a value of {treasure.Value}.";
            }
            else if (gameObject is Weapon)
            {
                Weapon weapon = gameObject as Weapon;

                messageBoxText += $"The {weapon.Name} has a value of {weapon.Value}.";
            }

            return(messageBoxText);
        }
        public void DisplayLookAt()
        {
            int             locationID      = _gameOgre.SwampLocationID;
            List <Item>     itemsInSwamp    = new List <Item>();
            List <Treasure> treasureInSwamp = new List <Treasure>();
            Item            itemToSee       = new Item();
            Treasure        treasureToSee   = new Treasure();

            itemsInSwamp    = _gameKingdom.GetItemsBySwampLocationID(locationID);
            treasureInSwamp = _gameKingdom.GetTreasuresBySwampLocationID(locationID);

            ConsoleUtil.HeaderText = "Items in Current Location";
            ConsoleUtil.DisplayReset();

            ConsoleUtil.DisplayMessage("");
            ConsoleUtil.DisplayMessage(_gameKingdom.GetSwampLocationByID(locationID).Name);
            ConsoleUtil.DisplayMessage("");

            if (itemsInSwamp != null)
            {
                ConsoleUtil.DisplayMessage("");
                ConsoleUtil.DisplayMessage("Items in Current location.");
                foreach (Item item in _gameKingdom.Items)
                {
                    if (item.SwampLocationID == locationID)
                    {
                        Console.WriteLine(item.GameObjectID + " - " + item.Name);
                        Console.WriteLine();
                    }
                }
                ConsoleUtil.DisplayPromptMessage("Enter item number or press Enter to move on to Treasures.");
                Console.WriteLine();
                int itemIDChoice;

                if (int.TryParse(Console.ReadLine(), out itemIDChoice))
                {
                    itemToSee = _gameKingdom.GetItemtByID(itemIDChoice);
                    ConsoleUtil.DisplayMessage(itemToSee.Description);

                    DisplayContinuePrompt();
                }
            }

            if (treasureInSwamp != null)
            {
                ConsoleUtil.DisplayMessage("");
                ConsoleUtil.DisplayMessage("Treasures in Current location.");
                foreach (Treasure treasure in _gameKingdom.Treasures)
                {
                    if (treasure.SwampLocationID == locationID)
                    {
                        Console.WriteLine(treasure.GameObjectID + " - " + treasure.Name);
                        Console.WriteLine();
                    }
                }
                ConsoleUtil.DisplayPromptMessage("Enter treasure number or press Enter to move on.");
                Console.WriteLine();
                int treasureIDChoice;

                if (int.TryParse(Console.ReadLine(), out treasureIDChoice))
                {
                    treasureToSee = _gameKingdom.GetTreasuretByID(treasureIDChoice);
                    ConsoleUtil.DisplayMessage(treasureToSee.Description);

                    DisplayContinuePrompt();
                }
            }
        }
        /// <summary>
        /// method to manage the application setup and control loop
        /// </summary>
        private void ManageGameLoop()
        {
            OgreAction ogreActionChoice = OgreAction.None;

            _gameConsoleView.DisplayWelcomeScreen();

            InitializeMission();

            //
            // game loop
            //
            while (_usingGame)
            {
                //not currently using the ogreActionChoice function
                UpdateGameStatus(ogreActionChoice);
                //
                // get a menu choice from the ConsoleView object
                //
                ogreActionChoice = _gameConsoleView.DisplayGetOgreActionChoice();

                //
                // choose an action based on the user's menu choice
                //
                switch (ogreActionChoice)
                {
                case OgreAction.None:
                    break;

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

                case OgreAction.TalkTo:
                    _gameConsoleView.DisplayTalkTo();
                    break;

                case OgreAction.LookAt:
                    _gameConsoleView.DisplayLookAt();
                    break;

                case OgreAction.PickUpItem:
                    int itemID;
                    itemID = _gameConsoleView.DisplayPickUpItem();

                    Item PickedUpItem = new Item();
                    PickedUpItem = _gameKingdom.GetItemtByID(itemID);

                    _gameOgre.OgresItems.Add(PickedUpItem);

                    PickedUpItem.SwampLocationID = 0;

                    break;

                case OgreAction.PickUpTreasure:
                    int treasureID = _gameConsoleView.DisplayPickUpTreasure();

                    Treasure PickedUpTreasure = new Treasure();
                    PickedUpTreasure = _gameKingdom.GetTreasuretByID(treasureID);

                    _gameOgre.OgresTreasures.Add(PickedUpTreasure);

                    PickedUpTreasure.SwampLocationID = 0;

                    break;

                case OgreAction.PutDownItem:
                    int itemToPutDown = _gameConsoleView.DisplayPutDownItem();

                    Item ItemToDrop = new Item();
                    ItemToDrop = _gameKingdom.GetItemtByID(itemToPutDown);

                    _gameOgre.OgresItems.Remove(ItemToDrop);

                    ItemToDrop.SwampLocationID = _gameOgre.SwampLocationID;

                    break;

                case OgreAction.PutDownTreasure:
                    int treasureToPutDown = _gameConsoleView.DisplayPutDownTreasure();

                    Treasure TreasureToDrop = new Treasure();
                    TreasureToDrop = _gameKingdom.GetTreasuretByID(treasureToPutDown);

                    _gameOgre.OgresTreasures.Remove(TreasureToDrop);

                    TreasureToDrop.SwampLocationID = _gameOgre.SwampLocationID;

                    break;

                case OgreAction.Travel:
                    _gameOgre.SwampLocationID = _gameConsoleView.DisplayGetOgresNewDestination().SwampLocationID;

                    break;

                case OgreAction.OgreInfo:
                    _gameConsoleView.DisplayOgreInfo();
                    break;

                case OgreAction.OgreInventory:
                    _gameConsoleView.DisplayOgreItems();
                    break;

                case OgreAction.OgreTreasure:
                    _gameConsoleView.DisplayOgreTreasure();
                    break;

                case OgreAction.ListSwampDestinations:
                    _gameConsoleView.DisplayListAllSwampDestinations();
                    break;

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

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

                case OgreAction.Exit:
                    _usingGame = false;
                    break;

                default:
                    break;
                }
            }

            _gameConsoleView.DisplayExitPrompt();

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