Answered step by step
Verified Expert Solution
Link Copied!

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
2
5
#define MAX
_
ITEM
_
COUNT
1
0
#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
1
2
8
/
*
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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Illuminated

Authors: Catherine M Ricardo, Susan D Urban

3rd Edition

1284056945, 9781284056945

More Books

Students also viewed these Databases questions

Question

What are Decision Trees?

Answered: 1 week ago

Question

What is meant by the Term Glass Ceiling?

Answered: 1 week ago