# Leap **Repository Path**: hw__2004/Leap ## Basic Information - **Project Name**: Leap - **Description**: this is out teamwork - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-04-08 - **Last Updated**: 2025-05-06 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # GROUP NAME :Leap #### Number: Star(郭星源) id:2023902044 Wren(何唯) id:2023905416 kale(王泉智)id:2023905335 #### Game Introduce Game Background In the forsaken lands of Dragon's Labyrinth, an ancient evil stirs beneath the ruins of a once-glorious kingdom. The dreaded dragon Ignarax has awakened, corrupting the land and summoning monstrous allies to guard its lair. As a brave adventurer, you must navigate a perilous 3x3 dungeon grid, battling enemies, collecting powerful relics, and ultimately confronting the dragon to restore peace. Only by defeating Ignarax can you claim victory and escape the labyrinth alive. Classes Choose your hero’s class, each with unique strengths and playstyles: Warrior Role: Tank/Melee Bruiser Base Stats: Health: 120 Attack: 15 Defense: 10 Special Trait: High survivability, ideal for players who prefer a balanced frontline role. Mage Role: Glass Cannon Base Stats: Health: 80 Attack: 20 Defense: 5 Special Trait: Devastating magic attacks but vulnerable to heavy hits. Perfect for risk-takers. Rogue Role: Agile Striker Base Stats: Health: 100 Attack: 18 Defense: 7 Special Trait: 20% critical strike chance, dealing double damage on lucky hits. Items Collect and use items to enhance your abilities: Health Potion: Restores +20 HP. Sharp Blade: Permanently increases Attack +5. Iron Shield: Permanently boosts Defense +5. Poison Dagger: Grants Attack +8 but reduces Defense -2 (high-risk, high-reward). Dragon Scale (Boss Drop): Legendary item granting HP +50, Attack +10, and Defense +10. Enemies Face deadly foes with unique behaviors: Goblin Stats: HP 50, Attack 8, Defense 3 Behavior: Basic melee attacker. Drops Rusty Sword (Attack +5). Skeleton Stats: HP 70, Attack 10, Defense 5 Behavior: Resilient undead warrior. Drops Bone Armor (Defense +8). Dragon (Boss) Stats: HP 200, Attack 20, Defense 10 Skills: Fire Breath: Deals massive damage to players with low defense. Enrage: At 50% HP, gains +50% Attack for the rest of the fight. Loot: Dragon Scale (game’s most powerful item). Combat Mechanics Turn-Based System: Players and enemies take alternating turns. Critical Strikes (Rogue Only): 20% chance to deal double damage. Enemy Skills: Enemies below 30% HP may heal themselves (+20 HP) every 3 turns. Bosses enter Enraged Mode at 50% HP, boosting their attack. Escape Mechanic: 30% chance to flee combat. Failure triggers an enemy counterattack. Victory & Defeat Victory Condition: Defeat the Dragon in the Boss Room to trigger the ending cutscene and win the game. Defeat Condition: If your HP reaches 0, the game ends with a "Game Over" screen. How to Play Compile the Game: bash g++ -std=c++17 main.cpp GameManager.cpp Player.cpp Enemy.cpp Item.cpp Room.cpp GameMap.cpp -o game Run the Executable: Linux/macOS: ./game Windows: game.exe Controls: Navigate menus using number keys. Move between rooms with directions: north, south, east, west. In combat: Attack, Use Items, or Escape. Embark on your journey, strategize with your class’s strengths, and claim glory in Dragon’s Labyrinth! 🐉⚔️ ### `ICharacter` Class (Interface Class) The `ICharacter` is an abstract base class, which can also be considered as an interface class. It defines the interfaces for the basic behaviors and attributes of characters. Other specific character classes need to implement these interfaces. #### Attributes None. As an interface class, it usually doesn't define specific data members. #### Methods **Constructor and Destructor Functions** - `ICharacter()`: The default constructor. - `ICharacter(const ICharacter&)`: The copy constructor. - `ICharacter& operator=(const ICharacter&)`: The copy assignment operator. - `virtual ~ICharacter()`: The virtual destructor, ensuring that derived class objects can release resources correctly. **Core Methods** - `virtual bool isAlive() const = 0`: Determine whether the character is alive. - `virtual void takeDamage(int damage) = 0`: Make the character receive damage. - `virtual void attack(ICharacter& target) = 0`: The character launches an attack on the target. **Attribute Retrieval Methods** - `virtual std::string getName() const = 0`: Get the character's name. - `virtual unsigned getHealth() const = 0`: Get the character's health value. - `virtual unsigned getAttack() const = 0`: Get the character's attack power. - `virtual unsigned getDefense() const = 0`: Get the character's defense power. **Item Management Methods** - `virtual void addItem(Item* item) = 0`: Add an item to the character. - `virtual void displayInventory() const = 0`: Display the character's inventory. **Drop and Cloning Methods** - `virtual std::unique_ptr generateDrop() const = 0`: Generate the items dropped by the character. - `virtual std::unique_ptr clone() const = 0`: Clone the character. ### `Item` Class (Entity Class) The `Item` class represents the items in the game, including the basic attributes of the items and the methods for operating on the items. #### Attributes - `name_`: Of type `std::string`, it is the name of the item. - `healthBoost_`: Of type `int`, it is the increase in health provided by the item. - `attackBoost_`: Of type `int`, it is the increase in attack power provided by the item. - `defenseBoost_`: Of type `int`, it is the increase in defense power provided by the item. - `type_`: Of the `Item::Type` enumeration type, it is the type of the item, such as potions, weapons, etc. #### Methods **Constructor and Destructor Functions** - `Item()`: The default constructor. - `Item(const std::string& name, int healthBoost, int attackBoost, int defenseBoost, Type type)`: The constructor with parameters. - `Item(const Item& other)`: The copy constructor. - `Item& operator=(const Item& other)`: The copy assignment operator. - `~Item()`: The destructor. **Operation Methods** - `void apply(ICharacter& character) const`: Apply the effect of the item to the character. - `std::string getName() const`: Get the name of the item. - `int getHealthBoost() const`: Get the increase in health provided by the item. - `int getAttackBoost() const`: Get the increase in attack power provided by the item. - `int getDefenseBoost() const`: Get the increase in defense power provided by the item. - `Type getType() const`: Get the type of the item. ### `Player` Class (Entity Class, Inheriting from `ICharacter`) The `Player` class represents the player character in the game. It implements the `ICharacter` interface and adds attributes and methods specific to the player. #### Attributes - `name_`: Of type `std::string`, it is the player's name. - `class_`: Of the `Player::Class` enumeration type, it is the player's class. - `health_`: Of type `unsigned`, it is the player's current health. - `maxHealth_`: Of type `unsigned`, it is the player's maximum health. - `attack_`: Of type `unsigned`, it is the player's attack power. - `defense_`: Of type `unsigned`, it is the player's defense power. - `exp_`: Of type `unsigned`, it is the player's current experience points. - `expToNextLevel_`: Of type `unsigned`, it is the experience points required to level up to the next level. - `level_`: Of type `unsigned`, it is the player's current level. - `criticalChance_`: Of type `double`, it is the player's critical strike probability. - `inventory_`: Of type `std::vector>`, it is the player's inventory. - `equippedItems_`: Of type `std::vector>`, it is the list of items equipped by the player. #### Methods **Constructor and Destructor Functions** - `Player()`: The default constructor. - `Player(const std::string& name, Class playerClass)`: The constructor with parameters. - `Player(const Player& other)`: The copy constructor. - `Player& operator=(const Player& other)`: The copy assignment operator. - `~Player() override`: The destructor, overriding the base class destructor. **`ICharacter` Interface Implementation Methods** - `bool isAlive() const override`: Determine whether the player is alive. - `void takeDamage(int damage) override`: The player takes damage. - `void attack(ICharacter& target) override`: The player attacks the target. - `std::string getName() const override`: Get the player's name. - `unsigned getHealth() const override`: Get the player's current health. - `unsigned getAttack() const override`: Get the player's attack power. - `unsigned getDefense() const override`: Get the player's defense power. - `void addItem(Item* item) override`: Add an item to the player. - `void displayInventory() const override`: Display the player's inventory. **Unique Methods** - `const std::vector>& getInventory() const`: Get the player's inventory. - `std::unique_ptr generateDrop() const override`: Generate the items dropped by the player. - `std::unique_ptr clone() const override`: Clone the player. - `void gainExp(unsigned exp)`: The player gains experience points. - `void levelUp()`: The player levels up. - `void showStats() const`: Display the player's attributes. - `bool tryEscape()`: The player tries to escape. - `void useSkill()`: The player uses a skill. - `void useItem(int index)`: The player uses the item at the specified index. - `void equipItem(int index)`: The player equips the item at the specified index. - `void unequipItem(int index)`: The player unequips the item at the specified index. - `unsigned calculateDamage(unsigned targetDefense) const`: Calculate the damage the player deals to the target. - `unsigned getInventorySize() const`: Get the number of items in the player's inventory. ### `Enemy` Class (Entity Class, Inheriting from `ICharacter`) The `Enemy` class represents the enemy characters in the game. It implements the `ICharacter` interface and adds attributes and methods specific to enemies. #### Attributes - `name_`: Of type `std::string`, it is the enemy's name. - `health_`: Of type `unsigned`, it is the enemy's health. - `attack_`: Of type `unsigned`, it is the enemy's attack power. - `defense_`: Of type `unsigned`, it is the enemy's defense power. - `expReward_`: Of type `unsigned`, it is the experience reward for defeating the enemy. - `skillCooldown_`: Of type `int`, it is the cooldown time of the enemy's skill. - `isEnraged_`: Of type `bool`, it indicates whether the enemy is in an enraged state. - `lastActionLog_`: Of type `std::string`, it is the enemy's last action log. #### Methods **Constructor and Destructor Functions** - `Enemy()`: The default constructor. - `Enemy(const std::string& name, unsigned h, unsigned a, unsigned d, unsigned exp)`: The constructor with parameters. - `Enemy(const Enemy& other)`: The copy constructor. - `Enemy& operator=(const Enemy& other)`: The copy assignment operator. - `~Enemy() override`: The destructor, overriding the base class destructor. **`ICharacter` Interface Implementation Methods** - `bool isAlive() const override`: Determine whether the enemy is alive. - `void takeDamage(int damage) override`: The enemy takes damage. - `void attack(ICharacter& target) override`: The enemy attacks the target. - `std::string getName() const override`: Get the enemy's name. - `unsigned getHealth() const override`: Get the enemy's health. - `unsigned getAttack() const override`: Get the enemy's attack power. - `unsigned getDefense() const override`: Get the enemy's defense power. - `void addItem(Item* item) override`: Add an item to the enemy. - `void displayInventory() const override`: Display the enemy's inventory. **Unique Methods** - `std::unique_ptr generateDrop() const override`: Generate the items dropped by the enemy. - `std::unique_ptr clone() const override`: Clone the enemy. - `unsigned getExpReward() const`: Get the experience reward for defeating the enemy. - `void applySpecialSkill()`: The enemy applies a special skill. - `unsigned calculateDamage(unsigned targetDefense) const`: Calculate the damage the enemy deals to the target. - `std::string useSkill(ICharacter& target)`: The enemy uses a skill to attack the target. - `const std::string& getLastActionLog() const`: Get the enemy's last action log. **Factory Methods** - `static std::unique_ptr createGoblin()`: Create a goblin enemy. - `static std::unique_ptr createBoss()`: Create a boss enemy. - `static std::unique_ptr createSkeleton()`: Create a skeleton enemy. - `static std::unique_ptr createGoblinArcher()`: Create a goblin archer enemy. ### `GameMap` Class (Management Class) The `GameMap` class is responsible for managing the game map, including the layout of rooms and the player's movement on the map. #### Attributes - `rooms_`: Of type `std::vector>`, it is a two-dimensional vector storing the rooms on the map. - `currentRoom_`: Of type `Room*`, it is a pointer pointing to the room where the player is currently located. - `playerPos_`: Of type `std::pair`, it is the player's position on the map. #### Methods **Constructor and Destructor Functions** - `GameMap()`: The default constructor. - `GameMap(const GameMap& other)`: The copy constructor. - `GameMap& operator=(const GameMap& other)`: The copy assignment operator. - `~GameMap()`: The destructor. **Operation Methods** - `Room* getCurrentRoom() const`: Get the room where the player is currently located. - `bool movePlayer(const std::string& direction)`: The player moves in the specified direction. - `void printMap() const`: Print the map. - `bool isInBossRoom() const`: Determine whether the player is in the boss room. ### `GameManager` Class (Management Class) The `GameManager` class is responsible for managing the entire game process, including the game's startup, loop, battle handling, etc. #### Attributes - `player_`: Of type `Player`, it is the player object in the game. - `gameMap_`: Of type `GameMap`, it is the game map object. - `lastCombatLog_`: Of type `std::string`, it is the log of the last battle. #### Methods **Constructor and Destructor Functions** - `GameManager()`: The default constructor. - `GameManager(const GameManager&)`: The copy constructor. - `GameManager& operator=(const GameManager&)`: The copy assignment operator. - `~GameManager()`: The destructor. **Operation Methods** - `void startGame()`: Start the game. - `void showCharacterInfo()`: Display the player character's information. - `void gameLoop()`: The main game loop. - `void showMainMenu()`: Display the game's main menu. - `void handleCombat(Enemy& enemy)`: Handle the battle with the enemy. - `void handleMovement()`: Handle the player's movement. ### `Room` Class (Entity Class) The `Room` class is an entity class that represents the rooms in the game. It contains various attributes of the room and methods for operating on the elements within the room, such as enemies and items. #### Attributes - `type_`: It is of the `Room::Type` enumeration type, which is used to indicate the type of the room. The possible values include `START` (Starting Room), `COMBAT` (Combat Room), `TREASURE` (Treasure Room), `BOSS` (Boss Room), `TRAP` (Trap Room), and `HEALING` (Healing Room). - `desc_`: It is of the `std::string` type and is used to store the description information of the room, which describes the characteristics or functions of the room, etc. - `enemy_`: It is of the `std::unique_ptr` type, which is a smart pointer pointing to the enemy object in the room (if any). Since the enemy is a type of character, an `ICharacter` type pointer is used. - `loot_`: It is of the `std::vector>` type, which is a vector container used to store the treasure items in the room. Each element is a smart pointer to the `Item` type. - `north_`: It is of the `Room*` type, which is a pointer pointing to the room adjacent to the north of this room, with an initial value of `nullptr`. - `east_`: It is of the `Room*` type, which is a pointer pointing to the room adjacent to the east of this room, with an initial value of `nullptr`. - `south_`: It is of the `Room*` type, which is a pointer pointing to the room adjacent to the south of this room, with an initial value of `nullptr`. - `west_`: It is of the `Room*` type, which is a pointer pointing to the room adjacent to the west of this room, with an initial value of `nullptr`. #### Methods **Constructor and Destructor Functions** - `Room()`: The default constructor is used to initialize the `Room` object. - `Room(Type type, const std::string& desc)`: The constructor with parameters initializes the room object according to the passed-in room type and description information. - `Room(const Room& other)`: The copy constructor is used to copy an existing `Room` object. - `Room& operator=(const Room& other)`: The copy assignment operator is used to assign one `Room` object to another `Room` object. - `~Room() = default`: The destructor uses the default implementation, which is used to release the resources occupied by the `Room` object. **Public Methods** - `Type getType() const`: Obtain the type of the room, and the return value is of the `Room::Type` enumeration type. `const` indicates that this function will not modify the state of the room object. - `void clearEnemy()`: Clear the enemy in the room, that is, release the enemy object pointed to by the `enemy_` smart pointer. - `std::string getDesc() const`: Obtain the description information of the room, and the return value is of the `std::string` type. `const` indicates that this function will not modify the state of the room object. - `void connect(Room* north, Room* east, Room* south, Room* west)`: Set the connection relationship between this room and the adjacent rooms. The parameters are pointers to the rooms adjacent to the north, east, south, and west respectively. - `void enter(ICharacter& player)`: Handle the logic of a character entering the room. The parameter is a reference of the `ICharacter` type, representing the character entering the room. - `void generateEnemy()`: Generate an enemy in the room, that is, create an enemy object and assign it to the `enemy_` smart pointer. - `void generateLoot()`: Generate treasure items in the room and add the generated items to the `loot_` vector container. - `Room* getNorth() const`: Obtain the pointer to the room adjacent to the north of this room, and the return value is of the `Room*` type. `const` indicates that this function will not modify the state of the room object. - `Room* getEast() const`: Obtain the pointer to the room adjacent to the east of this room, and the return value is of the `Room*` type. `const` indicates that this function will not modify the state of the room object. - `Room* getSouth() const`: Obtain the pointer to the room adjacent to the south of this room, and the return value is of the `Room*` type. `const` indicates that this function will not modify the state of the room object. - `Room* getWest() const`: Obtain the pointer to the room adjacent to the west of this room, and the return value is of the `Room*` type. `const` indicates that this function will not modify the state of the room object. - `Enemy* getEnemy() const`: Obtain the pointer to the enemy in the room, and the return value is of the `Enemy*` type. `const` indicates that this function will not modify the state of the room object. - `std::vector>& getLoot()`: Obtain the reference to the vector container of the treasure items in the room, and the return value is of the `std::vector>&` type. Through this reference, operations can be performed on the `loot_`.