연금술 제작법 관리 시스템
게임 속에 있을 연금술 제작 공방 관리 프로그램
기능 요구사항
기존 연금술 공방 관리 시스템에 검색 기능 추가
- 물약 이름으로 검색이 가능해야 한다.
- 재료로 검색이 가능해야 한다. 특정 재료가 포함된 모든 레시피를 찾을 수 있어야 한다.
- 물약 이름이 동일한 경우는 없다고 가정
구현 (미완성)
포션 레시피 클래스와 공방 관리 시스템 클래스의 멤버 함수와 멤버 변수를 선언 해 뼈대를 구축하고 멤버 함수를 만들어 가고 있다.
오늘은 레시피 추가, 모든 레시피 출력과 포션이름으로 검색하여 재료가 반환되는 함수를 구현 하였다.
#include <iostream>
#include <string>
#include <vector>
#include <map>
using namespace std;
class PotionRecipe
{
private:
string potionName;
vector<string> ingredients;
public:
PotionRecipe(const string& name, const vector<string>& ingredient)
{
potionName = name;
ingredients = move(ingredient);
}
const vector<string>& GetIngredients() const { return ingredients; } // const &를 안붙이면 겟 할때마다 복사생성자가 호출된다.
};
class AlchemyWorkShop
{
private:
vector<PotionRecipe> recipes;
map<string, PotionRecipe> storage;
public:
AlchemyWorkShop()
{
}
void addRecipe(const string& name, const vector<string>& ingredients)
{
PotionRecipe potionRecipe(name, ingredients);
recipes.push_back(potionRecipe);
storage.emplace(name, potionRecipe);
}
void displayAllRecipes() const
{
for (const auto& pair : storage)
{
cout << "name : " << pair.first << ", 재료 : ";
for (const auto& vec : pair.second.GetIngredients())
{
cout << vec << " ";
}
cout << endl;
}
}
PotionRecipe searchRecipeByName(const string& name)
{
const auto& it = storage.find(name);
if (it == storage.end()) return PotionRecipe("None", vector<string>());
const auto& pair = *it;
for (const auto& ingredient : pair.second.GetIngredients())
{
cout << ingredient << endl;
}
return pair.second;
}
vector<PotionRecipe> searchRecipeByIngredient(const string ingredient);
};
int main()
{
vector<string> ingredients;
AlchemyWorkShop* potion = new AlchemyWorkShop();
// 체크용 포션 레시피 추가
potion->addRecipe("healing potion", ingredients = { "버섯", "물" });
potion->addRecipe("Mana potion", ingredients = { "별가루", "물" });
potion->addRecipe("potion", ingredients = {"물" });
// 모든 포션 밑 레시피 출력
potion->displayAllRecipes();
// 포션 이름으로 검색
potion->searchRecipeByName("healing potion");
return 0;
}
현재 단계의 출력

현재 구현한 레시피 추가, 모든 레시피 출력, 포션이름으로 검색 기능이 뜨는 것을 볼 수 있다.
'언리얼' 카테고리의 다른 글
| [2025.12.23] Unreal_7기 19 일차 | C++ 3 주차 (0) | 2025.12.23 |
|---|---|
| [2025.12.22] Unreal_7기 18 일차 | C++ 2 주차 (0) | 2025.12.22 |
| [2025.12.18] Unreal_7기 16 일차 | C++ 2 주차 (0) | 2025.12.18 |
| [2025.12.17] Unreal_7기 15 일차 | C++ 2 주차 (0) | 2025.12.17 |
| [2025.12.16] Unreal_7기 14 일차 | C++ 2 주차 (0) | 2025.12.16 |
