Create a C++ program that fulfills the requirements of the following prompt: Thi
ID: 3848499 • Letter: C
Question
Create a C++ program that fulfills the requirements of the following prompt:
This program will create a text-based squad versus squad battling game. The game will be set up so that two players can play and each player will control a squad. Each member of the squad will have basic and special abilities. When one squad has been fully defeated, that player will be declared the loser. The program will then exit.
The basis of this program will require the use of parallel arrays. You should maintain a set of parallel arrays for each squad. The arrays are as follows:
Squad members’ names
Squad members’ health values
Squad members’ mana values
Squad members’ attack values
Each member of the squad should be able to take the following actions:
Attack
Defend
Special Ability
You will create the special abilities as you see fit. It is okay to allow each squad to have the same special abilities. Each time the player uses a Special Ability, that squad member’s mana should be decremented by some amount. If there isn’t enough mana left to use the ability, the player should be informed and the player should be allowed to choose another action to take. For an example, a special ability might look like this:
A squad member is a cleric. The cleric’s special ability is Heal. When I select Heal, I select a squad member. I then heal that squad member for 10 health points.
Play will proceed like this:
Squad A’s player takes their turn
Player A selects a squad member
Player A selects an action for that squad member
That action is carried out and whatever values should be updated, are
Squad B’s player takes their turn
Player B selects a squad member
Player B selects an action for that squad member
That action is carried out and whatever values should be updated, are
Play then loops back to Squad A’s player
The game is considered “done” when each member of a squad is at 0 heath or less.
Your program should be sectioned up using loops and functions. Specifically, special abilities should be in functions. If you need to pass a value to a function, do so using pointers ONLY (remember, passing an array to a function automatically works like a pointer). You should have appropriate validation when choosing what squad member to use (you shouldn’t be able to use squad members with zero health).
Make your program run automatically without any player needing to make input by using randomization. That means all squad member choices are made by the program and all action choices are made by the program. Play will execute the exact same as outlined above.
Explanation / Answer
lets call our two squad as player and enemy.
#include "stdafx.h"
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<ctime>
using namespace std;
int main()
{
int eHealth=100; //initial Enemy Health(based on enemy)
int pHealth=100; //initial Player Health
int eAttack=0; //Enemy Attack Strength(based on enemy)
int pAttack=0; //Player Attack Strength(based on level and items)
int selection=0; //Selection Variable for Battle Menue
int hPower=0; //Healing power Variable(random number)
int eSelection=0; //Enemies battle menu selection variable
int counter=0; //Counter to establish whos turn it is
int itemSelect=0; //Item inventory selection
int eMana=50; //Enemies special power meter
int pMana=50; //Players special power meter
cout<<pHealth<<" "<<eHealth<<endl; //player and enemy health levels
cout<<pMana<<" "<<eMana<<endl; //player and enemy magic levels
cout<<endl;
cout<<endl;
cout<<"1.Attack"<<endl; //lines 31-33 are the battle menu appears frequently throught game
cout<<"2.Heal"<<endl;
cout<<"3.Item"<<endl;
do //start of post test loop that runs the game until somebody is dead
{
if(counter==0)// if the counter variable is 0 it is the players turn
{
cin>>selection;
srand(static_cast<int>(time(0)));//randomize all the random variables
switch(selection)
{
case 1:// player chooses to ATTACK
pAttack=1+rand()%(35-1+1);//attack power can be between 1-35
cout<<"ATTACK "<<pAttack<<endl;
system("pause");
system("cls");
eHealth=eHealth-pAttack;
cout<<pHealth<<" "<<eHealth<<endl;
cout<<pMana<<" "<<eMana<<endl;
cout<<endl;
cout<<endl;
cout<<"1.Attack"<<endl;
cout<<"2.Heal"<<endl;
cout<<"3.Item"<<endl;
break;
case 2://Player chooses to heal, it costs 10 magic to heal so if you dont have enough magic you loose a turn
if(pMana>9)
{
hPower=1+rand()%(35-1+1);//healing power can be any number between 1-35
cout<<"HEAL"<<hPower<<endl;
system("pause");
system("cls");
pHealth=pHealth+hPower;
pMana=pMana-10;
cout<<pHealth<<" "<<eHealth<<endl;
cout<<pMana<<" "<<eMana<<endl;
cout<<endl;
cout<<endl;
cout<<"1.Attack"<<endl;
cout<<"2.Heal"<<endl;
cout<<"3.Item"<<endl;
}//endIF
break;
case 3:// if player chooses to use item inventory system
cout<<"ITEM INVENTORY"<<endl;
cout<<"1.Potion Restores HP"<<endl;
cout<<"2.Ether Restores MP"<<endl;
cout<<"3.Bomb Causes Damage to all players"<<endl;
cout<<"4.Big Purple Dildo ?????"<<endl;
cout<<"5.Sticky Bomb Freezes oponent for 3 Truns"<<endl;
cin>>itemSelect;
switch(itemSelect)
{
case 1:
pHealth=pHealth+75;
system("cls");
cout<<pHealth<<" "<<eHealth<<endl;
cout<<pMana<<" "<<eMana<<endl;
cout<<endl;
cout<<endl;
cout<<"1.Attack"<<endl;
cout<<"2.Heal"<<endl;
cout<<"3.Item"<<endl;
break;
case 2:
break;
}//endItemSwitch
}//endSelectionSwitch
counter=1;// advances the counter to 1 to allow the enemies turn
}//endif
eSelection=rand() % 2+1;
switch(eSelection)
{
case 1:
eAttack=1+rand()%(35-1+1);
cout<<"ATTACK "<<eAttack<<endl;
system("pause");
system("cls");
pHealth=pHealth-eAttack;
cout<<pHealth<<" "<<eHealth<<endl;
cout<<pMana<<" "<<eMana<<endl;
cout<<endl;
cout<<endl;
cout<<"1.Attack"<<endl;
cout<<"2.Heal"<<endl;
cout<<"3.Item"<<endl;
break;
case 2:
if(eMana>10)
{
hPower=1+rand()%(35-1+1);
cout<<"HEAL"<<hPower<<endl;
system("pause");
system("cls");
eMana=eMana-10;
eHealth=eHealth+hPower;
cout<<pHealth<<" "<<eHealth<<endl;
cout<<pMana<<" "<<eMana<<endl;
cout<<endl;
cout<<endl;
cout<<"1.Attack"<<endl;
cout<<"2.Heal"<<endl;
cout<<"3.Item"<<endl;
}
break;
}//endeSelectionSwitch
counter=0;
}while(eHealth > 1 && pHealth > 1);//loops while both players life is over 1 ends postest loop when players life or enemies falls below 1
system("pause");
return 0;
}