Answered step by step
Verified Expert Solution
Question
1 Approved Answer
* 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
user
s 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
#define MAX
ITEM
COUNT
#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
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
Describe
game
player.location
;
GetUserInput
;
ParseUserInput
;
return
;
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
did we recieve any input from user?
remove trailing new line from user input
aline
strlen
aline
;
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
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started