Implement a way to display your inventory

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

You can see what items you have in your inventory by typing "examine inventory". You could also add a command:

Easy Way

For some reason the skeleton program contains a method called DisplayInventory but this is never used within the program. Therefore the easiest way to implement this is to add a command into the switch case statement in play game:

instruction = GetInstruction();
Command = ExtractCommand(ref instruction);
switch (Command)
{
     case "get":
         GetItem(items, instruction, characters[0].CurrentLocation, ref stopGame);
         break;

Find the lines of code above and now add a new case similar to the code below (I have called mine "inventory"):

instruction = GetInstruction();
Command = ExtractCommand(ref instruction);
switch (Command)
{
     case "get":
         GetItem(items, instruction, characters[0].CurrentLocation, ref stopGame);
         break;
     case "inventory":
         DisplayInventory(items);
         break;