Question: Objective Add commands for getting items off the ground, view your inventory, dropping items on to the ground, and looking at items that are on

Objective
Add commands for getting items off the ground, view your inventory, dropping items on to the ground, and looking at items that are on the ground.
Your code is automatically copied into ~/cse240/05-mud/04 from the prior level.
This level will need to create a data structure to store the player's inventory. The inventory variable may be a simple array of 100 integers (the integers will store the item_id that's in the players inventory). It may also be a global variable within operations.c.
Update room display
Add item to room's display if value in room.item
If the room's item is greater than -1 then display "You see a %s" where %s is filled with the item's name.The item should occurr before the legend with the exits and commands
Update command legend to include [l]ook,[g]et,[i]nventory,[d]rop
[[n]orth,[s]outh,[l]ook,[g]et,[i]nventory,[d]rop,[q]uit ]
Add new command processing
After each command re-display the room informationLook or l
Looks at an item that's laying on the floor in a room.It prints the item's description
Get or g
A 'get;'will pick up the item, removing it from the room by setting the room's item to -1 and putting it into the player's inventory.The program must say "You picked up a " followed by the name of the item picked upThe item should no longer be displayed in the room (maybe make the room.item =-1)The item should now be in the player's inventory
Inventory or i
Displays the items that are in a player's inventory (i.e., the player's backpack).On display, the backpack will
List the items in the backpack
Print a description of the action "Your backpack of infinite holding contains:"Each item should be preceded with a +It will display its item Id number in brackets followed by the nameThe items must be listed in the order they were picked up
If nothing is in the backpack, then the game should say, "You currently have nothing in your backpack"
Example Inventory
Your backpack of infinite holding contains: +[5] scimitar blade +[10] pit +[135] fountain water +[365] banner war merc +[22] sword long
Drop or d
After user initiates a drop, the game will display the player's inventoryIt will prompt the user to enter the item ID of the item the player would like to dropIf the value entered by the player is not in the backpack then the game should print "Item does not exist in backpack".If value entered matches an item in the player's inventory, then
remove the item ID from the player's inventoryAssign the item Id to the the current room, room[X].item = itemIdOnly 1 item can be on the floor in a room at a timeIf an item is dropped in a room that already has an item in it, then the dropped item will overwrite the current item. In other words, the room.item field can be an integer and does not need to be an array.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!