Exemple #1
0
        public void DisplayLocationItems()
        {
            if (CurrentPlayer.CurrentLocation.Items.Count > 0)
            {
                int index = 1;
                WriteLine("There are items on the ground.");
                foreach (var Item in CurrentPlayer.CurrentLocation.Items)
                {
                    WriteLine($"{index++}: {Item.Name} - {Item.Description}");
                }

                int    userChoice = 0;
                string userInput  = Utility.GetUserInput("What would you like to pick up?");
                int.TryParse(userInput, out userChoice);
                if (userChoice > 0 && userChoice <= CurrentPlayer.CurrentLocation.Items.Count)
                {
                    userChoice--;
                    Item PickedUp = CurrentPlayer.CurrentLocation.Items[userChoice];
                    CurrentPlayer.CollectItem(PickedUp);
                    CurrentPlayer.CurrentLocation.Items.Remove(PickedUp);
                }

                else
                {
                    WriteLine("That item doesn't exist.");
                }
            }

            else
            {
                WriteLine("There are no more items here.");
            }
        }
        //this method shows the items available for collection at any location in the game.
        public void DisplayLocationItems()
        {
            //if the location still has the item that the player is trying to pick up, then they are displayed to the player with this method.
            if (CurrentPlayer.CurrentLocation.Items.Count > 0)
            {
                int index = 1;
                WriteLine($"There are some items laying around.");
                //this tells the player which items are in their current location
                foreach (var Item in CurrentPlayer.CurrentLocation.Items)
                {
                    WriteLine($"{index++}: {Item.Name} \n{Item.Description}");
                }

                //the player then chooses an item to pick up.
                int    userChoice = 0;
                string userInput  = Utility.GetUserInput("Which item would you like to pick up?");
                int.TryParse(userInput, out userChoice);
                if (userChoice > 0 && userChoice <= CurrentPlayer.CurrentLocation.Items.Count)
                {
                    userChoice--;
                    Item PickedUpItem = CurrentPlayer.CurrentLocation.Items[userChoice];
                    CurrentPlayer.CollectItem(PickedUpItem);
                    CurrentPlayer.CurrentLocation.Items.Remove(PickedUpItem);
                }
                //this runs if the player inputs a number that is not applicable
                else
                {
                    WriteLine("That is not an available item");
                }
            }
            //this runs if the player has already picked up the item located here.
            else
            {
                WriteLine("There are no more items here.");
            }
        }