C Program Simple RPG Battle: To start, you and the enemy both have 100 hit point
ID: 3742372 • Letter: C
Question
C Program Simple RPG Battle:
To start, you and the enemy both have 100 hit points. You as the player also have health potions. You will provide a menu that asks you the action you wish to take. Each action should have its ownfunction to implement the action. The actions I want you to implement include:
Attack: you need to pass in the enemy’s hit points, reduce them in the function by 20 damage points, and return the enemies remaining hit points. Also, have some text output letting the user know that the player attacked the enemy for 20 damage, and also output how many hit points the enemy has after the attack.
Heal: You, as the player, have the option the heal. So, you need to pass in your own hit points to the function. Inside of the function, you need increase your hit points by 60. Then you need to return your how much health you have back to the main program. As before have some text output letting the user know that you healed yourself for 60hit points, and then output how many total hit points the user has after they healed themselves.
Retreat: If you choose this option, then you run away ending the program. I want you to write a function stating how cowardly your character is and give a little narrative to their shameful flee.
After the user makes their action, the enemy will always attack the user for 30 damage. Make sure you do this in a function, so you’ll have to input the user’s hit points and return how many they have left after the attack. Remember to output some text letting the user know what’s happening similarly to the attack function mentioned above.
Once the user has won, lost, or retreated, give some text output stating what happened and exit the program.
Explanation / Answer
Program:--
#include<stdio.h>
// Attack function with text output says what happen
// and retuen the remaining points after attack
int Attack(int points)
{
printf(" The player attacked the enemy for 20 damage ");
printf("Enemy has %d points after the attack ",points-20);
return points-20;
}
// Heal function with text output says what happen
// and retuen the remaining points after heal
int Heal(int points)
{
printf("You healed yourself for 60 hit points ");
printf("You have %d points after Heal ",points+60);
return points+60;
}
//retreat function with simple printfs
void Retreat()
{
printf("I am queting the Game.");
printf("Program ending...");
}
// enemyAttacked function with text output says what happen
// and retuen the remaining points after enemy attacked
int enemyAttacked(int points)
{
printf(" Enemy Attacked for 30 hit points ");
printf("You have %d points after Attack ",points-30);
return points-30;
}
//main
int main()
{
int hitpoints=100,enemy_hitpoints=100;
int ch;
printf(":::RPG Battle:::");
//repeat the pross untill won lost or retreat the game
do
{
if(hitpoints<=0) //chcks enemy won
{
printf(" You lost the Game. Enemy Won!!!");
break;
}
if(enemy_hitpoints<=0) //chcks player won
{
printf(" Enemy lost the Game. You Won!!!");
break;
}
// naither won
printf(" 1.Attack 2.Heal 3.Retreat Enter the action you wish to take: ");
scanf("%d",&ch);
switch(ch)
{
case 1:
enemy_hitpoints=Attack(enemy_hitpoints); //call attack
hitpoints=enemyAttacked(hitpoints); //call enemy attack
break;
case 2:
hitpoints=Heal(hitpoints); //call heal
hitpoints=enemyAttacked(hitpoints); //call enemy attack
break;
case 3:
Retreat(); //call retreat
break;
default:printf("Enter 1,2 or 3 Only");
break;
}
}while(ch!=3);
return 0;
}
output:--
:::RPG Battle:::
1.Attack
2.Heal
3.Retreat
Enter the action you wish to take: 1
The player attacked the enemy for 20 damage
Enemy has 80 points after the attack
Enemy Attacked for 30 hit points
You have 70 points after Attack
1.Attack
2.Heal
3.Retreat
Enter the action you wish to take: 1
The player attacked the enemy for 20 damage
Enemy has 60 points after the attack
Enemy Attacked for 30 hit points
You have 40 points after Attack
1.Attack
2.Heal
3.Retreat
Enter the action you wish to take: 1
The player attacked the enemy for 20 damage
Enemy has 40 points after the attack
Enemy Attacked for 30 hit points
You have 10 points after Attack
1.Attack
2.Heal
3.Retreat
Enter the action you wish to take: 2
You healed yourself for 60 hit points
You have 70 points after Heal
Enemy Attacked for 30 hit points
You have 40 points after Attack
1.Attack
2.Heal
3.Retreat
Enter the action you wish to take: 1
The player attacked the enemy for 20 damage
Enemy has 20 points after the attack
Enemy Attacked for 30 hit points
You have 10 points after Attack
1.Attack
2.Heal
3.Retreat
Enter the action you wish to take: 2
You healed yourself for 60 hit points
You have 70 points after Heal
Enemy Attacked for 30 hit points
You have 40 points after Attack
1.Attack
2.Heal
3.Retreat
Enter the action you wish to take: 1
The player attacked the enemy for 20 damage
Enemy has 0 points after the attack
Enemy Attacked for 30 hit points
You have 10 points after Attack
Enemy lost the Game.
You Won!!!
Process exited normally.
Press any key to continue . . .
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.