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 pick-up 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 Describe(int location);
int GetUserInput(char *aline, int maxLine);
void ParseUserInput(char *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 GAME_H
#define GAME_H
#include "Location.h"
#include "Player.h"
#include "Item.h"
#define MAX_MAP_LOCATIONS 25
#define MAX_ITEM_COUNT 10
#define MAP_FILENAME "map.txt"
#define ITEM_FILENAME "items.txt"
typedef struct
{
int numLocations;
Location map[MAX_MAP_LOCATIONS];
int itemCount;
Item items[MAX_ITEM_COUNT];
Player player;
}Game;
int GameInitialize(Game *pGame);
#endif
________________________________________________
This is the .c file I have so far:
#include
#include
#include "Game.h"
#define LINE_MAX 128
/*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 main(void)
{
char input[LINE_MAX];
GameInitialize(); // loading up the game
//Interacting with the game
while(1)
{
Describe(game.player.location);
GetUserInput();
ParseUserInput();
}
return 0;
}
void Describe(int 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 GetUserInput(char *aline, int maxLine)
{
fgets(); // store user input in aline
//clean up user input
if(strlen(aline)>0)//did we recieve any input from user?
{
//remove trailing new line from user input
aline[strlen(aline)-1]='\0';
}
return strlen(aline); //return string length of user input
}
void ParseUserInput(char *aline)
{
char *verb = strtok(aline,"");
char *noun = strtok(NULL,"");
int itemNumber;
bool itemMoved;
//switch statement
//if user wants to pick up an item
ItemGetItemNumber()// get item handle/number
LocationHasItem()//does this location even have the item in question
PlayerAddItem()//if location has item, add it to player
LocationRemoveItem()//remove item from location since the player is now holding it
//if user wants to drop an item
ItemGetItemNumber()//get item handle/number
PlayerHasItem()//does the player even have the item they want to drop?
PlayerRemoveItem()//if player has the item, then drop it
LocationAddItem()//add the item to the location since the player dropped it there
//if user wants to check inventory
//check player's item count
//if 0, print message saying that you have nothing in your inventory
//if not 0, 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 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 Databases Questions!