Esempio n. 1
0
        /*
         * DISPLAY ROOM INFORMATION TO USER.  Clears screen each time this method is called.
         */
        public void ShowRoomInfo(RoomLocation currentRoom)
        {
            Console.Clear();
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine($"{dl} {currentRoom.Name}");
            Console.ResetColor();

            //Describe Room Location:
            var formattedRoomDescription = MisersHouseMain.FormatTextWidth(MisersHouseMain.maxColumns,
                                                                           currentRoom.DescriptionShort + "  " + currentRoom.Description);

            Console.WriteLine($"{sl}{formattedRoomDescription}");

            //Display any special object/room interactions or events:
            List <GameItem> roomItems = GameItem.GetRoomItems(MisersHouseMain.playerLocation);

            foreach (GameItem item in roomItems)
            {
                if (currentRoom.ItemRoomEvents.TryGetValue(item.ItemId, out string eventDescription))
                {
                    if (item.State.Equals(GameItem.ObjectState.VISIBLE))
                    {
                        Console.WriteLine(MisersHouseMain.FormatTextWidth(MisersHouseMain.maxColumns, eventDescription));
                    }
                }
            }

            //Describe any objects in the current room:
            foreach (GameItem item in roomItems)
            {
                if (item.State >= GameItem.ObjectState.VISIBLE)
                {
                    Console.WriteLine($" There is a {item.Name} here.");
                }
            }

            //Display specialized descriptions:
            string specialText = buildSpecialDescriptions(roomItems);

            if (specialText.Length > 0)
            {
                Console.WriteLine($" {specialText}");
            }

            //Disclose Available Directions:
            Console.WriteLine($"\n Obvious Exits: {BuildCompassDirections(currentRoom.LocationMap)}");
        }
        private static string ql     = "\n\n\n\n"; //quadline


        /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         *  TODO: Implement a chronometer into the game. :-)  In other words, track the passage of time.
         *        Perhaps something simple, such as one minute for each move, and display a digital clock
         *        readout above, when the room screen refresh occurs.   Time :   3:43 pm  (or even just the time)
         *
         *        So, there are two types of time passage I am thinking about:
         *          1.) The game is ALWAYS turn-based.  In other words, time only passes when a command
         *              is actually entered by the player.  Otherwise, time stands still.
         *
         *          2.) Game's Global time:  For every move, time passes.  This allows us to display
         *              general, time-related events, such as "a full moon shines its rays through the window."
         *              And global events can happen in the game.  "The chiming of a great clock can be heard!"
         *
         *          3.) Also, specific passage of time can be captured in relation to a room or location.
         *              Time is captured when entering the room, and something will happen if the player
         *              doesn't respond within 'n' number of moves.
         *
         *        Since a great deal of exploration by the player occurs in teh game, it would lose a
         *        significant element of fun if EVERYTHING in the game was time-based move to move!
         *
         *        NOTE:  These are things to think about... I have far more to get working first, before implementing this!
         * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         */

        static void Main(string[] args)
        {
            //Add inventory items:
            Inventory.InitializeInventory();

            Console.CursorSize = 100;


            // ----------------------------------------------------------------------------------------------------
            //TODO:  In order to call non-static methods, I must move them out of the Main class
            //       Then in order to call them, I must create an instance of the class.
            //       At first I will do it within this class (i.e. "Program"), but they should be
            //       moved out eventually into separate classes.  Then I can re-use them in other text adventures.
            // ----------------------------------------------------------------------------------------------------

            var misersHouse = new MisersHouseMain();

            misersHouse.DisplayGameIntro();

            //Instantiate RoomLocation class and populate actual Room Data:
            var roomLocationClass = new RoomLocation();

            roomLocations = roomLocationClass.GenerateRoomData();
            roomLocationClass.PopulateItemRoomEvents();

            //GameItems is a static object arry of items used throughout the game:
            //var gameItem = new GameItem();
            //gameItems = GameItem.GenerateGameObjectData();


            //gameIsActive = 1;

            //Need to keep the game in a loop until it is ready to end.  Primative, but it works
            while (gameIsActive > 0)
            {
                //Display Room data.
                roomLocationClass.ShowRoomInfo(roomLocations[MisersHouseMain.playerLocation]);

                //Generate current room object list:
                List <GameItem> roomItems = GameItem.GetRoomItems(MisersHouseMain.playerLocation);

                bool refreshRoom = false;
                while (!refreshRoom)
                {
                    //refreshRoom = false;

                    //Get Player Input:
                    Console.Write($"{sl}   ? ");
                    misersHouse.playerInput = Console.ReadLine().ToUpper();

                    //Player entered something... time to analyze!
                    refreshRoom = LanguageParser.AnalyzePlayerInput(misersHouse.playerInput, MisersHouseMain.playerLocation, roomItems);

                    if (LanguageParser.PlayerConfused > 5)
                    {
                        Console.WriteLine(MisersHouseMain.FormatTextWidth(MisersHouseMain.maxColumns, "\n You appear to be confused or frustrated.  None of your commands make any sense!  If you need help, please type: 'HELP' as a command!  I am here to serve you!"));
                        LanguageParser.PlayerConfused = 0;
                    }
                }

                //...MORE CODE?  Not yet...  The "quit" command will change the 'gameIsActive' value;
            }

            misersHouse.DisplayGameEnding();
        }