- MonsterType, ObjectInfo Create
- playerInfo, monsterInfo
enum class PlayerType
{
NONE, KNIGHT, ARCHER, MAGE
};
enum class MonsterType
{
NONE, ORC, SKELETON
};
struct ObjectInfo
{
int hp;
int attack;
int defence;
};
// 전역 변수 선언
ObjectInfo playerInfo;
ObjectInfo monsterInfo;
MonsterType monsterType;
void PlayerInfo()
{
playerInfo.hp = 100;
playerInfo.attack = 10;
playerInfo.defence = 5;
}
void CreateRandomMonster()
{
int random = (rand() % 2) + 1;
switch (random)
{
case (int)MonsterType::NONE: // (int) - cast
break;
case static_cast<int>(MonsterType::ORC):
monsterInfo.hp = 20;
monsterInfo.attack = 5;
monsterInfo.defence = 3;
break;
case static_cast<int>(MonsterType::SKELETON):
monsterInfo.hp = 10;
monsterInfo.attack = 3;
monsterInfo.defence = 1;
break;
default:
break;
}
}
void Battle()
{
while (true)
{
int damage = playerInfo.attack - monsterInfo.defence;
if (damage < 0) damage = 0;
monsterInfo.hp -= damage;
if (monsterInfo.hp < 0) monsterInfo.hp = 0;
if (monsterInfo.hp == 0) { return; }
}
}
int main()
{
while (true)
{
PlayerInfo(); // 플레이어 인포 설정
CreateRandomMonster(); // 몬스터 생성
cout << monsterInfo.hp << monsterInfo.attack << monsterInfo.defence << endl;
Battle(); // 나만 때리기
}
}