게임에서 퀘스트와 관련된 데이터를 관리하기 위해 데이터 카드 자료구조를 사용할 수 있습니다. 퀘스트 맵 데이터 카드 자료구조는 각 퀘스트를 카드 형태로 저장하며, 이를 통해 퀘스트의 세부 정보를 체계적으로 관리할 수 있습니다. 카드에는 퀘스트의 ID, 이름, 설명, 보상, 상태 등을 포함하여 게임 플레이 중 퀘스트 정보를 쉽게 조회하고 업데이트할 수 있습니다.

퀘스트 맵 데이터 카드 자료구조 설명

퀘스트 데이터 카드는 다음과 같은 필드를 포함합니다.

  1. 퀘스트 ID (quest_id): 퀘스트를 구분하는 고유 식별자
  2. 퀘스트 이름 (name): 퀘스트의 이름
  3. 퀘스트 설명 (description): 퀘스트의 목적과 수행 방법을 설명
  4. 보상 (rewards): 퀘스트 완료 시 제공되는 보상 (경험치, 아이템 등)
  5. 퀘스트 상태 (status): 현재 퀘스트의 상태 (예: Not Started, In Progress, Completed)
  6. 메타데이터 (metadata): 퀘스트에 대한 추가 정보 (예: 퀘스트 난이도, 퀘스트 위치 등)

데이터 카드 관리 클래스

퀘스트 데이터를 카드 형태로 관리하는 클래스를 정의하고, 퀘스트를 추가, 업데이트, 필터링, 조회하는 기능을 추가합니다.

예제 코드: 퀘스트 맵 데이터 카드 자료구조

from typing import List, Dict

# 퀘스트 데이터 카드 모델 정의
class QuestMap(list):
    def add_quest(self, quest_id: str, name: str, description: str, rewards: Dict, status: str = "Not Started", metadata: Dict = None):
        # 퀘스트 카드 생성
        quest_card = {
            "quest_id": quest_id,
            "name": name,
            "description": description,
            "rewards": rewards,
            "status": status,
            "metadata": metadata or {}
        }
        self.append(quest_card)  # 리스트에 퀘스트 카드 추가

    def update_quest_status(self, quest_id: str, new_status: str):
        # 특정 퀘스트의 상태 업데이트
        for quest in self:
            if quest["quest_id"] == quest_id:
                quest["status"] = new_status
                return quest  # 업데이트된 퀘스트 카드 반환
        return None  # 해당 퀘스트가 없을 때 None 반환

    def filter_by_status(self, status: str) -> List[Dict]:
        # 특정 상태에 해당하는 퀘스트만 필터링하여 반환
        return [quest for quest in self if quest["status"] == status]

    def get_quest(self, quest_id: str) -> Dict:
        # 특정 ID의 퀘스트 카드 조회
        for quest in self:
            if quest["quest_id"] == quest_id:
                return quest
        return None  # 해당 ID의 퀘스트가 없을 때 None 반환

# 퀘스트 맵 인스턴스 생성
quest_map = QuestMap()

# 퀘스트 추가
quest_map.add_quest(
    quest_id="Q001",
    name="Find the Lost Sword",
    description="Retrieve the legendary sword lost in the Forbidden Forest.",
    rewards={"experience": 500, "items": ["Legendary Sword"]},
    metadata={"difficulty": "Hard", "location": "Forbidden Forest"}
)

quest_map.add_quest(
    quest_id="Q002",
    name="Defend the Village",
    description="Help the villagers defend their homes from the goblin invasion.",
    rewards={"experience": 300, "items": ["Healing Potion"]},
    metadata={"difficulty": "Medium", "location": "East Village"}
)

# 퀘스트 상태 업데이트
updated_quest = quest_map.update_quest_status("Q001", "In Progress")
print("Updated Quest:", updated_quest)

# 특정 상태의 퀘스트 필터링 (예: In Progress 상태)
in_progress_quests = quest_map.filter_by_status("In Progress")
print("In Progress Quests:", in_progress_quests)

# 특정 ID의 퀘스트 조회
quest_details = quest_map.get_quest("Q002")
print("Details of Quest Q002:", quest_details)

출력 예시

Updated Quest: {
    'quest_id': 'Q001', 'name': 'Find the Lost Sword', 'description': 'Retrieve the legendary sword lost in the Forbidden Forest.',
    'rewards': {'experience': 500, 'items': ['Legendary Sword']},
    'status': 'In Progress', 'metadata': {'difficulty': 'Hard', 'location': 'Forbidden Forest'}
}

In Progress Quests: [
    {'quest_id': 'Q001', 'name': 'Find the Lost Sword', 'description': 'Retrieve the legendary sword lost in the Forbidden Forest.',
     'rewards': {'experience': 500, 'items': ['Legendary Sword']}, 'status': 'In Progress', 'metadata': {'difficulty': 'Hard', 'location': 'Forbidden Forest'}}
]

Details of Quest Q002: {
    'quest_id': 'Q002', 'name': 'Defend the Village', 'description': 'Help the villagers defend their homes from the goblin invasion.',
    'rewards': {'experience': 300, 'items': ['Healing Potion']},
    'status': 'Not Started', 'metadata': {'difficulty': 'Medium', 'location': 'East Village'}
}

코드 설명

  • add_quest 메서드: 새로운 퀘스트 카드를 생성하여 퀘스트 맵에 추가합니다.
  • update_quest_status 메서드: quest_id를 통해 퀘스트를 찾고, new_status로 상태를 업데이트합니다.
  • filter_by_status 메서드: 특정 상태에 해당하는 모든 퀘스트를 필터링하여 반환합니다.
  • get_quest 메서드: 특정 quest_id에 해당하는 퀘스트 카드를 반환합니다.

이 구조의 장점

  • 퀘스트 관리 효율성: 퀘스트 상태를 일괄 관리하고 필터링할 수 있어 관리가 용이합니다.
  • 가독성: 퀘스트 데이터가 각각의 카드로 구성되어 있어 코드를 읽고 이해하기가 쉽습니다.
  • 확장성: 새로운 필드를 추가하거나 필터링 조건을 다양하게 확장할 수 있어 게임 설계에 유연하게 대응할 수 있습니다.

이 구조는 게임 내 다양한 퀘스트를 효과적으로 관리하고, 플레이어가 진행 상황을 쉽게 파악할 수 있도록 돕습니다.

+ Recent posts