Add a Help command to display a list of possible commands

From TRCCompSci - AQA Computer Science
Jump to: navigation, search

A Help method

You could add an new method into the skeleton program to display the help information:

        private static void help()
        {
            Console.WriteLine("Commands: \n Get \n Use \n Go \n Read \n Examine \n Open \n Close \n Move \n Playdice \n Attack \n Quit");
        }

Now you can add a command into the PlayGame switch case statement by putting the code below:

                    case "help":
                        help();
                        break;

Command Only

Alternatively, if you don't want to make a new method you could just add the code into the PlayGame switch case:

case "help":
     Console.WriteLine("Commands: \n Get \n Use \n Go \n Read \n Examine \n Open \n Close \n Move \n Playdice \n Attack \n Quit");
     break;

More Complex Method

Alternatively, you could instead of just using Console.WriteLine you could create a List or Array of the commands and output them:

        private static void CreateCommandList(List<string list)
        {
            list.Add("Go");
            list.Add("Get");
            list.Add("Use");
            list.Add("Examine");
            list.Add("Move");
            list.Add("Open");
            list.Add("Close");
            list.Add("Read");
            list.Add("PlayDice");
            list.Add("Quit");
        }

Now at the start of PlayGame declare a new list, and run CreateCommandList:

List<string> commands = new List<string>();
CreateCommandList(commands);

Now as part of the PlayGame switch case statement add the following code:

                    case "help":
                        Console.WriteLine("The in game commands are: ");
                        foreach(string s in commands)
                            Console.WriteLine(s);
                        break;