write a c++ program that Create a game where a player and an enemy battle each o
ID: 3645227 • Letter: W
Question
write a c++ program that Create a game where a player and an enemy battle each other. Each has a certain amount ofhealth, which decreases when they are attacked. The battle ends when either the player or the
enemy runs out of health.
Each round, the player gets a chance to attack the enemy. The player (the user) can choose to
attack normally, or use a magic spell. Casting a spell costs 1 magic point, and the player only has
3 to begin with. However, magic spells hit for more damage. Check that the player has sufficient
MP to use the spell if it is chosen. After the players turn comes the enemys turn. The enemy
has no magic and can only attack. After both have taken their turns, you must check whether the
game has ended. Otherwise, continue. (Hint: Flag controlled loop)
To make the game more interesting, the strength of attacks is random. Both the player and the
enemy have a maximum attack strength. When an attack is made, generate a random number
between 0 and the maximum attack strength. If the attack is 0, display a message saying the
attack missed. If it is full strength, display a message saying it was a critical hit.
Here are some of the constants you will need in your program (change the values if you want):
const int INITIAL_PLAYER_HEALTH = 25;
const int INITIAL_ENEMY_HEALTH = 50;
const int PLAYER_ATTACK = 12;
const int ENEMY_ATTACK = 7;
const int PLAYER_MAGIC_ATTACK = 50;
const int INITIAL_PLAYER_MP = 3;
Constraint: you must include the following functions in your program:
1. A function named GetRandomBetween that takes a minimum and a maximum value,
and generates a random number between those two values. *Remember* the formula for
a random number is rand() % range + min, so you will first have to compute the
range.
2. A function named PlayerTurn that handles the player attacking the enemy. Remember,
the player can choose a regular attack or a magic attack. A magic attack costs 1 mp. Hint:
this function will have to be able to modify both the players mp and the enemys health.
3. A function named EnemyTurn that handles the enemy attacking the player. Hint: this
function will have to be able to modify the players health.
I also included other functions I thought were useful, such as:
PrintStats - displays the players health and mp before each round
PlayerAttack - prints messages about the attack (miss or critical hit) and returns the
attack strength
PlayerMagicAttack - similar to PlayerAttack but deals with a magic attack. Checks to
make sure player has enough mp and modifies player mp
Sample Output:
You have 25 health remaining.
You have 3 magic points left
It is your turn! What would you like to do?
A-Attack
M-Magic attack COST: 1MP
q
That is not a valid command!
The enemy lunges towards you with slimy claws...
You take 2 damage
You have 23 health remaining.
You have 3 magic points left
It is your turn! What would you like to do?
A-Attack
M-Magic attack COST: 1MP
m
You chant a terrifying incantation...
The enemy takes 16 damage
The enemy lunges towards you with slimy claws...
You take 4 damage
You have 19 health remaining.
You have 2 magic points left
It is your turn! What would you like to do?
A-Attack
M-Magic attack COST: 1MP
a
You strike at the enemy with your sword...
The enemy takes 8 damage
The enemy lunges towards you with slimy claws...
You take 1 damage
You have 18 health remaining.
You have 2 magic points left
It is your turn! What would you like to do?
A-Attack
M-Magic attack COST: 1MP
m
You chant a terrifying incantation...
It has no effect!
The enemy takes 0 damage
The enemy lunges towards you with slimy claws...
You take 1 damage
You have 17 health remaining.
You have 1 magic points left
It is your turn! What would you like to do?
A-Attack
M-Magic attack COST: 1MP
m
You chant a terrifying incantation...
The enemy takes 40 damage
You killed the enemy!
Explanation / Answer
#ifndef Being_h #define Being_h #include using namespace std; class Being {public: string name; int attackBonus; int range; float attackMod; int health; int healthMax; int mp; int mpMax; int arrows; void attack(Being& target); void rangedAttack(Being& target); void heal(); }; #endif or #include "Combat.h" 02 #include "Monster.h" 03 #include "Character.h" 04 05 Combat::Combat(Monster& newM) : M(newM) 06 { 07 08 } 09 10 11 void Combat::combatChoice(Character& C) 12 { 13 if (C.health>0) 14 { 15 C.display(); 16 17 coutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.