예제 #1
0
        // Handles displaying a menu and most user choice inputs
        public void DisplayMenu()
        {
            // Reset control variables in each room and space text input appropriately
            int i = 1;

            Console.WriteLine(" ");

            // Write out reference text for all available actions in this location's action list
            foreach (KeyValuePair <string, Action> possibleAction in this.possibleActions)
            {
                Console.WriteLine(i + ". - " + possibleAction.Key);
                i++;
            }

            // Display curent room and inventory information below the primary text
            Console.SetCursorPosition(0, 20);
            Console.WriteLine("Current Room: " + this.GetName());
            Game.playerCharacter.DisplayInventory();


            input = Game.GetUserInput(0, possibleActions.Count());

            Console.Clear();

            // Execute the action function corresponding to players' choice
            // Position in list is players' chosen number -1 since element 0 is not given as an option to the player
            possibleActions[possibleActions.Keys.ElementAt(input - 1)]();
        }
예제 #2
0
        protected override void LookAround()
        {
            base.LookAround();
            if (crowbarHere)
            {
                Console.WriteLine("You see a crowbar lying against a far wall. Take it?");
                Console.WriteLine("1. - Take the crowbar");
                Console.WriteLine("2. - Leave the crowbar where it is");

                input = Game.GetUserInput(1, 2);

                if (input == 1)
                {
                    Crowbar crowbar = new Crowbar();
                    Game.playerCharacter.Inventory.Add(crowbar);
                    crowbarHere = false;
                    Console.Clear();
                    Console.WriteLine("You pick up the crowbar.");
                }
                else if (input == 2)
                {
                    Console.Clear();
                    Console.WriteLine("You decide to leave the crowbar for now.");
                }
            }
        }
예제 #3
0
        public void UseInventory()
        {
            int i = 1;

            if (Game.playerCharacter.Inventory.Count == 0)
            {
                Console.Clear();
                Console.WriteLine("You have nothing in your inventory.");
            }
            else
            {
                Console.WriteLine("1. Use an item");
                Console.WriteLine("2. Inspect an item");
                Console.WriteLine("3. Close inventory");

                int input = Game.GetUserInput(1, 3);

                if (input == 1)
                {
                    Console.Clear();
                    Console.WriteLine("Use which item?");
                    foreach (Item inventoryItem in Game.playerCharacter.Inventory)
                    {
                        Console.WriteLine(i + ". - " + inventoryItem.name);
                        input = Game.GetUserInput(1, Game.playerCharacter.Inventory.Count);

                        Console.Clear();

                        Game.playerCharacter.Inventory[input - 1].UseItem();
                    }
                }

                else if (input == 2)
                {
                    Console.WriteLine("Inspect which item?");
                    foreach (Item inventoryItem in Game.playerCharacter.Inventory)
                    {
                        Console.WriteLine(i + ". - " + inventoryItem.name);
                        input = Game.GetUserInput(1, Game.playerCharacter.Inventory.Count);

                        Console.Clear();

                        Console.WriteLine(Game.playerCharacter.Inventory[input - 1].GetDescription());
                    }
                }
                else
                {
                    Console.Clear();
                }
            }
        }
예제 #4
0
        // Base function to handle movement choices generically. Can be overriden if additional
        // functionality is required when moving out of a specific room
        protected void MoveToDifferentRoom()
        {
            // Get generic movement options from this locations NearbyRooms list and display them
            Console.WriteLine("Which room would you like to go to?");
            int           i           = 1;
            List <string> nearbyRooms = this.GetNearbyRooms();

            foreach (string room in nearbyRooms)
            {
                Console.WriteLine(i + ". - " + room);
                i++;
            }

            // Always last element; choice to remain in current location
            Console.WriteLine(i + ". - " + "Stay in " + this.name);

            // Loop until user inputs acceptable value
            input = Game.GetUserInput(0, nearbyRooms.Count + 1);

            // If remaining in current location, display appropriate message but do not change location
            if (input == nearbyRooms.Count + 1)
            {
                Console.Clear();
                Console.WriteLine("You are still in the " + this.name.ToLower() + ".");
            }

            // Change the static currentLocation variable in the main game loop to the
            // element corresponding to users choice in static list of all rooms, using
            // nearbyRooms list in current location to get the correct key
            else
            {
                Game.currentLocation = Game.roomsList[nearbyRooms[input - 1]];

                Console.Clear();
                Game.currentLocation.OnEnterRoom();
            }
        }