Please create a game using C++. The compiler I am using is Visual Studios. The p
ID: 660130 • Letter: P
Question
Please create a game using C++. The compiler I am using is Visual Studios. The program must contain pointers, classes, inheritance, polymorphism, operator overloading, file processing, standard library, and data structures. Also, inlcude comments clearly labeling each of the required topics, and a short description of what is happening in the program. The game can be anything. I just need a description of what it is supposed to do. I am trying to see how to create games in this programming style.
Explanation / Answer
Here my example is...we have one animal which we set initial power / health for it. Similarly we creating two attacking animals where setting attacking power too...so that when they attack our animal power will reduce...at last animal will die if animal health is zero..otherwise survives if greater than zero.
----------------------------------------------------------
#include <iostream>
#include "Animal.h"
using namespace std;
int main() {
Tiger g;
Lion z;
Animal *Attacker1 = &g;
Animal *Attacker2 = &z;
Attacker1->setanimalAttackingPower(20);
Attacker2->setanimalAttackingPower(40);
g.attack();
z.attack();
return 0;
}
------------------------------------------------------------
//Animal.h
#include <iostream>
using namespace std;
class Animal
{
protected:
int AnimalHealth = 100;
int animalAttackingPower;
public:
void setanimalAttackingPower(int attack) {
animalAttackingPower = attack;
}
void attack(Animal* target)
{
target->AnimalHealth -= animalAttackingPower;
Attacking();
}
virtual void Attacking() = 0;
};
class Tiger: public Animal
{
public:
void Attacking() {
cout << "Tiger is attacking your Animal! - " << animalAttackingPower << " Points!" << endl;
}
};
class Lion: public Animal
{
public:
void Attacking() {
cout << "Lion is attacking your Animal! - " << animalAttackingPower << " Points!" << endl;
}
};
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.