Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The project in C is to create a game in which a player goes through a series of rooms in which they can find a

The project in C is to create a game in which a player goes through a series of rooms in which they can find a prize or a monster to fight. Game Rules:

A player will enter the number of rooms (greater than 1) they want to endure. The program will dynamically allocate an array of Rooms and populate it with prizes and monsters. Then, the player will enter each room in which an action will occur: o If the player enters a room with a prize, they will get a random value between 5 and 10, inclusive, added to their hitPoints. o If the player enters a room with a monster, the player will lose hitPoints based on the monsters hitPoints and the players experiencePoints. The monsters hitPoints is a random value between 10 and 30, inclusive. The total number of hitPoints lost is equal to the monsters hitPoints minus the players experiencePoints. Should the players experiencePoints be greater than the monsters hitPoints, the player does not lose any hitPoints. Each time a player battles a monster (win or lose), the player will get an increase to their experiencePoints. This increase is a random value of 0 or 1.

If a players hitPoints goes to zero or below at any point, they automatically lose. If a player completes all the rooms without their hitPoints going to zero at any time, they win. TASK 1 create and write monsterbattle.c and monsterbattle.h Write the source (.c) and header (.h) files for the game. The header file will have the definitions for all the structs you need, an enum, and the prototypes for the functions below. enum Include this enum in your header file so you can use as values for determining what the room has. typedef enum TYPE { EMPTY, PRIZE, MONSTER } TYPE; structs

Character this struct has two data members hitPoints and experiencePoints. This struct will represent a monster in the game. In this game, a monsters hitPoints represents the amount of damage it can inflict on the player and the experiencePoints is the number of experience points the player gains from battling this monster. Note that this struct will also be used to represent the player in which case the hitPoints represents their life points. Should this value go to zero or below, they have died. The experiencePoints for a player are used to deflect a monsters attack.

Prize this struct has one data members points. The points is what is awarded to a players hitPoints should they enter a room with a prize.

Room this struct represents a room. The game will create an array of these structs. The struct has three data members: type (see the enum above) to determine if this room is empty, has a monster, or a prize. If the room has a prize, then the prize data member will be initialized (see fillRooms()). If the room has a monster, then the monster data member will be initialized (see fillRooms()). If the room is empty, nothing happens with these data members. This struct is provided to you here: typedef struct Room { TYPE type; Character monster; Prize prize; } Room; Prototypes See functions in Task 2 below. Write all the prototypes. TASK 2 create and write monsterbattle.c (Monster Battle functions) Write the following functions that use all the struct's above.

int getRandomNumber( int min, int max ) This function computes a random number between min and max, inclusive, and returns it.

void fillRooms( Rooms *rooms, int length ) This function fills the array of rooms with a prize, monster, or nothing (empty room). There is a 10% chance that this room is empty, a 40% chance that this room has a prize, and 50% chance that this room has a monster in it. To do this, you can use the function getRandomNumber() to generate a random number between 0 and 9, inclusive, and use those values to determine which type to set. o Set the rooms type data member to EMPTY, PRIZE, or MONSTER o If the type is PRIZE, set the rooms prize data members points data member to a random value between 5 and 10, inclusive. o If the type is MONSTER, set the rooms monster data members hitPoints data member to a random value between 10 and 30, inclusive.using getRandomNumber().If the rooms monster hitPoints is a multiple of 3, set the rooms monster data members experiencePoints data member to 1. Otherwise, set its experiencePoints to 0. o If the type is EMPTY, do not set any other of the rooms data members.

void enterRoom( Room room, Character player, int *resultHP, int *resultXP ) This function simulates the character entering a room. o If the room type is EMPTY, print out a message that says the room is empty. Set the dereferenced values of resultHP and resultXP to 0. o If the room type is PRIZE, print out a message that says the room has a prize and how many points it has. Set the dereferenced values of resultHP to the prizes points and resultXP to 0. o If the room type is MONSTER, print out a message saying that the room has a monster. Do the battle calculations (see the rules above) to figure out how much damage was done (this should be a negative number). Set the dereferenced values of resultHP to the total damage and resultXP to the number of experiencePoints awarded by the monster. This function returns nothing.

void printCharacter( Character c ) This function prints out the Characters data member. It could look like this: Player (HP: 20, XP: 9). Assume it will only be used to print out the players information. TASK 3: Complete the project1-main.c

Download the attached project1-main.c Follow the instructions written in the comments in the main() function. The main() is the driver of the program. It calls the functions above set up the game and to simulate the battles.

project1 - main.c:

#include  #include  int main() { /* 1. Declare your variables here */ /* 2. change the seed for random */ /* 3. Initialize the player struct object, to have 50 hitpoints and 0 experience points by default */ /* 4. Dynamically allocate an array of Room structs with the number the user entered. Assume that the user has entered a positive number */ /* 5. Call the fillRooms function() to create the rooms */ /* 6. Print out a message to say how many rooms there are and that the challenge has started. */ /* 7. Call printPlayer() to print out the beginning stats */ /* 8. Taverse the array of rooms, for each room: 8.1 Call enterRoom() 8.2 Print out a message about how many hitpoints were lost or gained while in this room. Print out this value in a positive number (You lost 5 hitpoints while in this room). 8.3 Determine if entering the room resulted in a gain in experience points, and print out an appropriate message stating as such. If not experience points were gained, do not print out a message. 8.4 Update the player's hitpoints with the loss or gain. Never allow for the player's hitpoints to be negative. If it goes below zero, simply set the player's hitpoints to 0. If the player's hitpoints is zero, break the loop as the game is over. 8.5 Update the player's experience points 8.6 Call printPlayer() to print out the updated player's stats. 9. Outside the loop, print out a message of congratulations if the player has any hitpoints left. If a player has zero hitpoints, print out a message of regret. 10. deallocate the array of rooms. */ return 0; }

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

Step: 3

blur-text-image

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

Database And Expert Systems Applications Dexa 2023 Workshops 34th International Conference Dexa 2023 Penang Malaysia August 28 30 2023 Proceedings

Authors: Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil ,Bernhard Moser ,Atif Mashkoor ,Johannes Sametinger ,Maqbool Khan

1st Edition

303139688X, 978-3031396885

More Books

Students also viewed these Databases questions