diff --git a/Combat.cpp b/Combat.cpp new file mode 100644 index 0000000..eb7ae1a --- /dev/null +++ b/Combat.cpp @@ -0,0 +1,85 @@ +#include "Combat.h" +#include +#include // for setw + +using namespace std; + +void Combat::combatTurn(BaseCharacter& player, BaseCharacter& enemy) { + int round = 1; // Para rastrear o número de rodadas + + + + // **************************************************************************** + // **************************************************************************** + // **************************************************************************** + // **************************************************************************** + // **************************************************************************** + // **************************************************************************** + // **************************************************************************** + // **************************************************************************** + // SÓ SETAR A VIDA DO INIMIGO PARA ENTRAR NO LOOP, ELE JÁ ESTAVA ENTRANDO MORTO + enemy.setHealth(100); + + + + //Só para debug + //cout << "After " << enemy.getName() << " attacks: " << endl; + //cout << player.getName() << " Hero is alive?: " << player.isAlive() << endl; + //cout << enemy.getName() << " Enemy is alive?: " << enemy.isAlive() << endl << endl; + + cout << "Combat turn initiated between " << player.getName() << " and " << enemy.getName() << endl; + + while (player.isAlive() && enemy.isAlive()) { + cout << "\n---- Round " << round << " ----" << endl; + + cout << "Pressione Enter para atacar..." << endl; + cin.get(); // Aguardar o usuário pressionar Enter + + // Player attacks enemy + cout << player.getName() << " attacks " << enemy.getName() << endl; + player.attack(enemy); + cout << "After attack, " << enemy.getName() << " is alive: " << enemy.isAlive() << endl; + + if (enemy.isAlive()) { + // Enemy attacks player + cout << "Pressione Enter para atacar..." << endl; + cin.get(); // Aguardar o usuário pressionar Enter + + cout << enemy.getName() << " attacks " << player.getName() << endl; + enemy.attack(player); + cout << "After attack, " << player.getName() << " is alive: " << player.isAlive() << endl; + } + + // Exibir status após cada rodada de ataques + cout << "\n---- Status Apos Rodada de Ataques ----" << endl; + player.displayStatus(); + enemy.displayStatus(); + + round++; + } + + + //Só para debug + // cout << "After " << enemy.getName() << " attacks: " << endl; + // cout << player.getName() << " Hero is alive?: " << player.isAlive() << endl; + // cout << enemy.getName() << " Enemy is alive?: " << enemy.isAlive() << endl; + + + + cout << "\n=============================================\n"; + cout << " RESULTADO \n"; + cout << "=============================================\n"; + + if (player.isAlive()) { + cout << setw(20) << player.getName() << " venceu o combate!\n"; + } + else if (enemy.isAlive()) { + cout << setw(20) << enemy.getName() << " venceu o combate!\n"; + } + else { + cout << setw(20) << "Ambos os personagens morreram. Empate!\n"; + } + + cout << "=============================================\n"; + +} diff --git a/Combat.h b/Combat.h new file mode 100644 index 0000000..cf70fb8 --- /dev/null +++ b/Combat.h @@ -0,0 +1,12 @@ + +#ifndef COMBAT_H +#define COMBAT_H + +#include "../una-rpg-cpp/src/Character/BaseCharacter.h" + +class Combat { +public: + static void combatTurn(BaseCharacter& player, BaseCharacter& enemy); +}; + +#endif diff --git a/src/Character/BaseCharacter.cpp b/src/Character/BaseCharacter.cpp index 14b8692..894ea9b 100644 --- a/src/Character/BaseCharacter.cpp +++ b/src/Character/BaseCharacter.cpp @@ -4,11 +4,13 @@ using namespace std; void BaseCharacter::displayStatus() { - cout << "Name: " << characterName << "\nHealth: " << health << "\nStrength: " << strength << "\nDefence: " << defence << "\nDexterity: " << dexterity < 0; } + + ////attack function + virtual void attack(BaseCharacter& target) { + int damage = strength - target.getDefence(); + if (damage < 1) damage = 1; + cout << damage; + int vida = target.getHealth(); + target.damageTaken(damage); + cout << endl < +#include +#include "../Character/Hero/Class/Archer.h" +#include "../Character/Hero/Class/Mage.h" +#include "../Character/Hero/Class/Tank.h" +#include "../Character/Hero/Class/Warrior.h" +#include "../Character/Hero/Hero.h" +#include "../Character/Enemy/Enemy.h" +#include "../../Combat.h" +#include + +using namespace std; + +void Game::startNewGame() { + cout << "Starting a new game..." << endl; + chooseClass(); +} + +void Game::showCredits() { + cout << "Game developed by" << endl; +} + +void Game::exitGame() { + cout << "Exiting game. Thank you for playing!" << endl; +} + +void Game::chooseClass() { + system("cls");// limpa a tela + cout << "===== Choose class =====" << endl; + cout << "1. Archer" << endl; + cout << "2. Mage" << endl; + cout << "3. Tank" << endl; + cout << "4. Warrior" << endl; + cout << "Please select an option (1-4): "; + + int choice; + string name; + std::cin >> choice; + std::cin.ignore(); // Ignore newline character left in the buffer by std::cin + + system("cls");// limpa a tela + + Hero* hero = nullptr; + Hero* tank = nullptr; + + switch (choice) { + case 1: { + cout << "Enter the name for your Archer: "; + getline(cin, name); + hero = new Archer(name); + cout << "You have created an Archer named " << name << "." << endl; + break; + } + case 2: { + cout << "Enter the name for your Mage: "; + getline(cin, name); + hero = new Mage(name); + cout << "You have created a Mage named " << name << "." << endl; + break; + } + case 3: { + cout << "Enter the name for your Tank: "; + getline(cin, name); + hero = new Tank(name); + cout << "You have created a Tank named " << name << "." << endl; + break; + } + case 4: { + cout << "Enter the name for your Warrior: "; + getline(cin, name); + hero = new Warrior(name); + cout << "You have created a Warrior named " << name << "." << endl; + break; + } + default: + std::cout << "Invalid option. Please try again." << std::endl; + return; // exit the function if the input is invalid + } + + hero->applyBonus(); + hero->displayStatus(); + + // For demonstration, let's create a dummy Tank for the combat example + tank = new Tank("DummyTank"); + + system("cls"); // limpa a tela + + std::cout << "Starting combat..." << std::endl; + + Combat combat; + + // Example battles + combat.combatTurn(*hero, *tank); // Pass by reference, not by pointer + + cout << "Combat finished.\n\n\n"; + + // Clean up dynamically allocated memory + delete hero; + delete tank; +} diff --git a/src/Interface/Game.h b/src/Interface/Game.h new file mode 100644 index 0000000..45e112b --- /dev/null +++ b/src/Interface/Game.h @@ -0,0 +1,13 @@ +#ifndef GAME_H +#define GAME_H + +class Game { +public: + void startNewGame(); + void showCredits(); + void exitGame(); + + void chooseClass(); +}; + +#endif // GAME_H \ No newline at end of file diff --git a/src/Interface/Menu.cpp b/src/Interface/Menu.cpp new file mode 100644 index 0000000..57cb246 --- /dev/null +++ b/src/Interface/Menu.cpp @@ -0,0 +1,44 @@ +#include +#include +#include "Menu.h" + +#pragma execution_character_set( "utf-8" ) +#define _WIN32_WINNT 0x0500 + +using namespace std; + +void Menu::displayMenu() { + SetConsoleOutputCP(65001); + + cout << "===== RPG Game Menu =====" << endl; + cout << "1. Start New Game" << endl; + cout << "2. Credits" << endl; + cout << "3. Exit" << endl; + cout << "Please select an option (1-3): "; + + //HWND console = GetConsoleWindow(); + //RECT r; + //GetWindowRect(console, &r); //stores the console's current dimension + + //HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); + ////SetConsoleTextAttribute(hConsole, 10); + + //cout << "___ ___ _ _ _ ____________ _____" << endl; + //cout << "| \\/ | | (_) | | | ___ \\ ___ \\ __ \\" << endl; + //cout << "| . . | ___ __| |_ _____ ____ _| | | |_/ / |_/ / | \\/" << endl; + //cout << "| |\\/| |/ _ \\/ _` | |/ _ \\ \\ / / _` | | | /| __/| | __ " << endl; + //cout << "| | | | __/ (_| | | __/\\ V / (_| | | | |\\ \\| | | |_\\ \\" << endl; + //cout << "\\_| |_/\\___|\\__,_|_|\\___| \\_/ \\__,_|_| \\_| \\_\\_| \\____/" << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl; + + //cout << " _____________________________________________________________________________________________" << endl; + //cout << "| . . . |" << endl; + //cout << "| .-' : :':'-. | asfasfasfsafsa sa fsa fasf asfsafsafasfsa" << endl; + //cout << "| .' __/ \\__ : | asfasfasfasfasf asf sa fsa fas" << endl; + //cout << "| / / : | asfsafsa fas fsa fsa fsa f " << endl; + //cout << "| ( C O O : | " << endl; + //cout << "| \\ | > : |" << endl; + //cout << "| \\ | ___ : |" << endl; + //cout << "| :: . |" << endl; + //cout << "| / \\_______/ | [CONTINUAR]" << endl; + //cout << "|_____________________|_______________________________________________________________________" << endl; +} \ No newline at end of file diff --git a/src/Interface/Menu.h b/src/Interface/Menu.h new file mode 100644 index 0000000..e2a01e5 --- /dev/null +++ b/src/Interface/Menu.h @@ -0,0 +1,20 @@ +#ifndef MENU_H +#define MENU_H + +//#include "Screen.h" + +using namespace std; + +class Menu +{ +private: + +public: + //Screen screen; + //Hero(const string& name, int health = 0, int strength = 0, int defence = 0, int dexterity = 0) + // : BaseCharacter(name, health, strength, defence, dexterity), gold(0), experience(0) {} + + void displayMenu(); +}; + +#endif \ No newline at end of file diff --git a/src/Interface/Screen.cpp b/src/Interface/Screen.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/Interface/Screen.h b/src/Interface/Screen.h new file mode 100644 index 0000000..d59dc45 --- /dev/null +++ b/src/Interface/Screen.h @@ -0,0 +1,17 @@ +class Screen +{ +public: + Screen(); + ~Screen(); + +private: + +}; + +Screen::Screen() +{ +} + +Screen::~Screen() +{ +} \ No newline at end of file diff --git a/src/una-rpg-cpp.cpp b/src/una-rpg-cpp.cpp index 86cc745..c64a26b 100644 --- a/src/una-rpg-cpp.cpp +++ b/src/una-rpg-cpp.cpp @@ -7,90 +7,116 @@ #include "Database/FirebaseDataFetcher.h" #include +#include "Interface/Menu.h" +#include "Interface/Game.h" + using namespace std; int main() { - vector heroDialogues = fetchIntroductionDialogues(); - - - ////Obt�m a vers�o do banco de dados do Firebase - float version = fetchDatabaseVersion(); - - ////Verifica se a vers�o foi obtida com sucesso - if (version != -1) - { - cout << "Database version: " << version << endl; - } - else - { - cerr << "Failed to obtain the database version." << endl; - } - - // Obtem os nomes das armas e coloca no vetor - vector weaponNames = fetchWeaponsNames(); - - // Verifica se os dados foram obtidos com sucesso - if (!weaponNames.empty() && !heroDialogues.empty()) - { - cout << "Available weapons in the database:" << endl; - for (const auto &name : weaponNames) - { - cout << "- " << name << endl; - } - - cout << "\n\nDialogues:" << endl; - for (const auto& dialogue : heroDialogues) - { - cout << "- " << dialogue << endl; - } - } - else - { - cerr << "Failed to retrieve database." << endl; - } - - Hero hero("Vitor", 0, 0, 0); - Tank tank("Titan", 0, 0, 0); - - AttackBoostItem sword("Sword", "A sharp blade", 50, 10); - DefenseBoostItem shield("Shield", "Protects against attacks", 30, 5); - HealingItem potion("Potion", "Heals health", 20, 10); - - hero.addItem(&sword); - hero.addItem(&shield); - hero.addItem(&potion); - - cout << "\n---- Initial Status ----\n" - << endl; - hero.displayStatus(); - - cout << "\n---- Hero Status After Bonus ----\n" - << endl; - hero.applyBonus(); - hero.displayStatus(); - - cout << "\n---- Using Items ----\n" - << endl; - for (Item *item : hero.getInventory()) - { - item->use(hero); - } - - cout << "\n---- Hero Status After Bonus ----\n" - << endl; - hero.applyBonus(); - hero.displayStatus(); - - cout << "\n---- Tank Initial Status ----\n" - << endl; - tank.displayStatus(); - tank.applyBonus(); - cout << "\n---- Tank Status After Applying Bonus ----\n" - << endl; - tank.displayStatus(); - - system("pause"); - - return 0; + Menu menu; + Game game; + int choice; + + while (true) { + menu.displayMenu(); + std::cin >> choice; + + switch (choice) { + case 1: + game.startNewGame(); + break; + case 2: + game.showCredits(); + break; + case 3: + game.exitGame(); + return 0; // Saia do programa + default: + std::cout << "\n\nInvalid option. Please try again." << std::endl; + } + } + + vector heroDialogues = fetchIntroductionDialogues(); + + + ////Obt�m a vers�o do banco de dados do Firebase + float version = fetchDatabaseVersion(); + + ////Verifica se a vers�o foi obtida com sucesso + if (version != -1) + { + cout << "Database version: " << version << endl; + } + else + { + cerr << "Failed to obtain the database version." << endl; + } + + // Obtem os nomes das armas e coloca no vetor + vector weaponNames = fetchWeaponsNames(); + + // Verifica se os dados foram obtidos com sucesso + if (!weaponNames.empty() && !heroDialogues.empty()) + { + cout << "Available weapons in the database:" << endl; + for (const auto &name : weaponNames) + { + cout << "- " << name << endl; + } + + cout << "\n\nDialogues:" << endl; + for (const auto& dialogue : heroDialogues) + { + cout << "- " << dialogue << endl; + } + } + else + { + cerr << "Failed to retrieve database." << endl; + } + + Hero hero("Vitor", 0, 0, 0); + Tank tank("Titan", 0, 0, 0); + + AttackBoostItem sword("Sword", "A sharp blade", 50, 10); + DefenseBoostItem shield("Shield", "Protects against attacks", 30, 5); + HealingItem potion("Potion", "Heals health", 20, 10); + + hero.addItem(&sword); + hero.addItem(&shield); + hero.addItem(&potion); + + cout << "\n---- Initial Status ----\n" + << endl; + hero.displayStatus(); + + cout << "\n---- Hero Status After Bonus ----\n" + << endl; + hero.applyBonus(); + hero.displayStatus(); + + cout << "\n---- Using Items ----\n" + << endl; + for (Item *item : hero.getInventory()) + { + item->use(hero); + } + + cout << "\n---- Hero Status After Bonus ----\n" + << endl; + hero.applyBonus(); + hero.displayStatus(); + + cout << "\n---- Tank Initial Status ----\n" + << endl; + tank.displayStatus(); + tank.applyBonus(); + cout << "\n---- Tank Status After Applying Bonus ----\n" + << endl; + tank.displayStatus(); + + system("pause"); + + return 0; } diff --git a/una-rpg-cpp.vcxproj b/una-rpg-cpp.vcxproj index 79979e4..789b349 100644 --- a/una-rpg-cpp.vcxproj +++ b/una-rpg-cpp.vcxproj @@ -165,6 +165,7 @@ + @@ -174,6 +175,9 @@ + + + @@ -181,6 +185,7 @@ + @@ -190,6 +195,9 @@ + + + diff --git a/una-rpg-cpp.vcxproj.filters b/una-rpg-cpp.vcxproj.filters index 5b514c1..5208588 100644 --- a/una-rpg-cpp.vcxproj.filters +++ b/una-rpg-cpp.vcxproj.filters @@ -66,6 +66,18 @@ Source Files + + Source Files + + + Source Files + + + Source Files + + + Source Files + @@ -107,5 +119,17 @@ Header Files + + Header Files + + + Header Files + + + Header Files + + + Header Files + \ No newline at end of file