# Queen never cry **Repository Path**: GuoKexin-1/queen-never-cry ## Basic Information - **Project Name**: Queen never cry - **Description**: Katie Zima Zander - **Primary Language**: C++ - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-04-08 - **Last Updated**: 2026-01-14 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Queen never cry Group members 郭可馨 Katie 张鸣宇 Zima 张睿宸 Zander ## About the code ### Player class The Player class inherits from Character. It adds an experience system and an upgrade mechanism. Players gain experience by attacking enemies, and upon reaching the experience threshold, they can upgrade and receive attribute enhancements. The + operator is overloaded for attacks, and += is used for adding items. It includes functions such as status display, experience acquisition, and upgrade check, forming the basic player system of an RPG game. ``` Player::Player(const std::string& name, const std::string& desc) : Character(name, desc, 30, 8, 4), experience(0), level(1) { } ``` >Initialize the player character and inherit the Character class. Set the initial health value (30), attack power (8), and defense power (4). ### Game Class This class implements the main logic of the game, including room initialization, generation of items and enemies, player movement, combat system, menu interaction and victory/defeat determination, thus forming a complete framework of an RPG game. ``` void Game::connectRooms() { rooms[0]->setExit("East", rooms[1]); } void Game::initItems() { rooms[0]->addItem(new Item("Magic Amulet", "...", 10, 2, 0)); } void Game::initEnemies() { rooms[3]->addEnemy(new Boss("Ancient Guardian", "...", 25, 5, 2, 200, 5)); } ``` > Set the connection directions between rooms (such as east or north). Assign items and enemies to the room. The Boss awaits the final battle in the Treasure Room. ### Room class This calss implements the core logic of the game room, including room attribute management (healing/inflicting damage/ treasure), random item generation, enemy management, exit connection and room effect application, which constitutes the foundation of the game map system. ``` enum class RoomType { NORMAL, // Normal room HEALING, // Healing room (restores health each turn) DAMAGING, // Damaging room (causes damage each turn) TREASURE // Treasure room (has better items) }; ``` > We have four type of room,Each room corresponds to different influences on the players. ### Character class This class includes methods for character attributes (name, description, health points, attack power, defense power), combat functions (attack, injury determination), item management (adding/displaying item bar), etc. The constructor initializes character attributes, and the destructor releases item memory. The main functions include life status check, damage handling with defense calculation, collection of attribute enhancement items, and display of character information. ``` bool Character::takeDamage(unsigned damage) { // Calculate actual damage, considering defense unsigned actualDamage = (damage > defense) ? (damage - defense) : 0; // Deduct health points if (actualDamage >= health) { health = 0; return false; // Character died } else { health -= actualDamage; return true; // Character still alive } } ``` >This ensures that the battles in the game are dynamic and interesting, because the defense power of the characters will affect the outcome of the battles, making players need to consider how to enhance the defense power of their characters to better cope with the battles. ### Enemy class This class implements the attack and defense logic for different enemies (gnomes, ghosts, BOSS), including critical hits, dodges and berserk mechanisms. ``` bool Enemy::attack(ICharacter& target) { bool result = Character::attack(target); if (result) { std::cout << getName() << " attacked you!" << std::endl; if (target.getDefense() > 0) { std::cout << "Your defense absorbed some damage!" << std::endl; } std::cout << "You took " << ((getAttack() > target.getDefense()) ? (getAttack() - target.getDefense()) : 0) << " damage!" << std::endl; std::cout << "Your HP: " << target.getHealth() << "/" << target.getMaxHealth() << std::endl; } return result; } ``` >It first invokes the attack logic of the base class (Character::attack) to check whether the attack is successful.If the attack is successful, it will output the attack information, including the damage received by the target character (attack power minus defense power) and the current health value of the target.The return value is of boolean type, indicating whether the attack is successful. ### Main class This class creates a game instance and run it. After the game is over, wait for the user to press a key to exit the program.