Question: * This is in C programming * create the game by interfacing with the user to accept and follow the user s commands. For this
This is in C programming
create the game by interfacing with the user to accept and follow the
users commands. For this part of the assignment, implement a main.c which allows a player to move around the map in all directions, look at each room, and pickup or drop items. The interface must accept and implement all the user commands described earlier.
Have main.c include your Game.h file. Implement the following looping logic in your main.c:
Describe the location including items located at the user's current location
Read user input
Parse and perform the appropriate operation or report an error message
Implement each function below:
void Describeint location;
int GetUserInputchar aline int maxLine;
void ParseUserInputchar aline;
Call these from within your main function in a loop that terminates only when the user requests to quit the game.
This is my game.h file:
#ifndef GAMEH
#define GAMEH
#include "Location.h
#include "Player.h
#include "Item.h
#define MAXMAPLOCATIONS
#define MAXITEMCOUNT
#define MAPFILENAME "map.txt
#define ITEMFILENAME "items.txt
typedef struct
int numLocations;
Location mapMAXMAPLOCATIONS;
int itemCount;
Item itemsMAXITEMCOUNT;
Player player;
Game;
int GameInitializeGame pGame;
#endif
This is the c file I have so far:
#include
#include
#include "Game.h
#define LINEMAX
Describe the location including items located at the user's current location
Read user input
Parse and perform the appropriate operation or report an error message
Game game;
int mainvoid
char inputLINEMAX;
GameInitialize; loading up the game
Interacting with the game
while
Describegameplayer.location;
GetUserInput;
ParseUserInput;
return ;
void Describeint location
Check game's map field for location number and print out name and description printf
loop through all items at that location and print out each printf there is a bowl here
reading user input
int GetUserInputchar aline int maxLine
fgets; store user input in aline
clean up user input
ifstrlenalinedid we recieve any input from user?
remove trailing new line from user input
alinestrlenaline;
return strlenaline; return string length of user input
void ParseUserInputchar aline
char verb strtokaline;
char noun strtokNULL;
int itemNumber;
bool itemMoved;
switch statement
if user wants to pick up an item
ItemGetItemNumber get item handlenumber
LocationHasItemdoes this location even have the item in question
PlayerAddItemif location has item, add it to player
LocationRemoveItemremove item from location since the player is now holding it
if user wants to drop an item
ItemGetItemNumberget item handlenumber
PlayerHasItemdoes the player even have the item they want to drop?
PlayerRemoveItemif player has the item, then drop it
LocationAddItemadd the item to the location since the player dropped it there
if user wants to check inventory
check player's item count
if print message saying that you have nothing in your inventory
if not loop through each item in your inventory and print it out
Handle incorrect commands
At the bottom of your switch statement, you should include a default case and print error messages
make sure to add a breakout command after each case!
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
