#include <iostream>
#include <string>
using namespace std;
class Creature { //Base Class
public:
Creature();
Creature(int newType, int newStrength, int newHit);
int getDamage();
int getType();
int getStrength();
int getHP();
string getSpecies();
protected:
int type; //0 human 1 cyberdemon 2 balrog 3 elf
int strength; // 가할 수 있는 데미지 양
int hitpoints; // 체력
};
Creature::Creature() : type(0), strength(10), hitpoints(10)
{
//
}
Creature::Creature(int newType, int newStrength, int newHit) : type(newType), strength(newStrength), hitpoints(newHit) {
//
}
class Human : public Creature {
public:
Human();
Human(int newStrength, int newHit);
string getSpecies();
int getDamage();
private:
int type = 0;
};
Human::Human(){
strength = 10;
hitpoints = 10;
}
Human::Human(int newStrength, int newHit) {
strength = newStrength;
hitpoints = newHit;
}
string Human::getSpecies() {
return "Human";
}
class Cyberdemon : public Creature {
public:
Cyberdemon();
Cyberdemon(int newStrength, int newHit);
string getSpecies();
int getDamage();
private:
int type = 1;
};
Cyberdemon::Cyberdemon() {
strength = 10;
hitpoints = 10;
}
Cyberdemon::Cyberdemon(int newStrength, int newHit) {
strength = newStrength;
hitpoints = newHit;
}
string Cyberdemon::getSpecies() {
return "Cyberdemon";
}
class Balrog : public Creature {
public:
Balrog();
Balrog(int newStrength, int newHit);
string getSpecies();
int getDamage();
private:
int type = 2;
};
Balrog::Balrog() {
strength = 10;
hitpoints = 10;
}
Balrog::Balrog(int newStrength, int newHit) {
strength = newStrength;
hitpoints = newHit;
}
string Balrog::getSpecies() {
return "Balrog";
}
class Elf : public Creature {
public:
Elf();
Elf(int newStrength, int newHit);
string getSpecies();
int getDamage();
private:
int type = 3;
};
Elf::Elf() {
strength = 10;
hitpoints = 10;
}
Elf::Elf(int newStrength, int newHit) {
strength = newStrength;
hitpoints = newHit;
}
string Elf::getSpecies() {
return "Elf";
}
int main() {
Human a1;
Cyberdemon b1(20, 30);
Balrog c1(15, 30);
Elf d1(10, 20);
cout << c1.getDamage();
char flag = 'Y';
while (flag == 'Y' || flag == 'y') {
cout<<"Human 총 데미지 : "<<a1.getDamage()<<endl;
cout << "Cyberdemon 총 데미지 : "<<b1.getDamage()<<endl;
cout << "Balrog 총 데미지 : " << c1.getDamage()<<endl;
cout << "Elf 총 데미지 : " << d1.getDamage()<<endl;
cin >> flag;
}
return 0;
}
string Creature::getSpecies() {
switch (type) {
case 0: return "Human";
case 1: return "Cyberdemon";
case 2: return "Balrog";
case 3: return "Elf";
}
return "Unknown";
}
int Creature::getDamage() {
int damage;
damage = (rand() % strength) + 1;
cout << getSpecies() << " attacks for " <<
damage << " points!" << endl;
//데몬은 5%확률로 +50의 데미지를 입힌다.
if ((type == 2) || (type == 1)) {
if ((rand() % 100) < 5) {
damage += 50;
cout << "Demonic attack inflicts 50"
<< " additional damage points!" <<endl;
}
}
//엘프는 10%확률로 2배의 마법 손상을 가할 수 있다
if (type == 3) {
if ((rand() % 10) == 0) {
cout << "Magical attack inflicts " << damage <<
" additional damage points!" << endl;
damage = damage * 2;
}
}
//발록은 빠르게 2번 공격한다.
if (type == 2) {
int damage2 = (rand() % strength) + 1;
cout << "Balrog speed attack inflicts " << damage2 <<
" additional damage points!" << endl;
damage = damage + damage2;
}
return damage;
}
int Human::getDamage() {
int damage;
damage = (rand() % strength) + 1;
cout << getSpecies() << " attacks for " <<
damage << " points!" << endl;
return damage;
}
int Cyberdemon::getDamage() {
int damage;
damage = (rand() % strength) + 1;
cout << getSpecies() << " attacks for " <<
damage << " points!" << endl;
if ((rand() % 100) < 5) {
damage += 50;
cout << "Demonic attack inflicts 50"
<< " additional damage points!" << endl;
}
return damage;
}
int Balrog::getDamage() {
int damage;
damage = (rand() % strength) + 1;
cout << getSpecies() << " attacks for " <<
damage << " points!" << endl;
if ((rand() % 100) < 5) {
damage += 50;
cout << "Demonic attack inflicts 50"
<< " additional damage points!" << endl;
}
int damage2 = (rand() % strength) + 1;
cout << "Balrog speed attack inflicts " << damage2 <<
" additional damage points!" << endl;
damage = damage + damage2;
return damage;
}
int Elf::getDamage() {
int damage;
damage = (rand() % strength) + 1;
cout << getSpecies() << " attacks for " <<
damage << " points!" << endl;
if ((rand() % 10) == 0) {
cout << "Magical attack inflicts " << damage <<
" additional damage points!" << endl;
damage = damage * 2;
}
return damage;
}
int Creature::getType() {
switch (type) {
case 0 :
cout << "Human" << endl;
break;
case 1:
cout << "Cyberdemon" << endl;
break;
case 2:
cout << "Balrog" << endl;
break;
case 3:
cout << "Elf" << endl;
break;
default:
cout<<"Unknown Type..." << endl;
return -1;
}
return type;
}
int Creature::getStrength() {
return strength;
}
int Creature::getHP() {
return hitpoints;
}
댓글
댓글 쓰기