게임 개발자를 위한 C++ 문법 팀프로젝트 1

#include "../../include/Unit/NormalMonster.h"
#include "../../include/Item/IItem.h"
#include "../../include/Item/HealPotion.h"
#include "../../include/Item/AttackUp.h"
#include <random>
#include <tuple>
#include <memory>
using namespace std;
// GameManager에 추가 후 삭제
static mt19937 gen(random_device{}());
NormalMonster::NormalMonster(int PlayerLevel)
{
_Name = "Normal Monster";
_Level = PlayerLevel;
uniform_int_distribution<> HpDist(_Level * 20, _Level * 30);
_MaxHP = HpDist(gen);
_CurrentHP = _MaxHP;
uniform_int_distribution<> AtkDist(_Level * 5, _Level * 10);
_Atk = AtkDist(gen);
}
void NormalMonster::TakeDamage(int Amount)
{
// 데미지 받음
_CurrentHP -= Amount;
if (_CurrentHP < 0)
{
_CurrentHP = 0;
}
}
void NormalMonster::Attack(ICharacter* Target)
{
if (Target == nullptr)
{
return;
}
// 공격 연출 등 나중에 추가하면 될 듯
Target->TakeDamage(_Atk);
}
bool NormalMonster::IsDead()
{
// Dead 여부 확인
return _CurrentHP <= 0;
}
tuple<int, int, IItem*> NormalMonster::DropReward()
{
// 경험치 50, 골드 10~20, 30% 확률 아이템 드롭
IItem* DropItem = nullptr;
if (uniform_int_distribution<>(0, 9)(gen) < 3) // 30%
{
if (uniform_int_distribution<>(0, 1)(gen)) // 50%
{
//HealPotion 생성
}
else
{
//AttackUp 생성
}
}
tuple<int, int, IItem*> Reward(50, uniform_int_distribution<>(10, 20)(gen), DropItem);
return Reward;
}
일단 리워드를 드롭하는건 껍데기만 구현했고,, 아이템 로직에 대한 이해가 더 필요한거 같다.
#include "../../include/Manager/BattleManager.h"
#include "../../include/Unit/NormalMonster.h"
#include "../../include/Unit/Player.h"
#include <iostream>
#include <tuple>
#include <memory>
using namespace std;
bool BattleManager::StartAutoBattle(Player* P)
{
// Implementation needed
// 현재: 플레이어 선공, 노멀 몬스터로 고정 (추후 몬스터 지정 필요)
NormalMonster* NM = new NormalMonster(P->GetLevel());
while (true)
{
ProcessTurn(P, NM);
if (NM->IsDead())
{
//플레이어 승리
CalculateReward(P, NM);
return true;
}
ProcessAttack(NM, P);
if (P->IsDead())
{
//플레이어 패배
cout << "플레이어 패배" << endl;
return false;
}
}
}
void BattleManager::ProcessTurn(ICharacter* Atk, ICharacter* Def)
{
//아이템 사용 여부 체크 후 사용
if(Atk->GetCurrentHP() < Atk->GetMaxHP() / 4) //dummy // 체력 1/4 이하일 때 아이템 사용
{
Player* P = dynamic_cast<Player*>(Atk);
if(P != nullptr)
{
// 아이템 미보유 예외처리 추가 필요
P->UseItem(0); //dummy
cout << P->GetName() << "이(가) 아이템을 사용했습니다." << endl;
}
}
ProcessAttack(Atk, Def);
}
void BattleManager::ProcessAttack(ICharacter* Atk, ICharacter* Def)
{
Atk->Attack(Def);
cout << Atk->GetName() << "의 공격" << endl;
cout << Def->GetName() << "의 피해량: " << Atk->GetAtk() << ", 남은 체력: " << Def->GetCurrentHP() << "/" << Def->GetMaxHP() << endl;
}
void BattleManager::CalculateReward(Player* P, IMonster* M)
{
// Implementation needed
// 전투 결과에 따른 보상 계산 및 지급, 플레이어는 경험치 및 골드, 아이템 획득
tuple<int, int, IItem*>Reward = M->DropReward();
P->GainExp(get<0>(Reward)); // 경험치 획득
P->GainGold(get<1>(Reward)); // 골드 획득
//P->GetInventory().AddItem(아이템포인터, 1);
}
객체 생성 코드 오류를 수정해야한다..
팀원들한테 질문 폭탄 날렸는데 다들 고생하셨습니다.ㅜㅜ
'내배캠Unreal_TIL > 팀프로젝트' 카테고리의 다른 글
| [TIL] 2026-01-06 | [텍스트 콘솔 RPG] BM → BS 콜백 작업, 디버깅 (0) | 2026.01.06 |
|---|---|
| [TIL] 2026-01-05 | [텍스트 콘솔 RPG] 몬스터 클래스 디테일 높이기, 배틀매니저 로직 새로 짜기 (1) | 2026.01.05 |
| [TIL] 2026-01-02 | [텍스트 콘솔 RPG] 텍스트 로그 기반 진행 → 실시간 UI 렌더링 방식으로 전환 (0) | 2026.01.02 |
| [TIL] 2026-01-01 | [텍스트 콘솔 RPG] 아스키 아트 작업 (0) | 2026.01.02 |
| [TIL] 2025-12-30 | [텍스트 콘솔 RPG] 팀 프로젝트 1 시작하기 (0) | 2025.12.30 |