For this quest, you are going to start with the Attribute and Monster structs from the previous quest and write several functions (NOTE: I've renamed the Monster struct to Object). You will have to decide the return type and parameters! 1. printType(); a. will use a switch to print to the console an object's type. 2. loadGame() a, this function will load a saved game from a file. b. The file is structured such that the first item in the file is the number of objects. c. Each object in the file starts with the integer value for the Object::Type enum followed by values for all the attributes. 3. saveGame() a. This function is called when a player quits the game in the middle of a battle. b. The number of monsters +1 is first output to the file
For this quest, you are going to start with the Attribute and Monster structs from the previous quest and write several functions (NOTE: I've renamed the Monster struct to Object). You will have to
decide the return type and parameters!
1. printType();
a. will use a switch to print to the console an object's type.
2. loadGame()
a, this function will load a saved game from a file.
b. The file is structured such that the first item in the file is the number of objects.
c. Each object in the file starts with the integer value for the Object::Type enum followed by values for all the attributes.
3. saveGame()
a. This function is called when a player quits the game in the middle of a battle.
b. The number of monsters +1 is first output to the file
c. Each object (starting with the player) has the integer value of their name output followed by all the object's attributes.
4. displayBattle();
a. outputs to the console the player's information and a numbered list of monsters along with their health.
5. monsterAttack();
a loops over all monsters in the
b. returns true if all monsters are dead.
6. playerAttack();
a. Asks the user for an integer between 1 and monsters.size() and has the player attack that monster using the defend and attack methods (as mentioned below).
7. attack().
a. Output the attacking object's type and the string deals" to the console
b. uses a normal distribution with the mean being the attacker's strength and the standard deviation being 1 divided by the attacker's accuracy to calculate the damage done and return it..
8. defend():
a. outputs the passed-in damage integer and the string" damage to", along with the
defending object's type to the console. b. Uses the defending object's AC as the mean for a uniform distribution and the defender's level as the standard deviation to calculate the object's defense. This amount is subtracted from the incoming damage (ensuring it does not go below 0) c. subtracts the calculated damage amount from the defending object's HP.
d. Usage:: defend(monsters.at(0), attack(player));
Trending now
This is a popular solution!
Step by step
Solved in 3 steps