From f9310914a5efd2275efd785161c12b3387922f1f Mon Sep 17 00:00:00 2001 From: Pranav Bardiwale Date: Wed, 9 Jul 2025 10:48:38 +0530 Subject: [PATCH 01/27] Added greeting message and name input to main() --- Pokemon/main.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Pokemon/main.cpp b/Pokemon/main.cpp index c2bc7bfc..6a01d1af 100644 --- a/Pokemon/main.cpp +++ b/Pokemon/main.cpp @@ -1,6 +1,17 @@ #include +using namespace std; int main() { + string player_name; + cout<< "Enter your Name" << endl; + + cin >> player_name; + + cout << "Great Start " << player_name << ", looks like you have understood the main() function properly now!" << endl; return 0; } + + + + From cd8736172a155841e7e648c1c81bda222136c1ec Mon Sep 17 00:00:00 2001 From: Pranav Bardiwale Date: Wed, 9 Jul 2025 12:51:26 +0530 Subject: [PATCH 02/27] Giving the choice to with adding their name --- Pokemon/main.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/Pokemon/main.cpp b/Pokemon/main.cpp index 6a01d1af..ddf4909f 100644 --- a/Pokemon/main.cpp +++ b/Pokemon/main.cpp @@ -7,7 +7,27 @@ int main() { cin >> player_name; - cout << "Great Start " << player_name << ", looks like you have understood the main() function properly now!" << endl; + cout <<"Welcome to the Pokemon world " << player_name << "!,I am Professor Oak \n"; + cout << "Choose your Pokemon\n"; + cout << "1.Bulbasaur\n2.Charmander\n3.Squirtle\n"; + + int choice; + cin >> choice; + + if (choice == 1) { + cout << "your mate is Bulbasaur\n"; + } + else if (choice == 2) { + cout << "your mate is Charmander\n"; + } + else if (choice == 3) { + cout << "Your mate is Squirtle\n"; + } + else { + cout << "It's an invalid choice\n"; + } + + cout << "Ah, an excellent choice!\nBut beware, Trainer,this is only the beginning.\nYour journey is about to unfold.\nNow let’s see if you’ve got what it takes to keep going!\nGood luck, and remember… Choose wisely!"; return 0; } From 479c3a8b15e79e867442b0accae12a58d90d5c4a Mon Sep 17 00:00:00 2001 From: Pranav Bardiwale Date: Fri, 18 Jul 2025 12:37:30 +0530 Subject: [PATCH 03/27] Enum done --- Pokemon/main.cpp | 223 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 202 insertions(+), 21 deletions(-) diff --git a/Pokemon/main.cpp b/Pokemon/main.cpp index ddf4909f..32af6d8a 100644 --- a/Pokemon/main.cpp +++ b/Pokemon/main.cpp @@ -1,37 +1,218 @@ #include +#include using namespace std; -int main() { - string player_name; - cout<< "Enter your Name" << endl; - - cin >> player_name; +// Define an enum for Pokemon choices +enum class PokemonChoice { + Charmander = 1, + Bulbasaur, + Squirtle, + InvalidChoice +}; - cout <<"Welcome to the Pokemon world " << player_name << "!,I am Professor Oak \n"; - cout << "Choose your Pokemon\n"; - cout << "1.Bulbasaur\n2.Charmander\n3.Squirtle\n"; +enum class PokemonType { + Fire, + Electric, + Water, + Earth, + Normal +}; - int choice; - cin >> choice; +enum class HealingItems { + Potion, + Elixir +}; + +enum class BattleItems { + Potion, + Elixir +}; + +class Pokemon { +public: + string name; + PokemonType type; + int health; + + //created 2 constructors + Pokemon(){ - if (choice == 1) { - cout << "your mate is Bulbasaur\n"; } - else if (choice == 2) { - cout << "your mate is Charmander\n"; + + Pokemon(string p_name, PokemonType p_type, int p_health) { + name = p_name; + type = p_type; + health = p_health; } - else if (choice == 3) { - cout << "Your mate is Squirtle\n"; + + void attack() { cout << name << " attack with a powerful move!\n"; } +}; + +class Player { +public: + //Attributes + string name; + Pokemon chosenPokemon; + + //Method to choose pokemon + void choosePokemon(int choice) { + switch ((PokemonChoice)choice) { + case PokemonChoice::Charmander: + chosenPokemon = Pokemon("Charmander", PokemonType::Fire, 100); + break; + case PokemonChoice::Bulbasaur: + chosenPokemon = Pokemon("Bulbasaur", PokemonType::Earth, 100); + break; + case PokemonChoice::Squirtle: + chosenPokemon = Pokemon("Squirtle", PokemonType::Water, 100); + break; + default: + chosenPokemon = Pokemon("Pikachu", PokemonType::Electric, 100); + break; + } + cout << "Player " << name << " chose" << chosenPokemon.name << "!\n"; + } - else { - cout << "It's an invalid choice\n"; +}; + +//Professor oak class definition +class ProfessorOak { +public: + string name; + + //method to greet player + void greetPlayer(Player& player) { + cout << name << ": Hello there! Welcome to the world of Pokemon!\n"; + cout << name << ": My name is Oak. People call me the Pokemon Professor!\n"; + cout << name << ": But enough about me. Let's talk about you!\n"; } - cout << "Ah, an excellent choice!\nBut beware, Trainer,this is only the beginning.\nYour journey is about to unfold.\nNow let’s see if you’ve got what it takes to keep going!\nGood luck, and remember… Choose wisely!"; + //Method to ask the player to choose a pokemon + void offerPokemonChoices(Player& player) { + cout << name << ": First, tell me, what’s your name?\n"; + getline(cin, player.name); + cout << name << ": Ah, " << player.name << "! What a fantastic name!\n"; + cout << name << ": You must be eager to start your adventure. But first, you’ll need a Pokemon of your own!\n"; - return 0; -} + //Presenting Pokemon choices + cout << name << ": I have three Pokemon here with me. They’re all quite feisty!\n"; + cout << name << ": Choose wisely...\n"; std::cout << "1. Charmander - The fire type. A real hothead!\n"; + cout << "2. Bulbasaur - The grass type. Calm and collected!\n"; + cout << "3. Squirtle - The water type. Cool as a cucumber!\n"; + + int choice; + cout << name << ": So,which one will it be?Enter the number of your choice\n"; + cin >> choice; + player.choosePokemon(choice); + } +}; + +int main() { + + //Creating Obejcts of ProffessorOak,Pokemon and player class + ProfessorOak professor; + Pokemon placeholderPokemon; + Player player; + //Assigning values to PlaceholderPokemon attributes + placeholderPokemon.name = "Pikachu"; + placeholderPokemon.type = PokemonType::Electric; + placeholderPokemon.health = 40; + //Assigniong values to the player attribute + player.name = "Trainer"; + //Assigning values to the professorOak + professor.name = "Professor Oak"; + //Greet the player and offer Pokemon choices + professor.greetPlayer(player); + professor.offerPokemonChoices(player); + + //Conclude the first chapter + cout << "Professor Oak: " << player.chosenPokemon.name << " and you, " << player.name << ", are going to be the best of friends!\n"; + cout << "Professor Oak: Your journey begins now! Get ready to explore the vast world of Pokemon!\n"; + + + /*// Variables to store player name and chosen Pokemon + string player_name; + PokemonChoice chosen_pokemon = PokemonChoice::Charmander; // Default to an invalid choice + */ + //Using HealingItems + /*HealingItems HealPack = HealingItems::Elixir; + + //Using BattleItems + BattleItems BattlePack = BattleItems::Potion; + + cout << "Choose the Pack" << endl; + + switch (HealingItems) { + case 1: cout << "Healing Potion used! Your Pokémon recovers HP!\n"; + break; + case 2: cout << "Healing Elixir used! Your Pokémon recovers HP!\n"; + }*/ + /* + // Introduction by the Professor + cout << "Professor Oak: Hello there! Welcome to the world of Pokemon!\n"; + cout << "Professor Oak: My name is Oak. People call me the Pokemon Professor!\n"; + cout << "Professor Oak: But enough about me. Let's talk about you!\n"; + + // Taking player name as input + cout << "Professor Oak: First, tell me, what’s your name?\n"; + cin >> player_name; + + cout << "Professor Oak: Ah, " << player_name << "! What a fantastic name!\n"; + cout << "Professor Oak: You must be eager to start your adventure. But first, you’ll need a Pokemon of your own!\n"; + + // Presenting Pokemon choices + cout << "Professor Oak: I have three Pokemon here with me. They’re all quite feisty!\n"; + cout << "Professor Oak: Choose wisely...\n"; + cout << "1. Charmander - The fire type. A real hothead!\n"; + cout << "2. Bulbasaur - The grass type. Calm and collected!\n"; + cout << "3. Squirtle - The water type. Cool as a cucumber!\n"; + + int choice; + cout << "Professor Oak: So, which one will it be? Enter the number of your choice: "; + cin >> choice; + + // Map the integer choice to the corresponding enum value + switch (choice) { + case 1: + chosen_pokemon = Charmander; + break; + case 2: + chosen_pokemon = Bulbasaur; + break; + case 3: + chosen_pokemon = Squirtle; + break; + default: + chosen_pokemon = InvalidChoice; + break; + } + + // Respond based on the chosen Pokemon + switch (chosen_pokemon) { + case Charmander: + cout << "Professor Oak: A fiery choice! Charmander is yours!\n"; + break; + case Bulbasaur: + cout << "Professor Oak: A fine choice! Bulbasaur is always ready to grow on you!\n"; + break; + case Squirtle: + cout << "Professor Oak: Splendid! Squirtle will keep you cool under pressure!\n"; + break; + default: + cout << "Professor Oak: Hmm, that doesn't seem right. Let me choose for you...\n"; + chosen_pokemon = Charmander; // Default to Charmander if invalid choice + cout << "Professor Oak: Just kidding! Let's go with Charmander, the fiery dragon in the making!\n"; + break; + } + + // Concluding the first chapter + cout << "Professor Oak: " << (chosen_pokemon == Charmander ? "Charmander" : chosen_pokemon == Bulbasaur ? "Bulbasaur" : "Squirtle") + << " and you, " << player_name << ", are going to be the best of friends!\n"; + cout << "Professor Oak: Your journey begins now! Get ready to explore the vast world of Pokemon!\n"; + */ + return 0; +} \ No newline at end of file From de466fa5dcd9661189ba024e665791182fe7efc6 Mon Sep 17 00:00:00 2001 From: Pranav Bardiwale Date: Fri, 18 Jul 2025 17:51:04 +0530 Subject: [PATCH 04/27] Function calls are done! --- Pokemon/main.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Pokemon/main.cpp b/Pokemon/main.cpp index 32af6d8a..97b2988d 100644 --- a/Pokemon/main.cpp +++ b/Pokemon/main.cpp @@ -107,6 +107,20 @@ class ProfessorOak { } }; +void castSpell(int MagicLevel) { + cout << "Casting spell with magic level: "< Date: Mon, 21 Jul 2025 15:53:07 +0530 Subject: [PATCH 05/27] Cmstructor scroll done --- Pokemon/main.cpp | 264 +++++++++++++++++++---------------------------- 1 file changed, 109 insertions(+), 155 deletions(-) diff --git a/Pokemon/main.cpp b/Pokemon/main.cpp index 97b2988d..c4b24bd7 100644 --- a/Pokemon/main.cpp +++ b/Pokemon/main.cpp @@ -4,230 +4,184 @@ using namespace std; // Define an enum for Pokemon choices enum class PokemonChoice { - Charmander = 1, - Bulbasaur, - Squirtle, - InvalidChoice + CHARMANDER = 1, + BULBASAUR, + SQUIRTLE, + PIKACHU // Default choice }; +// Define an enum for Pokemon types enum class PokemonType { - Fire, - Electric, - Water, - Earth, - Normal -}; - -enum class HealingItems { - Potion, - Elixir -}; - -enum class BattleItems { - Potion, - Elixir + FIRE, + GRASS, + WATER, + ELECTRIC, + NORMAL // Added for the default constructor }; +// Pokemon class definition class Pokemon { public: + // Attributes string name; PokemonType type; int health; - //created 2 constructors - Pokemon(){ - + // Default constructor + Pokemon() { + name = "Unknown"; + type = PokemonType::NORMAL; + health = 50; + cout << "A new Pokemon has been created with the default constructor!\n"; } + // Parameterized constructor Pokemon(string p_name, PokemonType p_type, int p_health) { name = p_name; type = p_type; health = p_health; + cout << "A new Pokemon named " << name << " has been created!\n"; + } + + // Copy constructor + Pokemon(const Pokemon& other) { + name = other.name; + type = other.type; + health = other.health; + cout << "A new Pokemon has been copied from " << other.name << "!\n"; + } + + // Destructor + ~Pokemon() { + cout << name << " has been released.\n"; } - void attack() { cout << name << " attack with a powerful move!\n"; } + // Method to simulate attacking (just for demonstration) + void attack() { + cout << name << " attacks with a powerful move!\n"; + } }; +// Player class definition class Player { public: - //Attributes + // Attributes string name; Pokemon chosenPokemon; - //Method to choose pokemon + // Default constructor + Player() { + name = "Trainer"; + chosenPokemon = Pokemon(); // Using the default Pokemon constructor + cout << "A new player named " << name << " has been created!\n"; + } + + // Parameterized constructor + Player(std::string p_name, Pokemon p_chosenPokemon) { + name = p_name; + chosenPokemon = p_chosenPokemon; + cout << "Player " << name << " has been created!\n"; + } + + // Method to choose a Pokemon void choosePokemon(int choice) { switch ((PokemonChoice)choice) { - case PokemonChoice::Charmander: - chosenPokemon = Pokemon("Charmander", PokemonType::Fire, 100); + + case PokemonChoice::CHARMANDER: + chosenPokemon = Pokemon("Charmander", PokemonType::FIRE, 100); break; - case PokemonChoice::Bulbasaur: - chosenPokemon = Pokemon("Bulbasaur", PokemonType::Earth, 100); + case PokemonChoice::BULBASAUR: + chosenPokemon = Pokemon("Bulbasaur", PokemonType::GRASS, 100); break; - case PokemonChoice::Squirtle: - chosenPokemon = Pokemon("Squirtle", PokemonType::Water, 100); + case PokemonChoice::SQUIRTLE: + chosenPokemon = Pokemon("Squirtle", PokemonType::WATER, 100); break; default: - chosenPokemon = Pokemon("Pikachu", PokemonType::Electric, 100); + chosenPokemon = Pokemon("Pikachu", PokemonType::ELECTRIC, 100); break; } - cout << "Player " << name << " chose" << chosenPokemon.name << "!\n"; + cout << "Player " << name << " chose " << chosenPokemon.name << "!\n"; } }; -//Professor oak class definition +// ProfessorOak class definition class ProfessorOak { public: + // Attributes string name; - //method to greet player + // Parameterized constructor + ProfessorOak(string p_name) { + name = p_name; + } + + // Method to greet the player void greetPlayer(Player& player) { cout << name << ": Hello there! Welcome to the world of Pokemon!\n"; cout << name << ": My name is Oak. People call me the Pokemon Professor!\n"; cout << name << ": But enough about me. Let's talk about you!\n"; } - //Method to ask the player to choose a pokemon + // Method to ask the player to choose a Pokemon void offerPokemonChoices(Player& player) { cout << name << ": First, tell me, what’s your name?\n"; - getline(cin, player.name); + getline(std::cin, player.name); cout << name << ": Ah, " << player.name << "! What a fantastic name!\n"; cout << name << ": You must be eager to start your adventure. But first, you’ll need a Pokemon of your own!\n"; - //Presenting Pokemon choices + // Presenting Pokemon choices cout << name << ": I have three Pokemon here with me. They’re all quite feisty!\n"; - cout << name << ": Choose wisely...\n"; std::cout << "1. Charmander - The fire type. A real hothead!\n"; + cout << name << ": Choose wisely...\n"; + cout << "1. Charmander - The fire type. A real hothead!\n"; cout << "2. Bulbasaur - The grass type. Calm and collected!\n"; cout << "3. Squirtle - The water type. Cool as a cucumber!\n"; int choice; - cout << name << ": So,which one will it be?Enter the number of your choice\n"; + cout << name << ": So, which one will it be? Enter the number of your choice: "; cin >> choice; + player.choosePokemon(choice); } }; -void castSpell(int MagicLevel) { - cout << "Casting spell with magic level: "<> player_name; - - cout << "Professor Oak: Ah, " << player_name << "! What a fantastic name!\n"; - cout << "Professor Oak: You must be eager to start your adventure. But first, you’ll need a Pokemon of your own!\n"; - - // Presenting Pokemon choices - cout << "Professor Oak: I have three Pokemon here with me. They’re all quite feisty!\n"; - cout << "Professor Oak: Choose wisely...\n"; - cout << "1. Charmander - The fire type. A real hothead!\n"; - cout << "2. Bulbasaur - The grass type. Calm and collected!\n"; - cout << "3. Squirtle - The water type. Cool as a cucumber!\n"; - - int choice; - cout << "Professor Oak: So, which one will it be? Enter the number of your choice: "; - cin >> choice; - - // Map the integer choice to the corresponding enum value - switch (choice) { - case 1: - chosen_pokemon = Charmander; - break; - case 2: - chosen_pokemon = Bulbasaur; - break; - case 3: - chosen_pokemon = Squirtle; - break; - default: - chosen_pokemon = InvalidChoice; - break; - } - - // Respond based on the chosen Pokemon - switch (chosen_pokemon) { - case Charmander: - cout << "Professor Oak: A fiery choice! Charmander is yours!\n"; - break; - case Bulbasaur: - cout << "Professor Oak: A fine choice! Bulbasaur is always ready to grow on you!\n"; - break; - case Squirtle: - cout << "Professor Oak: Splendid! Squirtle will keep you cool under pressure!\n"; - break; - default: - cout << "Professor Oak: Hmm, that doesn't seem right. Let me choose for you...\n"; - chosen_pokemon = Charmander; // Default to Charmander if invalid choice - cout << "Professor Oak: Just kidding! Let's go with Charmander, the fiery dragon in the making!\n"; - break; - } - - // Concluding the first chapter - cout << "Professor Oak: " << (chosen_pokemon == Charmander ? "Charmander" : chosen_pokemon == Bulbasaur ? "Bulbasaur" : "Squirtle") - << " and you, " << player_name << ", are going to be the best of friends!\n"; - cout << "Professor Oak: Your journey begins now! Get ready to explore the vast world of Pokemon!\n"; - */ return 0; } \ No newline at end of file From 736cb67979431d28ece8eb72c076158896ff8b73 Mon Sep 17 00:00:00 2001 From: Pranav Bardiwale Date: Tue, 22 Jul 2025 14:15:20 +0530 Subject: [PATCH 06/27] Main quest done --- Pokemon/main.cpp | 154 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 125 insertions(+), 29 deletions(-) diff --git a/Pokemon/main.cpp b/Pokemon/main.cpp index c4b24bd7..3e3c9eb3 100644 --- a/Pokemon/main.cpp +++ b/Pokemon/main.cpp @@ -2,6 +2,20 @@ #include using namespace std; +// Function to clear the console +void clearConsole() { + // Platform-specific clear console command +#ifdef _WIN32 + system("cls"); +#else + (void)system("clear"); +#endif +} + +// Function to wait for user to press Enter +void waitForEnter() { + cin.get();//Wait for enter key +} // Define an enum for Pokemon choices enum class PokemonChoice { CHARMANDER = 1, @@ -32,7 +46,6 @@ class Pokemon { name = "Unknown"; type = PokemonType::NORMAL; health = 50; - cout << "A new Pokemon has been created with the default constructor!\n"; } // Parameterized constructor @@ -40,7 +53,6 @@ class Pokemon { name = p_name; type = p_type; health = p_health; - cout << "A new Pokemon named " << name << " has been created!\n"; } // Copy constructor @@ -48,12 +60,11 @@ class Pokemon { name = other.name; type = other.type; health = other.health; - cout << "A new Pokemon has been copied from " << other.name << "!\n"; } // Destructor ~Pokemon() { - cout << name << " has been released.\n"; + //Destructor message removed } // Method to simulate attacking (just for demonstration) @@ -73,14 +84,12 @@ class Player { Player() { name = "Trainer"; chosenPokemon = Pokemon(); // Using the default Pokemon constructor - cout << "A new player named " << name << " has been created!\n"; } // Parameterized constructor Player(std::string p_name, Pokemon p_chosenPokemon) { name = p_name; chosenPokemon = p_chosenPokemon; - cout << "Player " << name << " has been created!\n"; } // Method to choose a Pokemon @@ -119,8 +128,11 @@ class ProfessorOak { // Method to greet the player void greetPlayer(Player& player) { cout << name << ": Hello there! Welcome to the world of Pokemon!\n"; + waitForEnter(); cout << name << ": My name is Oak. People call me the Pokemon Professor!\n"; + waitForEnter(); cout << name << ": But enough about me. Let's talk about you!\n"; + waitForEnter(); } // Method to ask the player to choose a Pokemon @@ -128,7 +140,9 @@ class ProfessorOak { cout << name << ": First, tell me, what’s your name?\n"; getline(std::cin, player.name); cout << name << ": Ah, " << player.name << "! What a fantastic name!\n"; + waitForEnter(); cout << name << ": You must be eager to start your adventure. But first, you’ll need a Pokemon of your own!\n"; + waitForEnter(); // Presenting Pokemon choices cout << name << ": I have three Pokemon here with me. They’re all quite feisty!\n"; @@ -143,33 +157,109 @@ class ProfessorOak { player.choosePokemon(choice); } + + void explainMainQuest(Player& player) { + cout << "Professor Oak: Oak-ay" << player.name << "!, I am about to explain you about your upcoming grand adventure.\n"; + waitForEnter(); + cout << "Professor Oak: You see, becoming a Pokémon Master is no easy feat. It takes courage, wisdom, and a bit of luck!\n"; + waitForEnter(); + cout << "Professor Oak: Your mission, should you choose to accept it—and trust me, you really don’t have a choice—is to collect all the Pokémon Badges and conquer the Pokémon League.\n"; + waitForEnter(); + + cout << "\n" << player.name << ": Wait... that sounds a lot like every other Pokémon game out there...\n"; + waitForEnter(); + cout << "Professor Oak: Shhh! Don't break the fourth wall, " << player.name << "! This is serious business!\n"; + waitForEnter(); + + cout << "\nProfessor Oak: To achieve this, you’ll need to battle wild Pokémon, challenge gym leaders, and of course, keep your Pokémon healthy at the PokeCenter.\n"; + waitForEnter(); + cout << "Professor Oak: Along the way, you'll capture new Pokémon to strengthen your team. Just remember—there’s a limit to how many Pokémon you can carry, so choose wisely!\n"; + waitForEnter(); + + cout << "\n" << player.name << ": Sounds like a walk in the park... right?\n"; + waitForEnter(); + cout << "Professor Oak: Hah! That’s what they all say! But beware, young Trainer, the path to victory is fraught with challenges. And if you lose a battle... well, let’s just say you'll be starting from square one.\n"; + waitForEnter(); + + cout << "\nProfessor Oak: So, what do you say? Are you ready to become the next Pokémon Champion?\n"; + waitForEnter(); + cout << "\n" << player.name << ": Ready as I’ll ever be, Professor!\n"; + waitForEnter(); + + cout << "\nProfessor Oak: That’s the spirit! Now, your journey begins...\n"; + waitForEnter(); + cout << "Professor Oak: But first... let's just pretend I didn't forget to set up the actual game loop... Ahem, onwards!\n"; + waitForEnter(); + } + + }; -int main() { - // Task 1: Test default and parameterized constructors - Pokemon defaultPokemon; // Using default constructor - Pokemon charmander("Charmander", PokemonType::FIRE, 100); // Using parameterized constructor +//Function to handle the main game loop +void gameloop(Player& player) { + int choice; + bool keepPlaying = true; + + while (keepPlaying) { + //Clear console before showing options + clearConsole(); - cout << "Pokemon Details:\n"; - cout << "Name: " << defaultPokemon.name << "\nType: " << (int)defaultPokemon.type << "\nHealth: " << defaultPokemon.health << "\n"; - cout << "Name: " << charmander.name << "\nType: " << (int)charmander.type << "\nHealth: " << charmander.health << "\n"; + // Display options to the player + cout << "\nWhat would you like to do next, " << player.name << "?\n"; + cout << "1. Battle Wild Pokémon\n"; + cout << "2. Visit PokeCenter\n"; + cout << "3. Challenge Gyms\n"; + cout << "4. Enter Pokémon League\n"; + cout << "5. Quit\n"; + cout << "Enter your choice: "; + cin >> choice; - // Task 2: Test the copy constructor - Pokemon bulbasaur("Bulbasaur", PokemonType::GRASS, 100); // Create a Pokemon - Pokemon bulbasaurCopy = bulbasaur; // Copy the Pokemon - cout << "Original Pokemon Health: " << bulbasaur.health << "\n"; - cout << "Copied Pokemon Health: " << bulbasaurCopy.health << "\n"; + //Clear the newline character left in the buffer after cin >> choice + cin.ignore(numeric_limits::max(), '\n'); - // Modify the copy - bulbasaurCopy.health = 80; - cout << "After Modification:\n"; - cout << "Original Pokemon Health: " << bulbasaur.health << "\n"; - cout << "Copied Pokemon Health: " << bulbasaurCopy.health << "\n"; + // Process the player's choice and display the corresponding message + switch (choice) { + case 1: + cout << "You look around... but all the wild Pokémon are on " + "vacation. Maybe try again later?\n"; + break; + case 2: + cout + << "You head to the PokeCenter, but Nurse Joy is out on a coffee " + "break. Guess your Pokémon will have to tough it out for now!\n"; + break; + case 3: + cout << "You march up to the Gym, but it's closed for renovations. " + "Seems like even Gym Leaders need a break!\n"; + break; + case 4: + cout << "You boldly step towards the Pokémon League... but the " + "gatekeeper laughs and says, 'Maybe next time, champ!'\n"; + break; + case 5: + cout << "You try to quit, but Professor Oak's voice echoes: " + "There is no quitting in Pokemon training!\n"; + cout << "Are you sure you want to quit?(y/n)"; + char quitChoice; + cin >> quitChoice; + if (quitChoice == 'Y' || quitChoice == 'y'){ + keepPlaying = false; + } + break; + default: + cout << "That's not a valid choice.Try again!\n"; + break; + } + // Wait for Enter key before the screen is cleared and the menu is shown + // again + waitForEnter(); + } + cout << "Goodbye, " << player.name << "! Thanks for playing!\n"; +} - // Task 3: Test the destructor - { - Pokemon squirtle("Squirtle", PokemonType::WATER, 100); // Pokemon will be destroyed at the end of this scope - } // Destructor will be called here +int main() { + // Create Pokemon and Player objects for the game + Pokemon charmander("Charmander", PokemonType::FIRE, 100); // Using parameterized constructor // Continue with the main flow of the game ProfessorOak professor("Professor Oak"); @@ -179,9 +269,15 @@ int main() { professor.greetPlayer(player); professor.offerPokemonChoices(player); - // Conclude the first chapter + //Explain the main quest + professor.explainMainQuest(player); + + //Start the main game loop + gameloop(player); + + /*// Conclude the first chapter cout << "Professor Oak: " << player.chosenPokemon.name << " and you, " << player.name << ", are going to be the best of friends!\n"; cout << "Professor Oak: Your journey begins now! Get ready to explore the vast world of Pokemon!\n"; - + */ return 0; } \ No newline at end of file From dd1ccfdaec8e24fa8d23bf682a1ef2d68311c02e Mon Sep 17 00:00:00 2001 From: Pranav Bardiwale Date: Tue, 29 Jul 2025 00:22:34 +0530 Subject: [PATCH 07/27] head --- Pokemon/header.cpp | 1 + Pokemon/header.h | 6 ++ Pokemon/main.cpp | 159 ++++++++++++++++++++++++++------------------- 3 files changed, 99 insertions(+), 67 deletions(-) create mode 100644 Pokemon/header.cpp create mode 100644 Pokemon/header.h diff --git a/Pokemon/header.cpp b/Pokemon/header.cpp new file mode 100644 index 00000000..f5bec35f --- /dev/null +++ b/Pokemon/header.cpp @@ -0,0 +1 @@ +#include "header.h" diff --git a/Pokemon/header.h b/Pokemon/header.h new file mode 100644 index 00000000..82876bef --- /dev/null +++ b/Pokemon/header.h @@ -0,0 +1,6 @@ +#pragma once +class header +{ + +}; + diff --git a/Pokemon/main.cpp b/Pokemon/main.cpp index 3e3c9eb3..704e23b8 100644 --- a/Pokemon/main.cpp +++ b/Pokemon/main.cpp @@ -1,4 +1,5 @@ #include +#include // Include this header to use numeric_limits #include using namespace std; @@ -14,10 +15,11 @@ void clearConsole() { // Function to wait for user to press Enter void waitForEnter() { - cin.get();//Wait for enter key + cin.get(); // Wait for Enter key } + // Define an enum for Pokemon choices -enum class PokemonChoice { +enum PokemonChoice { CHARMANDER = 1, BULBASAUR, SQUIRTLE, @@ -25,7 +27,7 @@ enum class PokemonChoice { }; // Define an enum for Pokemon types -enum class PokemonType { +enum PokemonType { FIRE, GRASS, WATER, @@ -36,7 +38,6 @@ enum class PokemonType { // Pokemon class definition class Pokemon { public: - // Attributes string name; PokemonType type; int health; @@ -44,12 +45,12 @@ class Pokemon { // Default constructor Pokemon() { name = "Unknown"; - type = PokemonType::NORMAL; + type = NORMAL; health = 50; } // Parameterized constructor - Pokemon(string p_name, PokemonType p_type, int p_health) { + Pokemon(std::string p_name, PokemonType p_type, int p_health) { name = p_name; type = p_type; health = p_health; @@ -64,19 +65,15 @@ class Pokemon { // Destructor ~Pokemon() { - //Destructor message removed + // Destructor message removed } - // Method to simulate attacking (just for demonstration) - void attack() { - cout << name << " attacks with a powerful move!\n"; - } + void attack() { std::cout << name << " attacks with a powerful move!\n"; } }; // Player class definition class Player { public: - // Attributes string name; Pokemon chosenPokemon; @@ -92,116 +89,144 @@ class Player { chosenPokemon = p_chosenPokemon; } - // Method to choose a Pokemon void choosePokemon(int choice) { - switch ((PokemonChoice)choice) { - - case PokemonChoice::CHARMANDER: - chosenPokemon = Pokemon("Charmander", PokemonType::FIRE, 100); + switch (choice) { + case CHARMANDER: + chosenPokemon = Pokemon("Charmander", FIRE, 100); break; - case PokemonChoice::BULBASAUR: - chosenPokemon = Pokemon("Bulbasaur", PokemonType::GRASS, 100); + case BULBASAUR: + chosenPokemon = Pokemon("Bulbasaur", GRASS, 100); break; - case PokemonChoice::SQUIRTLE: - chosenPokemon = Pokemon("Squirtle", PokemonType::WATER, 100); + case SQUIRTLE: + chosenPokemon = Pokemon("Squirtle", WATER, 100); break; default: - chosenPokemon = Pokemon("Pikachu", PokemonType::ELECTRIC, 100); + chosenPokemon = Pokemon("Pikachu", ELECTRIC, 100); break; } - cout << "Player " << name << " chose " << chosenPokemon.name << "!\n"; + waitForEnter(); // Wait for user to press Enter before proceeding } }; // ProfessorOak class definition class ProfessorOak { public: - // Attributes string name; // Parameterized constructor - ProfessorOak(string p_name) { - name = p_name; - } + ProfessorOak(string p_name) { name = p_name; } - // Method to greet the player void greetPlayer(Player& player) { cout << name << ": Hello there! Welcome to the world of Pokemon!\n"; waitForEnter(); - cout << name << ": My name is Oak. People call me the Pokemon Professor!\n"; + cout << name + << ": My name is Oak. People call me the Pokemon Professor!\n"; waitForEnter(); cout << name << ": But enough about me. Let's talk about you!\n"; waitForEnter(); } - // Method to ask the player to choose a Pokemon void offerPokemonChoices(Player& player) { - cout << name << ": First, tell me, what’s your name?\n"; + cout + << name + << ": First, tell me, what’s your name? \t [Please Enter Your Name]\n"; getline(std::cin, player.name); - cout << name << ": Ah, " << player.name << "! What a fantastic name!\n"; + cout << name << ": Ah, " << player.name + << "! What a fantastic name!\n"; waitForEnter(); - cout << name << ": You must be eager to start your adventure. But first, you’ll need a Pokemon of your own!\n"; + cout << name + << ": You must be eager to start your adventure. But first, " + "you’ll need a Pokemon of your own!\n"; waitForEnter(); // Presenting Pokemon choices - cout << name << ": I have three Pokemon here with me. They’re all quite feisty!\n"; + cout + << name + << ": I have three Pokemon here with me. They’re all quite feisty!\n"; + waitForEnter(); cout << name << ": Choose wisely...\n"; cout << "1. Charmander - The fire type. A real hothead!\n"; cout << "2. Bulbasaur - The grass type. Calm and collected!\n"; cout << "3. Squirtle - The water type. Cool as a cucumber!\n"; int choice; - cout << name << ": So, which one will it be? Enter the number of your choice: "; + cout + << name + << ": So, which one will it be? Enter the number of your choice: "; cin >> choice; player.choosePokemon(choice); + waitForEnter(); } + // New method for the main quest conversation void explainMainQuest(Player& player) { - cout << "Professor Oak: Oak-ay" << player.name << "!, I am about to explain you about your upcoming grand adventure.\n"; + // Clear the console + clearConsole(); + + cout << "Professor Oak: " << player.name + << "!, I am about to explain you about your upcoming grand " + "adventure.\n"; waitForEnter(); - cout << "Professor Oak: You see, becoming a Pokémon Master is no easy feat. It takes courage, wisdom, and a bit of luck!\n"; + cout << "Professor Oak: You see, becoming a Pokémon Master is no easy " + "feat. It takes courage, wisdom, and a bit of luck!\n"; waitForEnter(); - cout << "Professor Oak: Your mission, should you choose to accept it—and trust me, you really don’t have a choice—is to collect all the Pokémon Badges and conquer the Pokémon League.\n"; + cout + << "Professor Oak: Your mission, should you choose to accept it—and " + "trust me, you really don’t have a choice—is to collect all the " + "Pokémon Badges and conquer the Pokémon League.\n"; waitForEnter(); - cout << "\n" << player.name << ": Wait... that sounds a lot like every other Pokémon game out there...\n"; + cout << "\n" + << player.name + << ": Wait... that sounds a lot like every other Pokémon game " + "out there...\n"; waitForEnter(); - cout << "Professor Oak: Shhh! Don't break the fourth wall, " << player.name << "! This is serious business!\n"; + cout << "Professor Oak: Shhh! Don't break the fourth wall, " + << player.name << "! This is serious business!\n"; waitForEnter(); - cout << "\nProfessor Oak: To achieve this, you’ll need to battle wild Pokémon, challenge gym leaders, and of course, keep your Pokémon healthy at the PokeCenter.\n"; + cout << "\nProfessor Oak: To achieve this, you’ll need to battle wild " + "Pokémon, challenge gym leaders, and of course, keep your " + "Pokémon healthy at the PokeCenter.\n"; waitForEnter(); - cout << "Professor Oak: Along the way, you'll capture new Pokémon to strengthen your team. Just remember—there’s a limit to how many Pokémon you can carry, so choose wisely!\n"; + cout << "Professor Oak: Along the way, you'll capture new Pokémon to " + "strengthen your team. Just remember—there’s a limit to how " + "many Pokémon you can carry, so choose wisely!\n"; waitForEnter(); - cout << "\n" << player.name << ": Sounds like a walk in the park... right?\n"; + cout << "\n" + << player.name << ": Sounds like a walk in the park... right?\n"; waitForEnter(); - cout << "Professor Oak: Hah! That’s what they all say! But beware, young Trainer, the path to victory is fraught with challenges. And if you lose a battle... well, let’s just say you'll be starting from square one.\n"; + cout << "Professor Oak: Hah! That’s what they all say! But beware, " + "young Trainer, the path to victory is fraught with " + "challenges. And if you lose a battle... well, let’s just say " + "you'll be starting from square one.\n"; waitForEnter(); - cout << "\nProfessor Oak: So, what do you say? Are you ready to become the next Pokémon Champion?\n"; + cout << "\nProfessor Oak: So, what do you say? Are you ready to " + "become the next Pokémon Champion?\n"; waitForEnter(); cout << "\n" << player.name << ": Ready as I’ll ever be, Professor!\n"; waitForEnter(); - cout << "\nProfessor Oak: That’s the spirit! Now, your journey begins...\n"; + cout + << "\nProfessor Oak: That’s the spirit! Now, your journey begins...\n"; waitForEnter(); - cout << "Professor Oak: But first... let's just pretend I didn't forget to set up the actual game loop... Ahem, onwards!\n"; + cout << "Professor Oak: But first... let's just pretend I didn't " + "forget to set up the actual game loop... Ahem, onwards!\n"; waitForEnter(); } - - }; -//Function to handle the main game loop -void gameloop(Player& player) { +// Function to handle the main game loop +void gameLoop(Player& player) { int choice; bool keepPlaying = true; while (keepPlaying) { - //Clear console before showing options + // Clear console before showing options clearConsole(); // Display options to the player @@ -214,9 +239,10 @@ void gameloop(Player& player) { cout << "Enter your choice: "; cin >> choice; - //Clear the newline character left in the buffer after cin >> choice + // Clear the newline character left in the buffer after cin >> choice cin.ignore(numeric_limits::max(), '\n'); + // Process the player's choice and display the corresponding message switch (choice) { case 1: @@ -238,28 +264,31 @@ void gameloop(Player& player) { break; case 5: cout << "You try to quit, but Professor Oak's voice echoes: " - "There is no quitting in Pokemon training!\n"; - cout << "Are you sure you want to quit?(y/n)"; + "'There's no quitting in Pokémon training!'\n"; + cout << "Are you sure you want to quit? (y/n): "; char quitChoice; cin >> quitChoice; - if (quitChoice == 'Y' || quitChoice == 'y'){ + if (quitChoice == 'y' || quitChoice == 'Y') { keepPlaying = false; } break; default: - cout << "That's not a valid choice.Try again!\n"; + cout << "That's not a valid choice. Try again!\n"; break; - } + } + // Wait for Enter key before the screen is cleared and the menu is shown // again waitForEnter(); } + cout << "Goodbye, " << player.name << "! Thanks for playing!\n"; } int main() { // Create Pokemon and Player objects for the game - Pokemon charmander("Charmander", PokemonType::FIRE, 100); // Using parameterized constructor + Pokemon charmander("Charmander", FIRE, + 100); // Using parameterized constructor // Continue with the main flow of the game ProfessorOak professor("Professor Oak"); @@ -269,15 +298,11 @@ int main() { professor.greetPlayer(player); professor.offerPokemonChoices(player); - //Explain the main quest + // Explain the main quest professor.explainMainQuest(player); - //Start the main game loop - gameloop(player); + // Start the main game loop + gameLoop(player); - /*// Conclude the first chapter - cout << "Professor Oak: " << player.chosenPokemon.name << " and you, " << player.name << ", are going to be the best of friends!\n"; - cout << "Professor Oak: Your journey begins now! Get ready to explore the vast world of Pokemon!\n"; - */ return 0; -} \ No newline at end of file +} From 17c437945ff3a84bf9c73766b81762b381f0624c Mon Sep 17 00:00:00 2001 From: Pranav Bardiwale Date: Tue, 29 Jul 2025 00:49:20 +0530 Subject: [PATCH 08/27] Can't understand the errord --- Pokemon/PokemonChoice.cpp | 1 + Pokemon/PokemonChoice.h | 7 +++++++ Pokemon/PokemonType.cpp | 1 + Pokemon/PokemonType.h | 8 ++++++++ Pokemon/main.cpp | 22 ++++------------------ 5 files changed, 21 insertions(+), 18 deletions(-) create mode 100644 Pokemon/PokemonChoice.cpp create mode 100644 Pokemon/PokemonChoice.h create mode 100644 Pokemon/PokemonType.cpp create mode 100644 Pokemon/PokemonType.h diff --git a/Pokemon/PokemonChoice.cpp b/Pokemon/PokemonChoice.cpp new file mode 100644 index 00000000..3a124bf6 --- /dev/null +++ b/Pokemon/PokemonChoice.cpp @@ -0,0 +1 @@ +#include "PokemonChoice.h" diff --git a/Pokemon/PokemonChoice.h b/Pokemon/PokemonChoice.h new file mode 100644 index 00000000..5e3d29a4 --- /dev/null +++ b/Pokemon/PokemonChoice.h @@ -0,0 +1,7 @@ +// Define an enum for Pokemon choices +enum class PokemonChoice { + CHARMANDER = 1, + BULBASAUR, + SQUIRTLE, + PIKACHU // Default choice +}; \ No newline at end of file diff --git a/Pokemon/PokemonType.cpp b/Pokemon/PokemonType.cpp new file mode 100644 index 00000000..f5bec35f --- /dev/null +++ b/Pokemon/PokemonType.cpp @@ -0,0 +1 @@ +#include "header.h" diff --git a/Pokemon/PokemonType.h b/Pokemon/PokemonType.h new file mode 100644 index 00000000..f50f9252 --- /dev/null +++ b/Pokemon/PokemonType.h @@ -0,0 +1,8 @@ +// Define an enum for Pokemon types +enum class PokemonType { + FIRE, + GRASS, + WATER, + ELECTRIC, + NORMAL // Added for the default constructor +}; diff --git a/Pokemon/main.cpp b/Pokemon/main.cpp index 704e23b8..32e771f0 100644 --- a/Pokemon/main.cpp +++ b/Pokemon/main.cpp @@ -1,6 +1,9 @@ +#include"PokemonType.h" +#include"PokemonChoice.h" #include #include // Include this header to use numeric_limits #include + using namespace std; // Function to clear the console @@ -18,23 +21,6 @@ void waitForEnter() { cin.get(); // Wait for Enter key } -// Define an enum for Pokemon choices -enum PokemonChoice { - CHARMANDER = 1, - BULBASAUR, - SQUIRTLE, - PIKACHU // Default choice -}; - -// Define an enum for Pokemon types -enum PokemonType { - FIRE, - GRASS, - WATER, - ELECTRIC, - NORMAL // Added for the default constructor -}; - // Pokemon class definition class Pokemon { public: @@ -285,7 +271,7 @@ void gameLoop(Player& player) { cout << "Goodbye, " << player.name << "! Thanks for playing!\n"; } -int main() { +int main() {s // Create Pokemon and Player objects for the game Pokemon charmander("Charmander", FIRE, 100); // Using parameterized constructor From b075054f166474c79395278379d8f8a366f9a4a9 Mon Sep 17 00:00:00 2001 From: Pranav Bardiwale Date: Tue, 29 Jul 2025 18:26:43 +0530 Subject: [PATCH 09/27] assignment done --- Pokemon/main.cpp | 105 +++++++++++++++++++------------------------- Pokemon/utility.cpp | 19 ++++++++ Pokemon/utility.h | 9 ++++ 3 files changed, 72 insertions(+), 61 deletions(-) create mode 100644 Pokemon/utility.cpp create mode 100644 Pokemon/utility.h diff --git a/Pokemon/main.cpp b/Pokemon/main.cpp index 32e771f0..323ccf25 100644 --- a/Pokemon/main.cpp +++ b/Pokemon/main.cpp @@ -1,26 +1,11 @@ -#include"PokemonType.h" -#include"PokemonChoice.h" +#include "PokemonChoice.h" +#include "PokemonType.h" +#include "utility.h" #include #include // Include this header to use numeric_limits #include - using namespace std; -// Function to clear the console -void clearConsole() { - // Platform-specific clear console command -#ifdef _WIN32 - system("cls"); -#else - (void)system("clear"); -#endif -} - -// Function to wait for user to press Enter -void waitForEnter() { - cin.get(); // Wait for Enter key -} - // Pokemon class definition class Pokemon { public: @@ -31,12 +16,12 @@ class Pokemon { // Default constructor Pokemon() { name = "Unknown"; - type = NORMAL; + type = PokemonType::NORMAL; health = 50; } // Parameterized constructor - Pokemon(std::string p_name, PokemonType p_type, int p_health) { + Pokemon(string p_name, PokemonType p_type, int p_health) { name = p_name; type = p_type; health = p_health; @@ -54,7 +39,7 @@ class Pokemon { // Destructor message removed } - void attack() { std::cout << name << " attacks with a powerful move!\n"; } + void attack() { cout << name << " attacks with a powerful move!\n"; } }; // Player class definition @@ -70,28 +55,28 @@ class Player { } // Parameterized constructor - Player(std::string p_name, Pokemon p_chosenPokemon) { + Player(string p_name, Pokemon p_chosenPokemon) { name = p_name; chosenPokemon = p_chosenPokemon; } void choosePokemon(int choice) { - switch (choice) { - case CHARMANDER: - chosenPokemon = Pokemon("Charmander", FIRE, 100); + switch ((PokemonChoice)choice) { + case PokemonChoice::CHARMANDER: + chosenPokemon = Pokemon("Charmander", PokemonType::FIRE, 100); break; - case BULBASAUR: - chosenPokemon = Pokemon("Bulbasaur", GRASS, 100); + case PokemonChoice::BULBASAUR: + chosenPokemon = Pokemon("Bulbasaur", PokemonType::GRASS, 100); break; - case SQUIRTLE: - chosenPokemon = Pokemon("Squirtle", WATER, 100); + case PokemonChoice::SQUIRTLE: + chosenPokemon = Pokemon("Squirtle", PokemonType::WATER, 100); break; default: - chosenPokemon = Pokemon("Pikachu", ELECTRIC, 100); + chosenPokemon = Pokemon("Pikachu", PokemonType::ELECTRIC, 100); break; } cout << "Player " << name << " chose " << chosenPokemon.name << "!\n"; - waitForEnter(); // Wait for user to press Enter before proceeding + utility::waitForEnter(); // Wait for user to press Enter before proceeding } }; @@ -105,32 +90,32 @@ class ProfessorOak { void greetPlayer(Player& player) { cout << name << ": Hello there! Welcome to the world of Pokemon!\n"; - waitForEnter(); + utility::waitForEnter(); cout << name << ": My name is Oak. People call me the Pokemon Professor!\n"; - waitForEnter(); + utility::waitForEnter(); cout << name << ": But enough about me. Let's talk about you!\n"; - waitForEnter(); + utility::waitForEnter(); } void offerPokemonChoices(Player& player) { cout << name << ": First, tell me, what’s your name? \t [Please Enter Your Name]\n"; - getline(std::cin, player.name); + getline(cin, player.name); cout << name << ": Ah, " << player.name << "! What a fantastic name!\n"; - waitForEnter(); + utility::waitForEnter(); cout << name << ": You must be eager to start your adventure. But first, " "you’ll need a Pokemon of your own!\n"; - waitForEnter(); + utility::waitForEnter(); // Presenting Pokemon choices cout << name << ": I have three Pokemon here with me. They’re all quite feisty!\n"; - waitForEnter(); + utility::waitForEnter(); cout << name << ": Choose wisely...\n"; cout << "1. Charmander - The fire type. A real hothead!\n"; cout << "2. Bulbasaur - The grass type. Calm and collected!\n"; @@ -143,66 +128,66 @@ class ProfessorOak { cin >> choice; player.choosePokemon(choice); - waitForEnter(); + utility::waitForEnter(); } // New method for the main quest conversation void explainMainQuest(Player& player) { // Clear the console - clearConsole(); + utility::clearConsole(); cout << "Professor Oak: " << player.name << "!, I am about to explain you about your upcoming grand " "adventure.\n"; - waitForEnter(); + utility::waitForEnter(); cout << "Professor Oak: You see, becoming a Pokémon Master is no easy " "feat. It takes courage, wisdom, and a bit of luck!\n"; - waitForEnter(); + utility::waitForEnter(); cout << "Professor Oak: Your mission, should you choose to accept it—and " "trust me, you really don’t have a choice—is to collect all the " "Pokémon Badges and conquer the Pokémon League.\n"; - waitForEnter(); + utility::waitForEnter(); cout << "\n" << player.name << ": Wait... that sounds a lot like every other Pokémon game " "out there...\n"; - waitForEnter(); + utility::waitForEnter(); cout << "Professor Oak: Shhh! Don't break the fourth wall, " << player.name << "! This is serious business!\n"; - waitForEnter(); + utility::waitForEnter(); cout << "\nProfessor Oak: To achieve this, you’ll need to battle wild " "Pokémon, challenge gym leaders, and of course, keep your " "Pokémon healthy at the PokeCenter.\n"; - waitForEnter(); + utility::waitForEnter(); cout << "Professor Oak: Along the way, you'll capture new Pokémon to " "strengthen your team. Just remember—there’s a limit to how " "many Pokémon you can carry, so choose wisely!\n"; - waitForEnter(); + utility::waitForEnter(); cout << "\n" << player.name << ": Sounds like a walk in the park... right?\n"; - waitForEnter(); + utility::waitForEnter(); cout << "Professor Oak: Hah! That’s what they all say! But beware, " "young Trainer, the path to victory is fraught with " "challenges. And if you lose a battle... well, let’s just say " "you'll be starting from square one.\n"; - waitForEnter(); + utility::waitForEnter(); cout << "\nProfessor Oak: So, what do you say? Are you ready to " "become the next Pokémon Champion?\n"; - waitForEnter(); + utility::waitForEnter(); cout << "\n" << player.name << ": Ready as I’ll ever be, Professor!\n"; - waitForEnter(); + utility::waitForEnter(); cout << "\nProfessor Oak: That’s the spirit! Now, your journey begins...\n"; - waitForEnter(); + utility::waitForEnter(); cout << "Professor Oak: But first... let's just pretend I didn't " "forget to set up the actual game loop... Ahem, onwards!\n"; - waitForEnter(); + utility::waitForEnter(); } }; @@ -213,7 +198,7 @@ void gameLoop(Player& player) { while (keepPlaying) { // Clear console before showing options - clearConsole(); + utility::clearConsole(); // Display options to the player cout << "\nWhat would you like to do next, " << player.name << "?\n"; @@ -225,9 +210,7 @@ void gameLoop(Player& player) { cout << "Enter your choice: "; cin >> choice; - // Clear the newline character left in the buffer after cin >> choice - cin.ignore(numeric_limits::max(), '\n'); - + utility::clearInputBuffer(); // Clear the input buffer // Process the player's choice and display the corresponding message switch (choice) { @@ -265,15 +248,15 @@ void gameLoop(Player& player) { // Wait for Enter key before the screen is cleared and the menu is shown // again - waitForEnter(); + utility::waitForEnter(); } cout << "Goodbye, " << player.name << "! Thanks for playing!\n"; } -int main() {s +int main() { // Create Pokemon and Player objects for the game - Pokemon charmander("Charmander", FIRE, + Pokemon charmander("Charmander", PokemonType::FIRE, 100); // Using parameterized constructor // Continue with the main flow of the game @@ -291,4 +274,4 @@ int main() {s gameLoop(player); return 0; -} +} \ No newline at end of file diff --git a/Pokemon/utility.cpp b/Pokemon/utility.cpp new file mode 100644 index 00000000..3ad2a280 --- /dev/null +++ b/Pokemon/utility.cpp @@ -0,0 +1,19 @@ +#include "utility.h" +#include +#include +using namespace std; + +void utility::clearConsole() { +#ifdef _WIN32 + system("cls"); +#else + system("clear"); +#endif +} + +void utility::waitForEnter() { + cin.get(); +} + +void utility::clearInputBuffer(){ +} \ No newline at end of file diff --git a/Pokemon/utility.h b/Pokemon/utility.h new file mode 100644 index 00000000..ca322012 --- /dev/null +++ b/Pokemon/utility.h @@ -0,0 +1,9 @@ +#pragma once +class utility +{ +public : + static void clearConsole(); + static void waitForEnter(); + static void clearInputBuffer(); +}; + From dad1bf509257497115f90a8d43009793e11af98e Mon Sep 17 00:00:00 2001 From: Pranav Bardiwale Date: Wed, 30 Jul 2025 23:30:06 +0530 Subject: [PATCH 10/27] Deaking with some errors --- Pokemon/Pokemon.sln | 19 +++++++++++++++++++ Pokemon/Pokemon.vcxproj | 10 ++++++++++ Pokemon/Pokemon.vcxproj.filters | 26 ++++++++++++++++++++++++++ Pokemon/Pokemon.vcxproj.user | 4 ++++ Pokemon/PokemonChoice.cpp | 1 - Pokemon/PokemonType.cpp | 2 +- Pokemon/PokemonType.h | 2 +- Pokemon/main.cpp | 1 + Pokemon/player.cpp | 33 +++++++++++++++++++++++++++++++++ Pokemon/player.h | 17 +++++++++++++++++ 10 files changed, 112 insertions(+), 3 deletions(-) create mode 100644 Pokemon/Pokemon.vcxproj.user create mode 100644 Pokemon/player.cpp create mode 100644 Pokemon/player.h diff --git a/Pokemon/Pokemon.sln b/Pokemon/Pokemon.sln index dea79cff..b117a60a 100644 --- a/Pokemon/Pokemon.sln +++ b/Pokemon/Pokemon.sln @@ -1,7 +1,12 @@  Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.36310.24 d17.14 +MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Pokemon", "Pokemon.vcxproj", "{872261CB-D6AC-488B-91C5-1B44032596F2}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Header.h", "..\Header.h\Header.h.vcxproj", "{47FEE16B-AAEB-4576-91E7-3C9C5225D963}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -18,5 +23,19 @@ Global {872261CB-D6AC-488B-91C5-1B44032596F2}.Release|Win32.Build.0 = Release|Win32 {872261CB-D6AC-488B-91C5-1B44032596F2}.Release|x64.ActiveCfg = Release|x64 {872261CB-D6AC-488B-91C5-1B44032596F2}.Release|x64.Build.0 = Release|x64 + {47FEE16B-AAEB-4576-91E7-3C9C5225D963}.Debug|Win32.ActiveCfg = Debug|Win32 + {47FEE16B-AAEB-4576-91E7-3C9C5225D963}.Debug|Win32.Build.0 = Debug|Win32 + {47FEE16B-AAEB-4576-91E7-3C9C5225D963}.Debug|x64.ActiveCfg = Debug|x64 + {47FEE16B-AAEB-4576-91E7-3C9C5225D963}.Debug|x64.Build.0 = Debug|x64 + {47FEE16B-AAEB-4576-91E7-3C9C5225D963}.Release|Win32.ActiveCfg = Release|Win32 + {47FEE16B-AAEB-4576-91E7-3C9C5225D963}.Release|Win32.Build.0 = Release|Win32 + {47FEE16B-AAEB-4576-91E7-3C9C5225D963}.Release|x64.ActiveCfg = Release|x64 + {47FEE16B-AAEB-4576-91E7-3C9C5225D963}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {AA496C07-30CF-4C3C-ABFF-0573647E3200} EndGlobalSection EndGlobal diff --git a/Pokemon/Pokemon.vcxproj b/Pokemon/Pokemon.vcxproj index 9e6331ef..2f89b0e7 100644 --- a/Pokemon/Pokemon.vcxproj +++ b/Pokemon/Pokemon.vcxproj @@ -154,7 +154,11 @@ + + + + @@ -162,6 +166,12 @@ + + + + + + diff --git a/Pokemon/Pokemon.vcxproj.filters b/Pokemon/Pokemon.vcxproj.filters index 644f8bee..3ffc753b 100644 --- a/Pokemon/Pokemon.vcxproj.filters +++ b/Pokemon/Pokemon.vcxproj.filters @@ -18,5 +18,31 @@ Source Files + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + \ No newline at end of file diff --git a/Pokemon/Pokemon.vcxproj.user b/Pokemon/Pokemon.vcxproj.user new file mode 100644 index 00000000..88a55094 --- /dev/null +++ b/Pokemon/Pokemon.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Pokemon/PokemonChoice.cpp b/Pokemon/PokemonChoice.cpp index 3a124bf6..e69de29b 100644 --- a/Pokemon/PokemonChoice.cpp +++ b/Pokemon/PokemonChoice.cpp @@ -1 +0,0 @@ -#include "PokemonChoice.h" diff --git a/Pokemon/PokemonType.cpp b/Pokemon/PokemonType.cpp index f5bec35f..8b137891 100644 --- a/Pokemon/PokemonType.cpp +++ b/Pokemon/PokemonType.cpp @@ -1 +1 @@ -#include "header.h" + diff --git a/Pokemon/PokemonType.h b/Pokemon/PokemonType.h index f50f9252..3806a62b 100644 --- a/Pokemon/PokemonType.h +++ b/Pokemon/PokemonType.h @@ -5,4 +5,4 @@ enum class PokemonType { WATER, ELECTRIC, NORMAL // Added for the default constructor -}; +}; \ No newline at end of file diff --git a/Pokemon/main.cpp b/Pokemon/main.cpp index 323ccf25..c56f4c12 100644 --- a/Pokemon/main.cpp +++ b/Pokemon/main.cpp @@ -1,6 +1,7 @@ #include "PokemonChoice.h" #include "PokemonType.h" #include "utility.h" +#include "player.h" #include #include // Include this header to use numeric_limits #include diff --git a/Pokemon/player.cpp b/Pokemon/player.cpp new file mode 100644 index 00000000..cfaaadf7 --- /dev/null +++ b/Pokemon/player.cpp @@ -0,0 +1,33 @@ +#include "player.h" +#include + +// Default constructor +player::player() { + name = "Trainer"; + chosenPokemon = Pokemon(); // Using the default Pokemon constructor +} + +// Parameterized constructor +player::player(string p_name, Pokemon p_chosenPokemon) { + name = p_name; + chosenPokemon = p_chosenPokemon; +} + +void player::choosePokemon(int choice) { + switch ((PokemonChoice)choice) { + case PokemonChoice::CHARMANDER: + chosenPokemon = Pokemon("Charmander", PokemonType::FIRE, 100); + break; + case PokemonChoice::BULBASAUR: + chosenPokemon = Pokemon("Bulbasaur", PokemonType::GRASS, 100); + break; + case PokemonChoice::SQUIRTLE: + chosenPokemon = Pokemon("Squirtle", PokemonType::WATER, 100); + break; + default: + chosenPokemon = Pokemon("Pikachu", PokemonType::ELECTRIC, 100); + break; + } + cout << "Player " << name << " chose " << chosenPokemon.name << "!\n"; + utility::waitForEnter(); // Wait for user to press Enter before proceeding +} \ No newline at end of file diff --git a/Pokemon/player.h b/Pokemon/player.h new file mode 100644 index 00000000..98562a80 --- /dev/null +++ b/Pokemon/player.h @@ -0,0 +1,17 @@ +#include +#include"PokemonChoice.h" +#include"PokemonType.h" +#include"utility.h" +using namespace std; +class player +{ +public: + string name; + Pokemon chosenPokemon; + + player();//default constructor + player(string p_name, Pokemon p_chosenPokemon);//Parameterized constructor + + void choosePokemon(int choice);//Method to choose pokemon +}; + From 04b7834da0925603817d9e66c5f7f967649532ee Mon Sep 17 00:00:00 2001 From: Pranav Bardiwale Date: Thu, 31 Jul 2025 00:26:38 +0530 Subject: [PATCH 11/27] facing errors in player.h and .cpp file --- Pokemon/main.cpp | 39 +-------------------------------------- Pokemon/player.cpp | 13 +++++++------ Pokemon/player.h | 26 +++++++++++++------------- 3 files changed, 21 insertions(+), 57 deletions(-) diff --git a/Pokemon/main.cpp b/Pokemon/main.cpp index c56f4c12..8b21ed08 100644 --- a/Pokemon/main.cpp +++ b/Pokemon/main.cpp @@ -1,7 +1,6 @@ #include "PokemonChoice.h" #include "PokemonType.h" #include "utility.h" -#include "player.h" #include #include // Include this header to use numeric_limits #include @@ -43,43 +42,7 @@ class Pokemon { void attack() { cout << name << " attacks with a powerful move!\n"; } }; -// Player class definition -class Player { -public: - string name; - Pokemon chosenPokemon; - - // Default constructor - Player() { - name = "Trainer"; - chosenPokemon = Pokemon(); // Using the default Pokemon constructor - } - - // Parameterized constructor - Player(string p_name, Pokemon p_chosenPokemon) { - name = p_name; - chosenPokemon = p_chosenPokemon; - } - - void choosePokemon(int choice) { - switch ((PokemonChoice)choice) { - case PokemonChoice::CHARMANDER: - chosenPokemon = Pokemon("Charmander", PokemonType::FIRE, 100); - break; - case PokemonChoice::BULBASAUR: - chosenPokemon = Pokemon("Bulbasaur", PokemonType::GRASS, 100); - break; - case PokemonChoice::SQUIRTLE: - chosenPokemon = Pokemon("Squirtle", PokemonType::WATER, 100); - break; - default: - chosenPokemon = Pokemon("Pikachu", PokemonType::ELECTRIC, 100); - break; - } - cout << "Player " << name << " chose " << chosenPokemon.name << "!\n"; - utility::waitForEnter(); // Wait for user to press Enter before proceeding - } -}; +#include "player.h" // ProfessorOak class definition class ProfessorOak { diff --git a/Pokemon/player.cpp b/Pokemon/player.cpp index cfaaadf7..3da5011b 100644 --- a/Pokemon/player.cpp +++ b/Pokemon/player.cpp @@ -1,19 +1,19 @@ +// Player.cpp #include "player.h" -#include +#include "iostream" +using namespace std; -// Default constructor -player::player() { +Player::Player() { name = "Trainer"; chosenPokemon = Pokemon(); // Using the default Pokemon constructor } -// Parameterized constructor -player::player(string p_name, Pokemon p_chosenPokemon) { +Player::Player(string p_name, Pokemon p_chosenPokemon) { name = p_name; chosenPokemon = p_chosenPokemon; } -void player::choosePokemon(int choice) { +void Player::choosePokemon(int choice) { switch ((PokemonChoice)choice) { case PokemonChoice::CHARMANDER: chosenPokemon = Pokemon("Charmander", PokemonType::FIRE, 100); @@ -25,6 +25,7 @@ void player::choosePokemon(int choice) { chosenPokemon = Pokemon("Squirtle", PokemonType::WATER, 100); break; default: + chosenPokemon = Pokemon("Pikachu", PokemonType::ELECTRIC, 100); chosenPokemon = Pokemon("Pikachu", PokemonType::ELECTRIC, 100); break; } diff --git a/Pokemon/player.h b/Pokemon/player.h index 98562a80..afb1568c 100644 --- a/Pokemon/player.h +++ b/Pokemon/player.h @@ -1,17 +1,17 @@ -#include -#include"PokemonChoice.h" -#include"PokemonType.h" -#include"utility.h" +// Player.h +#include +#include "PokemonType.h" +#include "PokemonChoice.h" +#include "utility.h" using namespace std; -class player -{ -public: - string name; - Pokemon chosenPokemon; - player();//default constructor - player(string p_name, Pokemon p_chosenPokemon);//Parameterized constructor +class Player { +public: + string name; + Pokemon chosenPokemon; - void choosePokemon(int choice);//Method to choose pokemon -}; + Player(); // Default constructor + Player(string p_name, Pokemon p_chosenPokemon); // Parameterized constructor + void choosePokemon(int choice); // Method to choose a Pokemon +}; \ No newline at end of file From 563d1aa1b955a62836622f187f0a7220f789fe80 Mon Sep 17 00:00:00 2001 From: Pranav Bardiwale Date: Thu, 31 Jul 2025 01:08:32 +0530 Subject: [PATCH 12/27] #included --- Pokemon/player.cpp | 3 +++ Pokemon/player.h | 3 --- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Pokemon/player.cpp b/Pokemon/player.cpp index 3da5011b..359662aa 100644 --- a/Pokemon/player.cpp +++ b/Pokemon/player.cpp @@ -1,5 +1,8 @@ // Player.cpp #include "player.h" +#include "PokemonChoice.h" +#include "PokemonType.h" +#include "utility.h" #include "iostream" using namespace std; diff --git a/Pokemon/player.h b/Pokemon/player.h index afb1568c..7b7b7d57 100644 --- a/Pokemon/player.h +++ b/Pokemon/player.h @@ -1,8 +1,5 @@ // Player.h #include -#include "PokemonType.h" -#include "PokemonChoice.h" -#include "utility.h" using namespace std; class Player { From 3d8fd92ff8723eb9903a01e337acf460cf673e41 Mon Sep 17 00:00:00 2001 From: Pranav Bardiwale Date: Thu, 31 Jul 2025 02:17:57 +0530 Subject: [PATCH 13/27] Good going --- Pokemon/Pokemon.cpp | 19 +++++++++++++++++++ Pokemon/Pokemon.h | 24 ++++++++++++++++++++++++ Pokemon/main.cpp | 4 ++-- Pokemon/player.h | 1 + 4 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 Pokemon/Pokemon.cpp create mode 100644 Pokemon/Pokemon.h diff --git a/Pokemon/Pokemon.cpp b/Pokemon/Pokemon.cpp new file mode 100644 index 00000000..3b2c1b6a --- /dev/null +++ b/Pokemon/Pokemon.cpp @@ -0,0 +1,19 @@ +#include "Pokemon.h" +#include + +Pokemon::Pokemon():name("unknown"),type(PokemonType::NORMAL),health(50){} +// Parameterized constructor +Pokemon::Pokemon(string p_name, PokemonType p_type, int p_health): name(p_name), +type(p_type), +health(p_health) { +} + +// Copy constructor +Pokemon::Pokemon(const Pokemon& other):name(other.name),type(other.type),health(other.health) {} + +// Destructor +Pokemon::~Pokemon() { + // Destructor message removed +} + +void Pokemon::attack() { cout << name << " attacks with a powerful move!\n"; } \ No newline at end of file diff --git a/Pokemon/Pokemon.h b/Pokemon/Pokemon.h new file mode 100644 index 00000000..03e8fef3 --- /dev/null +++ b/Pokemon/Pokemon.h @@ -0,0 +1,24 @@ +#include +#include "PokemonType.h" +using namespace std; + +class Pokemon { +public: + string name; + PokemonType type; + int health; + + // Default constructor + Pokemon(); + + // Parameterized constructor + Pokemon(string p_name, PokemonType p_type, int p_health); + + // Copy constructor + Pokemon(const Pokemon& other); + + // Destructor + ~Pokemon(); + + void attack(); +}; \ No newline at end of file diff --git a/Pokemon/main.cpp b/Pokemon/main.cpp index 8b21ed08..6d2192c4 100644 --- a/Pokemon/main.cpp +++ b/Pokemon/main.cpp @@ -6,7 +6,7 @@ #include using namespace std; -// Pokemon class definition +/*/ Pokemon class definition class Pokemon { public: string name; @@ -40,7 +40,7 @@ class Pokemon { } void attack() { cout << name << " attacks with a powerful move!\n"; } -}; +};*/ #include "player.h" diff --git a/Pokemon/player.h b/Pokemon/player.h index 7b7b7d57..25fa68f2 100644 --- a/Pokemon/player.h +++ b/Pokemon/player.h @@ -1,5 +1,6 @@ // Player.h #include +#include "Pokemon.h" using namespace std; class Player { From 5c143c9fbbd83667a1fd0dc07901c63ff8fe230b Mon Sep 17 00:00:00 2001 From: Pranav Bardiwale Date: Thu, 31 Jul 2025 02:52:57 +0530 Subject: [PATCH 14/27] Can't understand the error,need help --- Pokemon/Pokemon.cpp | 1 + Pokemon/Pokemon.h | 3 ++- Pokemon/main.cpp | 45 +++++---------------------------------------- Pokemon/player.cpp | 1 + Pokemon/player.h | 3 ++- 5 files changed, 11 insertions(+), 42 deletions(-) diff --git a/Pokemon/Pokemon.cpp b/Pokemon/Pokemon.cpp index 3b2c1b6a..ba7e8b34 100644 --- a/Pokemon/Pokemon.cpp +++ b/Pokemon/Pokemon.cpp @@ -1,5 +1,6 @@ #include "Pokemon.h" #include +#include"PokemonType.h" Pokemon::Pokemon():name("unknown"),type(PokemonType::NORMAL),health(50){} // Parameterized constructor diff --git a/Pokemon/Pokemon.h b/Pokemon/Pokemon.h index 03e8fef3..f7f8a549 100644 --- a/Pokemon/Pokemon.h +++ b/Pokemon/Pokemon.h @@ -1,7 +1,8 @@ #include -#include "PokemonType.h" using namespace std; +enum class PokemonType; + class Pokemon { public: string name; diff --git a/Pokemon/main.cpp b/Pokemon/main.cpp index 6d2192c4..eea74a8d 100644 --- a/Pokemon/main.cpp +++ b/Pokemon/main.cpp @@ -1,49 +1,14 @@ +class Player; +class Pokemon; +enum PokemonType; #include "PokemonChoice.h" -#include "PokemonType.h" -#include "utility.h" + +#include "Utility.h" #include #include // Include this header to use numeric_limits #include using namespace std; -/*/ Pokemon class definition -class Pokemon { -public: - string name; - PokemonType type; - int health; - - // Default constructor - Pokemon() { - name = "Unknown"; - type = PokemonType::NORMAL; - health = 50; - } - - // Parameterized constructor - Pokemon(string p_name, PokemonType p_type, int p_health) { - name = p_name; - type = p_type; - health = p_health; - } - - // Copy constructor - Pokemon(const Pokemon& other) { - name = other.name; - type = other.type; - health = other.health; - } - - // Destructor - ~Pokemon() { - // Destructor message removed - } - - void attack() { cout << name << " attacks with a powerful move!\n"; } -};*/ - -#include "player.h" - // ProfessorOak class definition class ProfessorOak { public: diff --git a/Pokemon/player.cpp b/Pokemon/player.cpp index 359662aa..4b7c8cdb 100644 --- a/Pokemon/player.cpp +++ b/Pokemon/player.cpp @@ -2,6 +2,7 @@ #include "player.h" #include "PokemonChoice.h" #include "PokemonType.h" +#include "Pokemon.h" #include "utility.h" #include "iostream" using namespace std; diff --git a/Pokemon/player.h b/Pokemon/player.h index 25fa68f2..6a2beb0b 100644 --- a/Pokemon/player.h +++ b/Pokemon/player.h @@ -1,8 +1,9 @@ // Player.h #include -#include "Pokemon.h" using namespace std; +class Pokemon; + class Player { public: string name; From 3620d014fb89032e876d9a606ef0b8a4224f9781 Mon Sep 17 00:00:00 2001 From: Pranav Bardiwale Date: Thu, 31 Jul 2025 03:11:12 +0530 Subject: [PATCH 15/27] greetings --- Pokemon/main.cpp | 6 ++---- Pokemon/player.h | 4 +--- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/Pokemon/main.cpp b/Pokemon/main.cpp index eea74a8d..d5349b7f 100644 --- a/Pokemon/main.cpp +++ b/Pokemon/main.cpp @@ -1,13 +1,11 @@ -class Player; -class Pokemon; -enum PokemonType; #include "PokemonChoice.h" - +#include "PokemonType.h" #include "Utility.h" #include #include // Include this header to use numeric_limits #include using namespace std; +#include "player.h" // ProfessorOak class definition class ProfessorOak { diff --git a/Pokemon/player.h b/Pokemon/player.h index 6a2beb0b..eb38a581 100644 --- a/Pokemon/player.h +++ b/Pokemon/player.h @@ -1,9 +1,7 @@ // Player.h #include +#include "Pokemon.h" using namespace std; - -class Pokemon; - class Player { public: string name; From d2a4cbf4da058c0476e7fda8bd1faa6ff3e02597 Mon Sep 17 00:00:00 2001 From: Pranav Bardiwale Date: Fri, 1 Aug 2025 18:08:28 +0530 Subject: [PATCH 16/27] We did it misty! --- Pokemon/Game.cpp | 70 +++++++++++++++++ Pokemon/Game.h | 9 +++ Pokemon/Grass.cpp | 14 ++++ Pokemon/Grass.h | 12 +++ Pokemon/main.cpp | 191 ++-------------------------------------------- 5 files changed, 112 insertions(+), 184 deletions(-) create mode 100644 Pokemon/Game.cpp create mode 100644 Pokemon/Game.h create mode 100644 Pokemon/Grass.cpp create mode 100644 Pokemon/Grass.h diff --git a/Pokemon/Game.cpp b/Pokemon/Game.cpp new file mode 100644 index 00000000..75afc5f8 --- /dev/null +++ b/Pokemon/Game.cpp @@ -0,0 +1,70 @@ +#include "Game.h" +#include "player.h" +#include "utility.h" + +Game::Game() { +} + +// Function to handle the main game loop +void Game::gameLoop(Player& player) { + int choice; + bool keepPlaying = true; + + while (keepPlaying) { + // Clear console before showing options + utility::clearConsole(); + + // Display options to the player + cout << "\nWhat would you like to do next, " << player.name << "?\n"; + cout << "1. Battle Wild Pokémon\n"; + cout << "2. Visit PokeCenter\n"; + cout << "3. Challenge Gyms\n"; + cout << "4. Enter Pokémon League\n"; + cout << "5. Quit\n"; + cout << "Enter your choice: "; + cin >> choice; + + utility::clearInputBuffer(); // Clear the input buffer + + // Process the player's choice and display the corresponding message + switch (choice) { + case 1: + cout << "You look around... but all the wild Pokémon are on " + "vacation. Maybe try again later?\n"; + break; + case 2: + cout + << "You head to the PokeCenter, but Nurse Joy is out on a coffee " + "break. Guess your Pokémon will have to tough it out for now!\n"; + break; + case 3: + cout << "You march up to the Gym, but it's closed for renovations. " + "Seems like even Gym Leaders need a break!\n"; + break; + case 4: + cout << "You boldly step towards the Pokémon League... but the " + "gatekeeper laughs and says, 'Maybe next time, champ!'\n"; + break; + case 5: + cout << "You try to quit, but Professor Oak's voice echoes: " + "'There's no quitting in Pokémon training!'\n"; + cout << "Are you sure you want to quit? (y/n): "; + char quitChoice; + cin >> quitChoice; + if (quitChoice == 'y' || quitChoice == 'Y') { + keepPlaying = false; + } + break; + default: + cout << "That's not a valid choice. Try again!\n"; + break; + } + + // Wait for Enter key before the screen is cleared and the menu is shown + // again + utility::waitForEnter(); + } + + cout << "Goodbye, " << player.name << "! Thanks for playing!\n"; +} + diff --git a/Pokemon/Game.h b/Pokemon/Game.h new file mode 100644 index 00000000..7189ee48 --- /dev/null +++ b/Pokemon/Game.h @@ -0,0 +1,9 @@ +#include +class Game +{ +public: + Game(); + // Function to handle the main game loop + void gameLoop(Player& player); +}; + diff --git a/Pokemon/Grass.cpp b/Pokemon/Grass.cpp new file mode 100644 index 00000000..4ddd09f0 --- /dev/null +++ b/Pokemon/Grass.cpp @@ -0,0 +1,14 @@ +#include "Grass.h" +#include"Pokemon.h" + +Grass forestGrass = { + "Forest", + {{"Pidgey", PokemonType::NORMAL, 40}, {"Caterpie", PokemonType::BUG, 35}}, + 70 +}; + +Grass caveGrass = { + "Cave", + {{"Zubat", PokemonType::POISON, 30}, {"Geodude", PokemonType::ROCK, 50}}, + 80 +}; \ No newline at end of file diff --git a/Pokemon/Grass.h b/Pokemon/Grass.h new file mode 100644 index 00000000..3c0c5c93 --- /dev/null +++ b/Pokemon/Grass.h @@ -0,0 +1,12 @@ +#include +#include +#include"Pokemon.h" +using namespace std; + +struct Grass{ + string environmentType; // Example: "Forest", "Cave", "Riverbank" + vector wildPokemonlist; // List of wild Pokémon that live in this grass + int encounterRate; // Likelihood of encountering a wild Pokémon, out of 100 + +}; + diff --git a/Pokemon/main.cpp b/Pokemon/main.cpp index d5349b7f..88776d2a 100644 --- a/Pokemon/main.cpp +++ b/Pokemon/main.cpp @@ -1,194 +1,16 @@ -#include "PokemonChoice.h" -#include "PokemonType.h" -#include "Utility.h" +#include"Game.h" +#include"player.h" +#include"ProfessorOak.h" #include #include // Include this header to use numeric_limits #include using namespace std; -#include "player.h" - -// ProfessorOak class definition -class ProfessorOak { -public: - string name; - - // Parameterized constructor - ProfessorOak(string p_name) { name = p_name; } - - void greetPlayer(Player& player) { - cout << name << ": Hello there! Welcome to the world of Pokemon!\n"; - utility::waitForEnter(); - cout << name - << ": My name is Oak. People call me the Pokemon Professor!\n"; - utility::waitForEnter(); - cout << name << ": But enough about me. Let's talk about you!\n"; - utility::waitForEnter(); - } - - void offerPokemonChoices(Player& player) { - cout - << name - << ": First, tell me, what’s your name? \t [Please Enter Your Name]\n"; - getline(cin, player.name); - cout << name << ": Ah, " << player.name - << "! What a fantastic name!\n"; - utility::waitForEnter(); - cout << name - << ": You must be eager to start your adventure. But first, " - "you’ll need a Pokemon of your own!\n"; - utility::waitForEnter(); - - // Presenting Pokemon choices - cout - << name - << ": I have three Pokemon here with me. They’re all quite feisty!\n"; - utility::waitForEnter(); - cout << name << ": Choose wisely...\n"; - cout << "1. Charmander - The fire type. A real hothead!\n"; - cout << "2. Bulbasaur - The grass type. Calm and collected!\n"; - cout << "3. Squirtle - The water type. Cool as a cucumber!\n"; - - int choice; - cout - << name - << ": So, which one will it be? Enter the number of your choice: "; - cin >> choice; - - player.choosePokemon(choice); - utility::waitForEnter(); - } - - // New method for the main quest conversation - void explainMainQuest(Player& player) { - // Clear the console - utility::clearConsole(); - - cout << "Professor Oak: " << player.name - << "!, I am about to explain you about your upcoming grand " - "adventure.\n"; - utility::waitForEnter(); - cout << "Professor Oak: You see, becoming a Pokémon Master is no easy " - "feat. It takes courage, wisdom, and a bit of luck!\n"; - utility::waitForEnter(); - cout - << "Professor Oak: Your mission, should you choose to accept it—and " - "trust me, you really don’t have a choice—is to collect all the " - "Pokémon Badges and conquer the Pokémon League.\n"; - utility::waitForEnter(); - - cout << "\n" - << player.name - << ": Wait... that sounds a lot like every other Pokémon game " - "out there...\n"; - utility::waitForEnter(); - cout << "Professor Oak: Shhh! Don't break the fourth wall, " - << player.name << "! This is serious business!\n"; - utility::waitForEnter(); - - cout << "\nProfessor Oak: To achieve this, you’ll need to battle wild " - "Pokémon, challenge gym leaders, and of course, keep your " - "Pokémon healthy at the PokeCenter.\n"; - utility::waitForEnter(); - cout << "Professor Oak: Along the way, you'll capture new Pokémon to " - "strengthen your team. Just remember—there’s a limit to how " - "many Pokémon you can carry, so choose wisely!\n"; - utility::waitForEnter(); - - cout << "\n" - << player.name << ": Sounds like a walk in the park... right?\n"; - utility::waitForEnter(); - cout << "Professor Oak: Hah! That’s what they all say! But beware, " - "young Trainer, the path to victory is fraught with " - "challenges. And if you lose a battle... well, let’s just say " - "you'll be starting from square one.\n"; - utility::waitForEnter(); - - cout << "\nProfessor Oak: So, what do you say? Are you ready to " - "become the next Pokémon Champion?\n"; - utility::waitForEnter(); - cout << "\n" << player.name << ": Ready as I’ll ever be, Professor!\n"; - utility::waitForEnter(); - - cout - << "\nProfessor Oak: That’s the spirit! Now, your journey begins...\n"; - utility::waitForEnter(); - cout << "Professor Oak: But first... let's just pretend I didn't " - "forget to set up the actual game loop... Ahem, onwards!\n"; - utility::waitForEnter(); - } -}; - -// Function to handle the main game loop -void gameLoop(Player& player) { - int choice; - bool keepPlaying = true; - - while (keepPlaying) { - // Clear console before showing options - utility::clearConsole(); - - // Display options to the player - cout << "\nWhat would you like to do next, " << player.name << "?\n"; - cout << "1. Battle Wild Pokémon\n"; - cout << "2. Visit PokeCenter\n"; - cout << "3. Challenge Gyms\n"; - cout << "4. Enter Pokémon League\n"; - cout << "5. Quit\n"; - cout << "Enter your choice: "; - cin >> choice; - - utility::clearInputBuffer(); // Clear the input buffer - - // Process the player's choice and display the corresponding message - switch (choice) { - case 1: - cout << "You look around... but all the wild Pokémon are on " - "vacation. Maybe try again later?\n"; - break; - case 2: - cout - << "You head to the PokeCenter, but Nurse Joy is out on a coffee " - "break. Guess your Pokémon will have to tough it out for now!\n"; - break; - case 3: - cout << "You march up to the Gym, but it's closed for renovations. " - "Seems like even Gym Leaders need a break!\n"; - break; - case 4: - cout << "You boldly step towards the Pokémon League... but the " - "gatekeeper laughs and says, 'Maybe next time, champ!'\n"; - break; - case 5: - cout << "You try to quit, but Professor Oak's voice echoes: " - "'There's no quitting in Pokémon training!'\n"; - cout << "Are you sure you want to quit? (y/n): "; - char quitChoice; - cin >> quitChoice; - if (quitChoice == 'y' || quitChoice == 'Y') { - keepPlaying = false; - } - break; - default: - cout << "That's not a valid choice. Try again!\n"; - break; - } - - // Wait for Enter key before the screen is cleared and the menu is shown - // again - utility::waitForEnter(); - } - - cout << "Goodbye, " << player.name << "! Thanks for playing!\n"; -} int main() { - // Create Pokemon and Player objects for the game - Pokemon charmander("Charmander", PokemonType::FIRE, - 100); // Using parameterized constructor - + // Continue with the main flow of the game ProfessorOak professor("Professor Oak"); - Player player("Ash", charmander); + Player player; // Greet the player and offer Pokemon choices professor.greetPlayer(player); @@ -198,7 +20,8 @@ int main() { professor.explainMainQuest(player); // Start the main game loop - gameLoop(player); + Game game; + game.gameLoop(player); return 0; } \ No newline at end of file From dd4052683b8b7a22b75ca32843a1392c5ae62bbf Mon Sep 17 00:00:00 2001 From: Pranav Bardiwale Date: Sat, 2 Aug 2025 01:52:32 +0530 Subject: [PATCH 17/27] identifier "WildPokemon" is undefined --- Pokemon/Game.cpp | 58 ++++++++++++++++++++------------ Pokemon/Game.h | 18 +++++----- Pokemon/Grass.cpp | 2 +- Pokemon/Grass.h | 2 +- Pokemon/WildEncounterManager.cpp | 12 +++++++ Pokemon/WildEncounterManager.h | 8 +++++ Pokemon/utility.cpp | 7 ++-- Pokemon/utility.h | 5 ++- 8 files changed, 75 insertions(+), 37 deletions(-) create mode 100644 Pokemon/WildEncounterManager.cpp create mode 100644 Pokemon/WildEncounterManager.h diff --git a/Pokemon/Game.cpp b/Pokemon/Game.cpp index 75afc5f8..48391b53 100644 --- a/Pokemon/Game.cpp +++ b/Pokemon/Game.cpp @@ -1,18 +1,28 @@ #include "Game.h" -#include "player.h" +#include "Player.h" +#include "PokemonType.h" #include "utility.h" +#include "WildEncounterManager.h" +#include +using namespace std; Game::Game() { + // Create a sample grass environment with actual Pokemon objects + forestGrass = { "Forest", + {Pokemon("Pidgey", PokemonType::NORMAL, 40), + Pokemon("Caterpie", PokemonType::BUG, 35), + Pokemon("Zubat", PokemonType::POISON, 30)}, + 70 }; } -// Function to handle the main game loop void Game::gameLoop(Player& player) { + int choice; bool keepPlaying = true; while (keepPlaying) { // Clear console before showing options - utility::clearConsole(); + Utility::clearConsole(); // Display options to the player cout << "\nWhat would you like to do next, " << player.name << "?\n"; @@ -24,30 +34,35 @@ void Game::gameLoop(Player& player) { cout << "Enter your choice: "; cin >> choice; - utility::clearInputBuffer(); // Clear the input buffer + Utility::clearInputBuffer(); // Clear the input buffer // Process the player's choice and display the corresponding message switch (choice) { - case 1: - cout << "You look around... but all the wild Pokémon are on " - "vacation. Maybe try again later?\n"; + case 1: { + // Create a scope within case 1 + WildEncounterManager encounterManager; + Pokemon encounteredPokemon = encounterManager.getRandomPokemonFromGrass(forestGrass); + cout << "A wild " << encounteredPokemon.name << " appeared!\n"; break; - case 2: - cout - << "You head to the PokeCenter, but Nurse Joy is out on a coffee " + } + case 2: { + cout << "You head to the PokeCenter, but Nurse Joy is out on a coffee " "break. Guess your Pokémon will have to tough it out for now!\n"; break; - case 3: - cout << "You march up to the Gym, but it's closed for renovations. " - "Seems like even Gym Leaders need a break!\n"; + } + case 3: { + cout << "You march up to the Gym, but it's closed for renovations. Seems " + "like even Gym Leaders need a break!\n"; break; - case 4: + } + case 4: { cout << "You boldly step towards the Pokémon League... but the " "gatekeeper laughs and says, 'Maybe next time, champ!'\n"; break; - case 5: - cout << "You try to quit, but Professor Oak's voice echoes: " - "'There's no quitting in Pokémon training!'\n"; + } + case 5: { + cout << "You try to quit, but Professor Oak's voice echoes: 'There's no " + "quitting in Pokémon training!'\n"; cout << "Are you sure you want to quit? (y/n): "; char quitChoice; cin >> quitChoice; @@ -55,16 +70,17 @@ void Game::gameLoop(Player& player) { keepPlaying = false; } break; - default: + } + default: { cout << "That's not a valid choice. Try again!\n"; break; } + } // Wait for Enter key before the screen is cleared and the menu is shown // again - utility::waitForEnter(); + Utility::waitForEnter(); } cout << "Goodbye, " << player.name << "! Thanks for playing!\n"; -} - +} \ No newline at end of file diff --git a/Pokemon/Game.h b/Pokemon/Game.h index 7189ee48..e5d3602a 100644 --- a/Pokemon/Game.h +++ b/Pokemon/Game.h @@ -1,9 +1,11 @@ -#include -class Game -{ -public: - Game(); - // Function to handle the main game loop - void gameLoop(Player& player); -}; +#include "Grass.h" + +class Player; +class Game { +private: + Grass forestGrass; +public: + Game(); + void gameLoop(Player& player); +}; \ No newline at end of file diff --git a/Pokemon/Grass.cpp b/Pokemon/Grass.cpp index 4ddd09f0..7378afdd 100644 --- a/Pokemon/Grass.cpp +++ b/Pokemon/Grass.cpp @@ -1,5 +1,5 @@ #include "Grass.h" -#include"Pokemon.h" +#include"PokemonType.h" Grass forestGrass = { "Forest", diff --git a/Pokemon/Grass.h b/Pokemon/Grass.h index 3c0c5c93..0c0c9516 100644 --- a/Pokemon/Grass.h +++ b/Pokemon/Grass.h @@ -5,7 +5,7 @@ using namespace std; struct Grass{ string environmentType; // Example: "Forest", "Cave", "Riverbank" - vector wildPokemonlist; // List of wild Pokémon that live in this grass + vector wildPokemonList; // List of wild Pokémon that live in this grass int encounterRate; // Likelihood of encountering a wild Pokémon, out of 100 }; diff --git a/Pokemon/WildEncounterManager.cpp b/Pokemon/WildEncounterManager.cpp new file mode 100644 index 00000000..63bd053e --- /dev/null +++ b/Pokemon/WildEncounterManager.cpp @@ -0,0 +1,12 @@ +#include "WildEncounterManager.h" +#include // For rand() +#include // For time() + +WildEncounterManager::WildEncounterManager() { + srand(time(0)); // Seed the random number generator +} + +WildPokemon WildEncounterManager::getRandomPokemonFromGrass(const Grass& grass) { + int randomIndex = rand() % grass.wildPokemonList.size(); + return grass.wildPokemonList[randomIndex]; +} \ No newline at end of file diff --git a/Pokemon/WildEncounterManager.h b/Pokemon/WildEncounterManager.h new file mode 100644 index 00000000..7ff1d749 --- /dev/null +++ b/Pokemon/WildEncounterManager.h @@ -0,0 +1,8 @@ +#include +#include "Grass.h" // Assuming the Grass struct is defined here + +class WildEncounterManager { +public: + WildPokemon getRandomPokemonFromGrass(const Grass& grass + ); +}; diff --git a/Pokemon/utility.cpp b/Pokemon/utility.cpp index 3ad2a280..eab18a0c 100644 --- a/Pokemon/utility.cpp +++ b/Pokemon/utility.cpp @@ -3,7 +3,7 @@ #include using namespace std; -void utility::clearConsole() { +void Utility::clearConsole() { #ifdef _WIN32 system("cls"); #else @@ -11,9 +11,10 @@ void utility::clearConsole() { #endif } -void utility::waitForEnter() { +void Utility::waitForEnter() { cin.get(); } -void utility::clearInputBuffer(){ +void Utility::clearInputBuffer(){ + cin.ignore(numeric_limits::max(), '\n'); } \ No newline at end of file diff --git a/Pokemon/utility.h b/Pokemon/utility.h index ca322012..b8849d92 100644 --- a/Pokemon/utility.h +++ b/Pokemon/utility.h @@ -1,6 +1,5 @@ -#pragma once -class utility -{ +#include +class Utility{ public : static void clearConsole(); static void waitForEnter(); From 5cdff4a446440662ef739c83a0a3ae986ee149fc Mon Sep 17 00:00:00 2001 From: Pranav Bardiwale Date: Sat, 2 Aug 2025 01:53:56 +0530 Subject: [PATCH 18/27] identifier "WildPokemon" is undefined --- Pokemon/PokemonType.h | 5 +- Pokemon/ProfessorOak.cpp | 109 +++++++++++++++++++++++++++++++++++++++ Pokemon/ProfessorOak.h | 18 +++++++ 3 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 Pokemon/ProfessorOak.cpp create mode 100644 Pokemon/ProfessorOak.h diff --git a/Pokemon/PokemonType.h b/Pokemon/PokemonType.h index 3806a62b..7ee5187a 100644 --- a/Pokemon/PokemonType.h +++ b/Pokemon/PokemonType.h @@ -4,5 +4,8 @@ enum class PokemonType { GRASS, WATER, ELECTRIC, - NORMAL // Added for the default constructor + NORMAL, + BUG, + POISON, + ROCK // Added for the default constructor }; \ No newline at end of file diff --git a/Pokemon/ProfessorOak.cpp b/Pokemon/ProfessorOak.cpp new file mode 100644 index 00000000..e710cc68 --- /dev/null +++ b/Pokemon/ProfessorOak.cpp @@ -0,0 +1,109 @@ +#include "ProfessorOak.h" +#include"utility.h" +#include "player.h" +#include + +// Parameterized constructor +ProfessorOak::ProfessorOak(string p_name) { name = p_name; } + +void ProfessorOak::greetPlayer(Player& player) { + cout << name << ": Hello there! Welcome to the world of Pokemon!\n"; + utility::waitForEnter(); + cout << name + << ": My name is Oak. People call me the Pokemon Professor!\n"; + utility::waitForEnter(); + cout << name << ": But enough about me. Let's talk about you!\n"; + utility::waitForEnter(); +} + +void ProfessorOak::offerPokemonChoices(Player& player) { + cout + << name + << ": First, tell me, what’s your name? \t [Please Enter Your Name]\n"; + getline(cin, player.name); + cout << name << ": Ah, " << player.name + << "! What a fantastic name!\n"; + utility::waitForEnter(); + cout << name + << ": You must be eager to start your adventure. But first, " + "you’ll need a Pokemon of your own!\n"; + utility::waitForEnter(); + + // Presenting Pokemon choices + cout + << name + << ": I have three Pokemon here with me. They’re all quite feisty!\n"; + utility::waitForEnter(); + cout << name << ": Choose wisely...\n"; + cout << "1. Charmander - The fire type. A real hothead!\n"; + cout << "2. Bulbasaur - The grass type. Calm and collected!\n"; + cout << "3. Squirtle - The water type. Cool as a cucumber!\n"; + + int choice; + cout + << name + << ": So, which one will it be? Enter the number of your choice: "; + cin >> choice; + + player.choosePokemon(choice); + utility::waitForEnter(); +} + +// New method for the main quest conversation +void ProfessorOak::explainMainQuest(Player& player) { + // Clear the console + utility::clearConsole(); + + cout << "Professor Oak: " << player.name + << "!, I am about to explain you about your upcoming grand " + "adventure.\n"; + utility::waitForEnter(); + cout << "Professor Oak: You see, becoming a Pokémon Master is no easy " + "feat. It takes courage, wisdom, and a bit of luck!\n"; + utility::waitForEnter(); + cout + << "Professor Oak: Your mission, should you choose to accept it—and " + "trust me, you really don’t have a choice—is to collect all the " + "Pokémon Badges and conquer the Pokémon League.\n"; + utility::waitForEnter(); + + cout << "\n" + << player.name + << ": Wait... that sounds a lot like every other Pokémon game " + "out there...\n"; + utility::waitForEnter(); + cout << "Professor Oak: Shhh! Don't break the fourth wall, " + << player.name << "! This is serious business!\n"; + utility::waitForEnter(); + + cout << "\nProfessor Oak: To achieve this, you’ll need to battle wild " + "Pokémon, challenge gym leaders, and of course, keep your " + "Pokémon healthy at the PokeCenter.\n"; + utility::waitForEnter(); + cout << "Professor Oak: Along the way, you'll capture new Pokémon to " + "strengthen your team. Just remember—there’s a limit to how " + "many Pokémon you can carry, so choose wisely!\n"; + utility::waitForEnter(); + + cout << "\n" + << player.name << ": Sounds like a walk in the park... right?\n"; + utility::waitForEnter(); + cout << "Professor Oak: Hah! That’s what they all say! But beware, " + "young Trainer, the path to victory is fraught with " + "challenges. And if you lose a battle... well, let’s just say " + "you'll be starting from square one.\n"; + utility::waitForEnter(); + + cout << "\nProfessor Oak: So, what do you say? Are you ready to " + "become the next Pokémon Champion?\n"; + utility::waitForEnter(); + cout << "\n" << player.name << ": Ready as I’ll ever be, Professor!\n"; + utility::waitForEnter(); + + cout + << "\nProfessor Oak: That’s the spirit! Now, your journey begins...\n"; + utility::waitForEnter(); + cout << "Professor Oak: But first... let's just pretend I didn't " + "forget to set up the actual game loop... Ahem, onwards!\n"; + utility::waitForEnter(); +} diff --git a/Pokemon/ProfessorOak.h b/Pokemon/ProfessorOak.h new file mode 100644 index 00000000..0b911a4e --- /dev/null +++ b/Pokemon/ProfessorOak.h @@ -0,0 +1,18 @@ +#include +using namespace std; + +// ProfessorOak class definition +class ProfessorOak { +public: + string name; + + // Parameterized constructor + ProfessorOak(string p_name); + + void greetPlayer(Player& player); + + void offerPokemonChoices(Player& player); + + // New method for the main quest conversation + void explainMainQuest(Player& player); +}; \ No newline at end of file From c045e167b0c1ceb5e4e79883d4533bfc83426303 Mon Sep 17 00:00:00 2001 From: Pranav Bardiwale Date: Sat, 2 Aug 2025 21:20:30 +0530 Subject: [PATCH 19/27] Ready for battle! --- Pokemon/BattleManager.cpp | 24 ++++++++++++++++++++++++ Pokemon/BattleManager.h | 5 +++++ Pokemon/Pokemon.cpp | 16 +++++++++++++++- Pokemon/Pokemon.h | 7 ++++++- Pokemon/WildEncounterManager.cpp | 3 ++- Pokemon/WildEncounterManager.h | 2 +- 6 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 Pokemon/BattleManager.cpp create mode 100644 Pokemon/BattleManager.h diff --git a/Pokemon/BattleManager.cpp b/Pokemon/BattleManager.cpp new file mode 100644 index 00000000..6e1e00a0 --- /dev/null +++ b/Pokemon/BattleManager.cpp @@ -0,0 +1,24 @@ +#include "BattleManager.h" +#include +#include "Pokemon.h" +#include "PokemonType.h" +using namespace std; + +void Battle(Pokemon& playerPokemon, Pokemon& wildPokemon) { + cout << "A wild " << wildPokemon.name << " appeared!\\n"; + + while (!playerPokemon.isFainted() && !wildPokemon.isFainted()) { + playerPokemon.attack(wildPokemon); // Player attacks first + + if (!wildPokemon.isFainted()) { + wildPokemon.attack(playerPokemon); // Wild Pokémon attacks back + } + } + + if (playerPokemon.isFainted()) { + cout << playerPokemon.name << " has fainted! You lose the battle.\\n"; + } + else { + cout << "You defeated the wild " << wildPokemon.name << "!\\n"; + } +} \ No newline at end of file diff --git a/Pokemon/BattleManager.h b/Pokemon/BattleManager.h new file mode 100644 index 00000000..1b6070df --- /dev/null +++ b/Pokemon/BattleManager.h @@ -0,0 +1,5 @@ +#include "Pokemon.h" +#include "PokemonType.h" + + +void Battle(Pokemon& playerPokemon, Pokemon& wildPokemon); \ No newline at end of file diff --git a/Pokemon/Pokemon.cpp b/Pokemon/Pokemon.cpp index ba7e8b34..0e9f151d 100644 --- a/Pokemon/Pokemon.cpp +++ b/Pokemon/Pokemon.cpp @@ -17,4 +17,18 @@ Pokemon::~Pokemon() { // Destructor message removed } -void Pokemon::attack() { cout << name << " attacks with a powerful move!\n"; } \ No newline at end of file +void Pokemon::attack(Pokemon& target) { + int damage = 10; // Example damage value, could be based on type or other factors + target.TakeDamage(damage); // Example damage value + cout << name << " attacks " << target.name << " for " << damage << " damage!\\n"; +} +void Pokemon::TakeDamage(int Damage) { + health -= Damage;// Reduce health by the damage taken + + if (health < 0) { + health = 0; // Ensure health doesn't go below 0 + } +} +bool Pokemon::isFainted() const { + return health <= 0; // Check if health is 0 or less +} \ No newline at end of file diff --git a/Pokemon/Pokemon.h b/Pokemon/Pokemon.h index f7f8a549..786a7181 100644 --- a/Pokemon/Pokemon.h +++ b/Pokemon/Pokemon.h @@ -8,6 +8,7 @@ class Pokemon { string name; PokemonType type; int health; + int maxHealth; // Default constructor Pokemon(); @@ -21,5 +22,9 @@ class Pokemon { // Destructor ~Pokemon(); - void attack(); + void attack(Pokemon & target); + + void TakeDamage(int damage); + + bool isFainted() const; }; \ No newline at end of file diff --git a/Pokemon/WildEncounterManager.cpp b/Pokemon/WildEncounterManager.cpp index 63bd053e..a9f116c8 100644 --- a/Pokemon/WildEncounterManager.cpp +++ b/Pokemon/WildEncounterManager.cpp @@ -2,11 +2,12 @@ #include // For rand() #include // For time() + WildEncounterManager::WildEncounterManager() { srand(time(0)); // Seed the random number generator } -WildPokemon WildEncounterManager::getRandomPokemonFromGrass(const Grass& grass) { +Pokemon WildEncounterManager::getRandomPokemonFromGrass(const Grass& grass) { int randomIndex = rand() % grass.wildPokemonList.size(); return grass.wildPokemonList[randomIndex]; } \ No newline at end of file diff --git a/Pokemon/WildEncounterManager.h b/Pokemon/WildEncounterManager.h index 7ff1d749..534cc6aa 100644 --- a/Pokemon/WildEncounterManager.h +++ b/Pokemon/WildEncounterManager.h @@ -3,6 +3,6 @@ class WildEncounterManager { public: - WildPokemon getRandomPokemonFromGrass(const Grass& grass + Pokemon getRandomPokemonFromGrass(const Grass& grass ); }; From 89ea3d4e9a081c60dd1413c50ad6f127ba5fa43a Mon Sep 17 00:00:00 2001 From: Pranav Bardiwale Date: Sat, 2 Aug 2025 22:17:12 +0530 Subject: [PATCH 20/27] Healing battle --- Pokemon/Game.cpp | 5 +++-- Pokemon/Pokemon.cpp | 7 ++++++- Pokemon/Pokemon.h | 3 +++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Pokemon/Game.cpp b/Pokemon/Game.cpp index 48391b53..f71f1ff2 100644 --- a/Pokemon/Game.cpp +++ b/Pokemon/Game.cpp @@ -46,8 +46,9 @@ void Game::gameLoop(Player& player) { break; } case 2: { - cout << "You head to the PokeCenter, but Nurse Joy is out on a coffee " - "break. Guess your Pokémon will have to tough it out for now!\n"; + cout << "You head to the PokeCenter.\\n"; + player.chosenPokemon.heal(); + cout << player.chosenPokemon.name << " has been healed to full health!\n"; break; } case 3: { diff --git a/Pokemon/Pokemon.cpp b/Pokemon/Pokemon.cpp index 0e9f151d..f5f4b5d8 100644 --- a/Pokemon/Pokemon.cpp +++ b/Pokemon/Pokemon.cpp @@ -18,7 +18,7 @@ Pokemon::~Pokemon() { } void Pokemon::attack(Pokemon& target) { - int damage = 10; // Example damage value, could be based on type or other factors + int damage = attackPower; // Example damage value, could be based on type or other factors target.TakeDamage(damage); // Example damage value cout << name << " attacks " << target.name << " for " << damage << " damage!\\n"; } @@ -31,4 +31,9 @@ void Pokemon::TakeDamage(int Damage) { } bool Pokemon::isFainted() const { return health <= 0; // Check if health is 0 or less +} + +int Pokemon::heal() { + int healAmount = maxHealth; // Example heal amount + return health; // Return the new health value } \ No newline at end of file diff --git a/Pokemon/Pokemon.h b/Pokemon/Pokemon.h index 786a7181..7271f11c 100644 --- a/Pokemon/Pokemon.h +++ b/Pokemon/Pokemon.h @@ -9,6 +9,7 @@ class Pokemon { PokemonType type; int health; int maxHealth; + int attackPower; // Default constructor Pokemon(); @@ -27,4 +28,6 @@ class Pokemon { void TakeDamage(int damage); bool isFainted() const; + + int heal(); }; \ No newline at end of file From bea99f112c26d15e5ac059b20596216cd8bc436c Mon Sep 17 00:00:00 2001 From: Pranav Bardiwale Date: Sun, 3 Aug 2025 00:32:52 +0530 Subject: [PATCH 21/27] Ready for Battle! --- Pokemon/BattleManager.cpp | 24 +++++++++++++++++++++--- Pokemon/BattleManager.h | 12 +++++++++--- Pokemon/Game.cpp | 6 ++++-- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/Pokemon/BattleManager.cpp b/Pokemon/BattleManager.cpp index 6e1e00a0..ea406946 100644 --- a/Pokemon/BattleManager.cpp +++ b/Pokemon/BattleManager.cpp @@ -2,23 +2,41 @@ #include #include "Pokemon.h" #include "PokemonType.h" +#include "utility.h" using namespace std; -void Battle(Pokemon& playerPokemon, Pokemon& wildPokemon) { - cout << "A wild " << wildPokemon.name << " appeared!\\n"; +void BattleManager::startBattle(Player& player, Pokemon& wildPokemon) { + cout<<"A wild "<< wildPokemon.name << " appeared!\n"; + // Start the battle with the player's chosen Pokémon + Battle(player.chosenPokemon, wildPokemon); +} +void BattleManager::Battle(Pokemon& playerPokemon, Pokemon& wildPokemon) { while (!playerPokemon.isFainted() && !wildPokemon.isFainted()) { playerPokemon.attack(wildPokemon); // Player attacks first if (!wildPokemon.isFainted()) { wildPokemon.attack(playerPokemon); // Wild Pokémon attacks back } + //Pause to show battle progress + Utility::waitForEnter(); } - if (playerPokemon.isFainted()) { + /*if (playerPokemon.isFainted()) { cout << playerPokemon.name << " has fainted! You lose the battle.\\n"; } else { cout << "You defeated the wild " << wildPokemon.name << "!\\n"; + }*/ +} + +void BattleManager::handleBattleOutcome(Player& player, bool playerWon) { + if (playerWon) { + std::cout << player.chosenPokemon.name << " is victorious! Keep an eye on your Pokémon's health.\n"; + } + else { + std::cout << "Oh no! " << player.chosenPokemon.name << " fainted! You need to visit the PokeCenter.\n"; + Utility::waitForEnter(); + std::cout << "Game Over.\n"; } } \ No newline at end of file diff --git a/Pokemon/BattleManager.h b/Pokemon/BattleManager.h index 1b6070df..48c472cc 100644 --- a/Pokemon/BattleManager.h +++ b/Pokemon/BattleManager.h @@ -1,5 +1,11 @@ #include "Pokemon.h" -#include "PokemonType.h" +#include "Player.h" - -void Battle(Pokemon& playerPokemon, Pokemon& wildPokemon); \ No newline at end of file +class BattleManager { +public: + // Function to handle the battle between player's Pokémon and wild Pokémon + void startBattle(Player& player, Pokemon& wildPokemon); +private: + void Battle(Pokemon& playerPokemon, Pokemon& wildPokemon); + void handleBattleOutcome(Player& player, bool playerWon); +}; \ No newline at end of file diff --git a/Pokemon/Game.cpp b/Pokemon/Game.cpp index f71f1ff2..859fa8c0 100644 --- a/Pokemon/Game.cpp +++ b/Pokemon/Game.cpp @@ -4,6 +4,7 @@ #include "utility.h" #include "WildEncounterManager.h" #include +#include"BattleManager.h" using namespace std; Game::Game() { @@ -17,6 +18,7 @@ Game::Game() { void Game::gameLoop(Player& player) { + BattleManager BattleManager; int choice; bool keepPlaying = true; @@ -41,8 +43,8 @@ void Game::gameLoop(Player& player) { case 1: { // Create a scope within case 1 WildEncounterManager encounterManager; - Pokemon encounteredPokemon = encounterManager.getRandomPokemonFromGrass(forestGrass); - cout << "A wild " << encounteredPokemon.name << " appeared!\n"; + Pokemon wildPokemon = encounterManager.getRandomPokemonFromGrass(forestGrass); + BattleManager.startBattle(player,wildPokemon);; break; } case 2: { From a44ff8d0d8b557db311e180f2eeceebf57df8789 Mon Sep 17 00:00:00 2001 From: Pranav Bardiwale Date: Sun, 3 Aug 2025 01:47:14 +0530 Subject: [PATCH 22/27] * --- Pokemon/BattleManager.cpp | 56 +++++++++++++++++++++++++-------------- Pokemon/BattleManager.h | 11 +++++--- Pokemon/BattleState.cpp | 1 + Pokemon/BattleState.h | 8 ++++++ 4 files changed, 52 insertions(+), 24 deletions(-) create mode 100644 Pokemon/BattleState.cpp create mode 100644 Pokemon/BattleState.h diff --git a/Pokemon/BattleManager.cpp b/Pokemon/BattleManager.cpp index ea406946..f63a71e6 100644 --- a/Pokemon/BattleManager.cpp +++ b/Pokemon/BattleManager.cpp @@ -3,40 +3,56 @@ #include "Pokemon.h" #include "PokemonType.h" #include "utility.h" +#include "BattleState.h" using namespace std; void BattleManager::startBattle(Player& player, Pokemon& wildPokemon) { - cout<<"A wild "<< wildPokemon.name << " appeared!\n"; - // Start the battle with the player's chosen Pokémon - Battle(player.chosenPokemon, wildPokemon); + battleState.playerPokemon = &player.chosenPokemon; + battleState.wildPokemon = &wildPokemon; + battleState.playerTurn = true; // Player starts first + battleState.battleOngoing = true; + std::cout << "A wild " << wildPokemon.name << " appeared!\\n"; + battle(); } -void BattleManager::Battle(Pokemon& playerPokemon, Pokemon& wildPokemon) { - while (!playerPokemon.isFainted() && !wildPokemon.isFainted()) { - playerPokemon.attack(wildPokemon); // Player attacks first - if (!wildPokemon.isFainted()) { - wildPokemon.attack(playerPokemon); // Wild Pokémon attacks back +void BattleManager::battle() { + while (battleState.battleOngoing) { + if (battleState.playerTurn) { + // Player's turn to attack + battleState.playerPokemon->attack(*battleState.wildPokemon); } - //Pause to show battle progress + else { + // Wild Pokémon's turn to attack + battleState.wildPokemon->attack(*battleState.playerPokemon); + } + + // Update the battle state after the turn + updateBattleState(); + + // Switch turns + battleState.playerTurn = !battleState.playerTurn; + Utility::waitForEnter(); } - /*if (playerPokemon.isFainted()) { - cout << playerPokemon.name << " has fainted! You lose the battle.\\n"; + handleBattleOutcome(); +} + +void BattleManager::updateBattleState() { + if (battleState.playerPokemon->isFainted()) { + battleState.battleOngoing = false; + } + else if (battleState.wildPokemon->isFainted()) { + battleState.battleOngoing = false; } - else { - cout << "You defeated the wild " << wildPokemon.name << "!\\n"; - }*/ } -void BattleManager::handleBattleOutcome(Player& player, bool playerWon) { - if (playerWon) { - std::cout << player.chosenPokemon.name << " is victorious! Keep an eye on your Pokémon's health.\n"; +void BattleManager::handleBattleOutcome() { + if (battleState.playerPokemon->isFainted()) { + std::cout << battleState.playerPokemon->name << " has fainted! You lose the battle.\\n"; } else { - std::cout << "Oh no! " << player.chosenPokemon.name << " fainted! You need to visit the PokeCenter.\n"; - Utility::waitForEnter(); - std::cout << "Game Over.\n"; + std::cout << "You defeated the wild " << battleState.wildPokemon->name << "!\\n"; } } \ No newline at end of file diff --git a/Pokemon/BattleManager.h b/Pokemon/BattleManager.h index 48c472cc..19f99270 100644 --- a/Pokemon/BattleManager.h +++ b/Pokemon/BattleManager.h @@ -1,11 +1,14 @@ #include "Pokemon.h" #include "Player.h" +#include"BattleState.h" class BattleManager { public: - // Function to handle the battle between player's Pokémon and wild Pokémon - void startBattle(Player& player, Pokemon& wildPokemon); + void startBattle(Player& player, Pokemon& wildPokemon); private: - void Battle(Pokemon& playerPokemon, Pokemon& wildPokemon); - void handleBattleOutcome(Player& player, bool playerWon); + BattleState battleState; // New BattleState object to track the battle + + void battle(); + void handleBattleOutcome(); + void updateBattleState(); // Method to update the battle state after each turn }; \ No newline at end of file diff --git a/Pokemon/BattleState.cpp b/Pokemon/BattleState.cpp new file mode 100644 index 00000000..d4dde2be --- /dev/null +++ b/Pokemon/BattleState.cpp @@ -0,0 +1 @@ +#include "BattleState.h" diff --git a/Pokemon/BattleState.h b/Pokemon/BattleState.h new file mode 100644 index 00000000..63766235 --- /dev/null +++ b/Pokemon/BattleState.h @@ -0,0 +1,8 @@ +#include "Pokemon.h" + +struct BattleState { + Pokemon* playerPokemon; // Pointer to the player's Pokémon + Pokemon* wildPokemon; // Pointer to the wild Pokémon + bool playerTurn; // True if it's the player's turn, false if it's the wild Pokémon's turn + bool battleOngoing; // True if the battle is ongoing, false if the battle has ended +}; \ No newline at end of file From d94efbab7045ee9b3a5fb64a39cfd7a61131a023 Mon Sep 17 00:00:00 2001 From: Pranav Bardiwale Date: Sun, 3 Aug 2025 04:02:28 +0530 Subject: [PATCH 23/27] Don't want to do --- Pokemon/BattleManager.cpp | 1 + Pokemon/BattleManager.h | 2 +- Pokemon/ProfessorOak.cpp | 44 +++++++++++++++++++-------------------- Pokemon/ProfessorOak.h | 2 ++ Pokemon/player.cpp | 2 +- Pokemon/player.h | 1 + 6 files changed, 28 insertions(+), 24 deletions(-) diff --git a/Pokemon/BattleManager.cpp b/Pokemon/BattleManager.cpp index f63a71e6..406ec9ac 100644 --- a/Pokemon/BattleManager.cpp +++ b/Pokemon/BattleManager.cpp @@ -2,6 +2,7 @@ #include #include "Pokemon.h" #include "PokemonType.h" +#include "player.h" #include "utility.h" #include "BattleState.h" using namespace std; diff --git a/Pokemon/BattleManager.h b/Pokemon/BattleManager.h index 19f99270..d9c8ce6c 100644 --- a/Pokemon/BattleManager.h +++ b/Pokemon/BattleManager.h @@ -1,5 +1,5 @@ #include "Pokemon.h" -#include "Player.h" +#include "player.h" #include"BattleState.h" class BattleManager { diff --git a/Pokemon/ProfessorOak.cpp b/Pokemon/ProfessorOak.cpp index e710cc68..66ea0e0b 100644 --- a/Pokemon/ProfessorOak.cpp +++ b/Pokemon/ProfessorOak.cpp @@ -1,6 +1,5 @@ #include "ProfessorOak.h" #include"utility.h" -#include "player.h" #include // Parameterized constructor @@ -8,12 +7,12 @@ ProfessorOak::ProfessorOak(string p_name) { name = p_name; } void ProfessorOak::greetPlayer(Player& player) { cout << name << ": Hello there! Welcome to the world of Pokemon!\n"; - utility::waitForEnter(); + Utility::waitForEnter(); cout << name << ": My name is Oak. People call me the Pokemon Professor!\n"; - utility::waitForEnter(); + Utility::waitForEnter(); cout << name << ": But enough about me. Let's talk about you!\n"; - utility::waitForEnter(); + Utility::waitForEnter(); } void ProfessorOak::offerPokemonChoices(Player& player) { @@ -23,17 +22,17 @@ void ProfessorOak::offerPokemonChoices(Player& player) { getline(cin, player.name); cout << name << ": Ah, " << player.name << "! What a fantastic name!\n"; - utility::waitForEnter(); + Utility::waitForEnter(); cout << name << ": You must be eager to start your adventure. But first, " "you’ll need a Pokemon of your own!\n"; - utility::waitForEnter(); + Utility::waitForEnter(); // Presenting Pokemon choices cout << name << ": I have three Pokemon here with me. They’re all quite feisty!\n"; - utility::waitForEnter(); + Utility::waitForEnter(); cout << name << ": Choose wisely...\n"; cout << "1. Charmander - The fire type. A real hothead!\n"; cout << "2. Bulbasaur - The grass type. Calm and collected!\n"; @@ -46,64 +45,65 @@ void ProfessorOak::offerPokemonChoices(Player& player) { cin >> choice; player.choosePokemon(choice); - utility::waitForEnter(); + Utility::waitForEnter(); } // New method for the main quest conversation void ProfessorOak::explainMainQuest(Player& player) { // Clear the console - utility::clearConsole(); + Utility::clearConsole(); cout << "Professor Oak: " << player.name << "!, I am about to explain you about your upcoming grand " "adventure.\n"; - utility::waitForEnter(); + Utility::waitForEnter(); cout << "Professor Oak: You see, becoming a Pokémon Master is no easy " "feat. It takes courage, wisdom, and a bit of luck!\n"; - utility::waitForEnter(); + Utility::waitForEnter(); cout << "Professor Oak: Your mission, should you choose to accept it—and " "trust me, you really don’t have a choice—is to collect all the " "Pokémon Badges and conquer the Pokémon League.\n"; - utility::waitForEnter(); + Utility::waitForEnter(); cout << "\n" << player.name << ": Wait... that sounds a lot like every other Pokémon game " "out there...\n"; - utility::waitForEnter(); + Utility::waitForEnter(); cout << "Professor Oak: Shhh! Don't break the fourth wall, " << player.name << "! This is serious business!\n"; - utility::waitForEnter(); + Utility::waitForEnter(); cout << "\nProfessor Oak: To achieve this, you’ll need to battle wild " "Pokémon, challenge gym leaders, and of course, keep your " "Pokémon healthy at the PokeCenter.\n"; - utility::waitForEnter(); + Utility::waitForEnter(); cout << "Professor Oak: Along the way, you'll capture new Pokémon to " "strengthen your team. Just remember—there’s a limit to how " "many Pokémon you can carry, so choose wisely!\n"; - utility::waitForEnter(); + Utility::waitForEnter(); cout << "\n" << player.name << ": Sounds like a walk in the park... right?\n"; - utility::waitForEnter(); + Utility::waitForEnter(); cout << "Professor Oak: Hah! That’s what they all say! But beware, " "young Trainer, the path to victory is fraught with " "challenges. And if you lose a battle... well, let’s just say " "you'll be starting from square one.\n"; - utility::waitForEnter(); + Utility::waitForEnter(); cout << "\nProfessor Oak: So, what do you say? Are you ready to " "become the next Pokémon Champion?\n"; - utility::waitForEnter(); + Utility::waitForEnter(); cout << "\n" << player.name << ": Ready as I’ll ever be, Professor!\n"; - utility::waitForEnter(); + Utility::waitForEnter(); cout << "\nProfessor Oak: That’s the spirit! Now, your journey begins...\n"; - utility::waitForEnter(); + Utility::waitForEnter(); cout << "Professor Oak: But first... let's just pretend I didn't " "forget to set up the actual game loop... Ahem, onwards!\n"; - utility::waitForEnter(); + Utility::waitForEnter(); } + diff --git a/Pokemon/ProfessorOak.h b/Pokemon/ProfessorOak.h index 0b911a4e..8463d19f 100644 --- a/Pokemon/ProfessorOak.h +++ b/Pokemon/ProfessorOak.h @@ -1,6 +1,8 @@ #include +#include "player.h" using namespace std; + // ProfessorOak class definition class ProfessorOak { public: diff --git a/Pokemon/player.cpp b/Pokemon/player.cpp index 4b7c8cdb..02494481 100644 --- a/Pokemon/player.cpp +++ b/Pokemon/player.cpp @@ -34,5 +34,5 @@ void Player::choosePokemon(int choice) { break; } cout << "Player " << name << " chose " << chosenPokemon.name << "!\n"; - utility::waitForEnter(); // Wait for user to press Enter before proceeding + Utility::waitForEnter(); // Wait for user to press Enter before proceeding } \ No newline at end of file diff --git a/Pokemon/player.h b/Pokemon/player.h index eb38a581..25fa68f2 100644 --- a/Pokemon/player.h +++ b/Pokemon/player.h @@ -2,6 +2,7 @@ #include #include "Pokemon.h" using namespace std; + class Player { public: string name; From 3684eb2c602ec94897eea2114530131e961cbda6 Mon Sep 17 00:00:00 2001 From: Pranav Bardiwale Date: Thu, 7 Aug 2025 01:46:07 +0530 Subject: [PATCH 24/27] Inherited! But don't want to use namespace --- Pokemon/Caterpie.cpp | 0 Pokemon/Caterpie.h | 0 Pokemon/Pidgey.cpp | 0 Pokemon/Pidgey.h | 0 Pokemon/Pikachu.cpp | 11 ++++ Pokemon/Pikachu.h | 11 ++++ Pokemon/Pokemon.cpp | 5 +- Pokemon/Pokemon.h | 2 +- Pokemon/Pokemon.vcxproj | 22 +++++++ Pokemon/Pokemon.vcxproj.filters | 100 ++++++++++++++++++++++++++------ Pokemon/Temp.txt | 1 + Pokemon/Zubat.cpp | 0 Pokemon/Zubat.h | 8 +++ 13 files changed, 140 insertions(+), 20 deletions(-) create mode 100644 Pokemon/Caterpie.cpp create mode 100644 Pokemon/Caterpie.h create mode 100644 Pokemon/Pidgey.cpp create mode 100644 Pokemon/Pidgey.h create mode 100644 Pokemon/Pikachu.cpp create mode 100644 Pokemon/Pikachu.h create mode 100644 Pokemon/Temp.txt create mode 100644 Pokemon/Zubat.cpp create mode 100644 Pokemon/Zubat.h diff --git a/Pokemon/Caterpie.cpp b/Pokemon/Caterpie.cpp new file mode 100644 index 00000000..e69de29b diff --git a/Pokemon/Caterpie.h b/Pokemon/Caterpie.h new file mode 100644 index 00000000..e69de29b diff --git a/Pokemon/Pidgey.cpp b/Pokemon/Pidgey.cpp new file mode 100644 index 00000000..e69de29b diff --git a/Pokemon/Pidgey.h b/Pokemon/Pidgey.h new file mode 100644 index 00000000..e69de29b diff --git a/Pokemon/Pikachu.cpp b/Pokemon/Pikachu.cpp new file mode 100644 index 00000000..ff66e029 --- /dev/null +++ b/Pokemon/Pikachu.cpp @@ -0,0 +1,11 @@ +#include "Pikachu.h" +#include +#include"PokemonType.h" +using namespace std; + +Pikachu::Pikachu() : Pokemon("Pikachu", PokemonType::ELECTRIC, 100, 20) {} + +void Pikachu::thunderShock(Pokemon& target) { + cout << name << "uses Tunder shock on " << target.name << "\n"; + target.TakeDamage(20); +} \ No newline at end of file diff --git a/Pokemon/Pikachu.h b/Pokemon/Pikachu.h new file mode 100644 index 00000000..d9e42dc9 --- /dev/null +++ b/Pokemon/Pikachu.h @@ -0,0 +1,11 @@ +#include"Pokemon.h" +#pragma once + +class Pikachu : public Pokemon +{ +public: + Pikachu(); + + void thunderShock(Pokemon& target); +}; + diff --git a/Pokemon/Pokemon.cpp b/Pokemon/Pokemon.cpp index f5f4b5d8..b4b7f295 100644 --- a/Pokemon/Pokemon.cpp +++ b/Pokemon/Pokemon.cpp @@ -4,9 +4,10 @@ Pokemon::Pokemon():name("unknown"),type(PokemonType::NORMAL),health(50){} // Parameterized constructor -Pokemon::Pokemon(string p_name, PokemonType p_type, int p_health): name(p_name), +Pokemon::Pokemon(string p_name, PokemonType p_type, int p_health,int p_attackPower): name(p_name), type(p_type), -health(p_health) { +health(p_health), +attackPower(p_attackPower){ } // Copy constructor diff --git a/Pokemon/Pokemon.h b/Pokemon/Pokemon.h index 7271f11c..3a026acd 100644 --- a/Pokemon/Pokemon.h +++ b/Pokemon/Pokemon.h @@ -15,7 +15,7 @@ class Pokemon { Pokemon(); // Parameterized constructor - Pokemon(string p_name, PokemonType p_type, int p_health); + Pokemon(string p_name, PokemonType p_type, int p_health,int attackPower); // Copy constructor Pokemon(const Pokemon& other); diff --git a/Pokemon/Pokemon.vcxproj b/Pokemon/Pokemon.vcxproj index 2f89b0e7..b33695c1 100644 --- a/Pokemon/Pokemon.vcxproj +++ b/Pokemon/Pokemon.vcxproj @@ -154,11 +154,22 @@ + + + + + + + + + + + @@ -167,10 +178,21 @@ + + + + + + + + + + + diff --git a/Pokemon/Pokemon.vcxproj.filters b/Pokemon/Pokemon.vcxproj.filters index 3ffc753b..c7c1e6cc 100644 --- a/Pokemon/Pokemon.vcxproj.filters +++ b/Pokemon/Pokemon.vcxproj.filters @@ -1,48 +1,114 @@ - + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - + {93995380-89BD-4b04-88EB-625FBE52EBFB} h;hh;hpp;hxx;hm;inl;inc;ipp;xsd - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - + + src + + + src + + + src + + + src + - Source Files + src - - Source Files + + src + + + src - Source Files + src + + + src + + + src - Source Files + src - - Source Files + + src + + + src + + + src + + + src + + + src - Header Files + include - Header Files + include - Header Files + include - Header Files + include + + + include + + + include + + + include + + + include + + + include + + + include + + + include + + + include + + + include + + + include + + + include \ No newline at end of file diff --git a/Pokemon/Temp.txt b/Pokemon/Temp.txt new file mode 100644 index 00000000..5f282702 --- /dev/null +++ b/Pokemon/Temp.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Pokemon/Zubat.cpp b/Pokemon/Zubat.cpp new file mode 100644 index 00000000..e69de29b diff --git a/Pokemon/Zubat.h b/Pokemon/Zubat.h new file mode 100644 index 00000000..f9fd0faf --- /dev/null +++ b/Pokemon/Zubat.h @@ -0,0 +1,8 @@ +#pragma once +#include"Pokemon.h" +class Zubat :public Pokemon +{ +public: + Zubat(); + void superSonic(Pokemon& target); +}; \ No newline at end of file From 1f1d6d83203b7c2d7c25cd0bf49837bc6c7dcfe2 Mon Sep 17 00:00:00 2001 From: Pranav Bardiwale Date: Fri, 8 Aug 2025 04:23:53 +0530 Subject: [PATCH 25/27] Poor player!,showing the error --- Pokemon/Bulbasaur.cpp | 11 +++++++++++ Pokemon/Bulbasaur.h | 11 +++++++++++ Pokemon/Caterpie.cpp | 11 +++++++++++ Pokemon/Caterpie.h | 10 ++++++++++ Pokemon/Charmander.cpp | 11 +++++++++++ Pokemon/Charmander.h | 10 ++++++++++ Pokemon/Pidgey.h | 10 ++++++++++ Pokemon/Pikachu.h | 2 +- Pokemon/Pokemon.cpp | 4 ++-- Pokemon/Pokemon.h | 8 ++++---- Pokemon/Squirtle.cpp | 12 ++++++++++++ Pokemon/Squirtle.h | 10 ++++++++++ Pokemon/main.cpp | 18 +++++++++++------- Pokemon/player.cpp | 10 +++++----- 14 files changed, 119 insertions(+), 19 deletions(-) create mode 100644 Pokemon/Bulbasaur.cpp create mode 100644 Pokemon/Bulbasaur.h create mode 100644 Pokemon/Charmander.cpp create mode 100644 Pokemon/Charmander.h create mode 100644 Pokemon/Squirtle.cpp create mode 100644 Pokemon/Squirtle.h diff --git a/Pokemon/Bulbasaur.cpp b/Pokemon/Bulbasaur.cpp new file mode 100644 index 00000000..a1ddddf7 --- /dev/null +++ b/Pokemon/Bulbasaur.cpp @@ -0,0 +1,11 @@ +#include "Bulbasaur.h" +#include +#include "PokemonType.h" +using namespace std; + +Bulbasaur::Bulbasaur() : Pokemon("Bulbasaur", PokemonType::GRASS, 100, 35) {} + +void Bulbasaur::vineWhip(Pokemon& target) { + cout << name << " uses Vine Whip on " << target.name << "!\n"; + target.TakeDamage(20); +} \ No newline at end of file diff --git a/Pokemon/Bulbasaur.h b/Pokemon/Bulbasaur.h new file mode 100644 index 00000000..ec657ab4 --- /dev/null +++ b/Pokemon/Bulbasaur.h @@ -0,0 +1,11 @@ +#pragma once +#include"Pokemon.h" +class Bulbasaur:public Pokemon +{ +public: + Bulbasaur(); +private: + void vineWhip(Pokemon& target); + +}; + diff --git a/Pokemon/Caterpie.cpp b/Pokemon/Caterpie.cpp index e69de29b..1b179165 100644 --- a/Pokemon/Caterpie.cpp +++ b/Pokemon/Caterpie.cpp @@ -0,0 +1,11 @@ +#include "Caterpie.h" +#include "PokemonType.h" +#include +using namespace std; + +Caterpie::Caterpie() : Pokemon("Caterpie", PokemonType::BUG, 100, 35) {} + +void Caterpie::bugBite(Pokemon& target) { + cout << name << " uses Flame Thrower on " << target.name << "!\n"; + target.TakeDamage(20); +} \ No newline at end of file diff --git a/Pokemon/Caterpie.h b/Pokemon/Caterpie.h index e69de29b..fe20c8ce 100644 --- a/Pokemon/Caterpie.h +++ b/Pokemon/Caterpie.h @@ -0,0 +1,10 @@ +#include"Pokemon.h" +#pragma once + +class Caterpie : public Pokemon +{ +public: + Caterpie(); +private: + void bugBite(Pokemon& target); +}; diff --git a/Pokemon/Charmander.cpp b/Pokemon/Charmander.cpp new file mode 100644 index 00000000..89a12352 --- /dev/null +++ b/Pokemon/Charmander.cpp @@ -0,0 +1,11 @@ +#include "Charmander.h" +#include "PokemonType.h" +#include +using namespace std; + +Charmander::Charmander() : Pokemon("Charmander", PokemonType::FIRE, 100, 35) {} + +void Charmander::flameThrower(Pokemon& target) { + cout << name << " uses Flame Thrower on " << target.name << "!\n"; + target.TakeDamage(20); +} \ No newline at end of file diff --git a/Pokemon/Charmander.h b/Pokemon/Charmander.h new file mode 100644 index 00000000..34d00bbd --- /dev/null +++ b/Pokemon/Charmander.h @@ -0,0 +1,10 @@ +#include"Pokemon.h" +#pragma once + +class Charmander : public Pokemon +{ +public: + Charmander(); +private: + void flameThrower(Pokemon& target); +}; diff --git a/Pokemon/Pidgey.h b/Pokemon/Pidgey.h index e69de29b..5c8278eb 100644 --- a/Pokemon/Pidgey.h +++ b/Pokemon/Pidgey.h @@ -0,0 +1,10 @@ +#include"Pokemon.h" +#pragma once + +class Pidgey : public Pokemon +{ +public: + Pidgey(); +private: + void wingAttack(Pokemon& target); +}; diff --git a/Pokemon/Pikachu.h b/Pokemon/Pikachu.h index d9e42dc9..7f913248 100644 --- a/Pokemon/Pikachu.h +++ b/Pokemon/Pikachu.h @@ -5,7 +5,7 @@ class Pikachu : public Pokemon { public: Pikachu(); - +private: void thunderShock(Pokemon& target); }; diff --git a/Pokemon/Pokemon.cpp b/Pokemon/Pokemon.cpp index b4b7f295..f75314bd 100644 --- a/Pokemon/Pokemon.cpp +++ b/Pokemon/Pokemon.cpp @@ -2,7 +2,7 @@ #include #include"PokemonType.h" -Pokemon::Pokemon():name("unknown"),type(PokemonType::NORMAL),health(50){} +Pokemon::Pokemon():name("unknown"),type(PokemonType::NORMAL),health(50),attackPower(10){} // Parameterized constructor Pokemon::Pokemon(string p_name, PokemonType p_type, int p_health,int p_attackPower): name(p_name), type(p_type), @@ -11,7 +11,7 @@ attackPower(p_attackPower){ } // Copy constructor -Pokemon::Pokemon(const Pokemon& other):name(other.name),type(other.type),health(other.health) {} +Pokemon::Pokemon(const Pokemon& other):name(other.name),type(other.type),health(other.health),attackPower(other.attackPower) {} // Destructor Pokemon::~Pokemon() { diff --git a/Pokemon/Pokemon.h b/Pokemon/Pokemon.h index 3a026acd..513d6736 100644 --- a/Pokemon/Pokemon.h +++ b/Pokemon/Pokemon.h @@ -4,13 +4,13 @@ using namespace std; enum class PokemonType; class Pokemon { -public: +protected: string name; PokemonType type; int health; - int maxHealth; - int attackPower; - + int maxHealth; + int attackPower; +public: // Default constructor Pokemon(); diff --git a/Pokemon/Squirtle.cpp b/Pokemon/Squirtle.cpp new file mode 100644 index 00000000..4cfd8033 --- /dev/null +++ b/Pokemon/Squirtle.cpp @@ -0,0 +1,12 @@ +#include "Squirtle.h" +#include +#include "PokemonType.h" + +using namespace std; + +Squirtle::Squirtle() : Pokemon("Squirtle", PokemonType::WATER, 100, 35) {} + +void Squirtle::waterSplash(Pokemon& target) { + cout << name << " uses Water Splash on " << target.name << "!\n"; + target.TakeDamage(20); +} \ No newline at end of file diff --git a/Pokemon/Squirtle.h b/Pokemon/Squirtle.h new file mode 100644 index 00000000..0b5faa3f --- /dev/null +++ b/Pokemon/Squirtle.h @@ -0,0 +1,10 @@ +#pragma once +#include"Pokemon.h" +class Squirtle: public Pokemon +{ +public: + Squirtle(); +private: + void waterSplash(Pokemon& target); +}; + diff --git a/Pokemon/main.cpp b/Pokemon/main.cpp index 88776d2a..742e7db1 100644 --- a/Pokemon/main.cpp +++ b/Pokemon/main.cpp @@ -9,19 +9,23 @@ using namespace std; int main() { // Continue with the main flow of the game - ProfessorOak professor("Professor Oak"); - Player player; + ProfessorOak *professor=new ProfessorOak("Professor Oak"); + Player *player=new Player(); // Greet the player and offer Pokemon choices - professor.greetPlayer(player); - professor.offerPokemonChoices(player); + professor->greetPlayer(player); + professor->offerPokemonChoices(player); // Explain the main quest - professor.explainMainQuest(player); + professor->explainMainQuest(player); // Start the main game loop - Game game; - game.gameLoop(player); + Game *game=new Game(); + game->gameLoop(player); + + delete(professor); + delete(player); + delete(game); return 0; } \ No newline at end of file diff --git a/Pokemon/player.cpp b/Pokemon/player.cpp index 02494481..133c9c11 100644 --- a/Pokemon/player.cpp +++ b/Pokemon/player.cpp @@ -3,6 +3,7 @@ #include "PokemonChoice.h" #include "PokemonType.h" #include "Pokemon.h" +#include "Pikachu.h" #include "utility.h" #include "iostream" using namespace std; @@ -20,17 +21,16 @@ Player::Player(string p_name, Pokemon p_chosenPokemon) { void Player::choosePokemon(int choice) { switch ((PokemonChoice)choice) { case PokemonChoice::CHARMANDER: - chosenPokemon = Pokemon("Charmander", PokemonType::FIRE, 100); + chosenPokemon = Pokemon("Charmander", PokemonType::FIRE, 100,10); break; case PokemonChoice::BULBASAUR: - chosenPokemon = Pokemon("Bulbasaur", PokemonType::GRASS, 100); + chosenPokemon = Pokemon("Bulbasaur", PokemonType::GRASS, 100,8); break; case PokemonChoice::SQUIRTLE: - chosenPokemon = Pokemon("Squirtle", PokemonType::WATER, 100); + chosenPokemon = Pokemon("Squirtle", PokemonType::WATER, 100,9); break; default: - chosenPokemon = Pokemon("Pikachu", PokemonType::ELECTRIC, 100); - chosenPokemon = Pokemon("Pikachu", PokemonType::ELECTRIC, 100); + chosenPokemon = Pikachu(); break; } cout << "Player " << name << " chose " << chosenPokemon.name << "!\n"; From d4cec005c406ad3593c5aa164b6feb121a12763d Mon Sep 17 00:00:00 2001 From: Pranav Bardiwale Date: Sat, 16 Aug 2025 23:27:26 +0530 Subject: [PATCH 26/27] overridding burns! --- Pokemon/Bulbasaur.cpp | 7 ++++--- Pokemon/Bulbasaur.h | 2 +- Pokemon/Caterpie.cpp | 4 ++-- Pokemon/Caterpie.h | 2 +- Pokemon/Charmander.cpp | 3 ++- Pokemon/Charmander.h | 2 +- Pokemon/Pidgey.cpp | 12 ++++++++++++ Pokemon/Pidgey.h | 2 +- Pokemon/Pikachu.cpp | 5 +++-- Pokemon/Pikachu.h | 2 +- Pokemon/Pokemon.cpp | 4 ++-- Pokemon/Pokemon.h | 2 +- Pokemon/Squirtle.cpp | 3 ++- Pokemon/Squirtle.h | 2 +- Pokemon/Zubat.cpp | 13 +++++++++++++ Pokemon/Zubat.h | 2 +- 16 files changed, 48 insertions(+), 19 deletions(-) diff --git a/Pokemon/Bulbasaur.cpp b/Pokemon/Bulbasaur.cpp index a1ddddf7..d5847bcb 100644 --- a/Pokemon/Bulbasaur.cpp +++ b/Pokemon/Bulbasaur.cpp @@ -5,7 +5,8 @@ using namespace std; Bulbasaur::Bulbasaur() : Pokemon("Bulbasaur", PokemonType::GRASS, 100, 35) {} -void Bulbasaur::vineWhip(Pokemon& target) { - cout << name << " uses Vine Whip on " << target.name << "!\n"; - target.TakeDamage(20); +void Bulbasaur::attack(Pokemon* target) { + vineWhip(target); + cout << name << " uses Vine Whip on " << target.name << "!\n"; + target.TakeDamage(20); } \ No newline at end of file diff --git a/Pokemon/Bulbasaur.h b/Pokemon/Bulbasaur.h index ec657ab4..1c19a2a7 100644 --- a/Pokemon/Bulbasaur.h +++ b/Pokemon/Bulbasaur.h @@ -5,7 +5,7 @@ class Bulbasaur:public Pokemon public: Bulbasaur(); private: - void vineWhip(Pokemon& target); + void attack(Pokemon* target)override; }; diff --git a/Pokemon/Caterpie.cpp b/Pokemon/Caterpie.cpp index 1b179165..e3b91d1e 100644 --- a/Pokemon/Caterpie.cpp +++ b/Pokemon/Caterpie.cpp @@ -5,7 +5,7 @@ using namespace std; Caterpie::Caterpie() : Pokemon("Caterpie", PokemonType::BUG, 100, 35) {} -void Caterpie::bugBite(Pokemon& target) { - cout << name << " uses Flame Thrower on " << target.name << "!\n"; +void Caterpie::attack(Pokemon* target) { + bugBite(target); target.TakeDamage(20); } \ No newline at end of file diff --git a/Pokemon/Caterpie.h b/Pokemon/Caterpie.h index fe20c8ce..f81da526 100644 --- a/Pokemon/Caterpie.h +++ b/Pokemon/Caterpie.h @@ -6,5 +6,5 @@ class Caterpie : public Pokemon public: Caterpie(); private: - void bugBite(Pokemon& target); + void attack(Pokemon* target)override; }; diff --git a/Pokemon/Charmander.cpp b/Pokemon/Charmander.cpp index 89a12352..5c5eddf3 100644 --- a/Pokemon/Charmander.cpp +++ b/Pokemon/Charmander.cpp @@ -5,7 +5,8 @@ using namespace std; Charmander::Charmander() : Pokemon("Charmander", PokemonType::FIRE, 100, 35) {} -void Charmander::flameThrower(Pokemon& target) { +void Charmander::attack(Pokemon* target) { + flameThrower(target); cout << name << " uses Flame Thrower on " << target.name << "!\n"; target.TakeDamage(20); } \ No newline at end of file diff --git a/Pokemon/Charmander.h b/Pokemon/Charmander.h index 34d00bbd..64fbeb0b 100644 --- a/Pokemon/Charmander.h +++ b/Pokemon/Charmander.h @@ -6,5 +6,5 @@ class Charmander : public Pokemon public: Charmander(); private: - void flameThrower(Pokemon& target); + void attack(Pokemon* target)override; }; diff --git a/Pokemon/Pidgey.cpp b/Pokemon/Pidgey.cpp index e69de29b..5a19e273 100644 --- a/Pokemon/Pidgey.cpp +++ b/Pokemon/Pidgey.cpp @@ -0,0 +1,12 @@ +#include "Pidgey.h" +#include +#include "PokemonType.h" +using namespace std; + +Pidgey::Pidgey() : Pokemon("Pidgey", PokemonType::NORMAL, 100, 35) {} + +void Pidgey::attack(Pokemon* target) { + wingAttack(target); + cout << name << " uses Vine Whip on " << target.name << "!\n"; + target.TakeDamage(20); +} \ No newline at end of file diff --git a/Pokemon/Pidgey.h b/Pokemon/Pidgey.h index 5c8278eb..b2e8cb77 100644 --- a/Pokemon/Pidgey.h +++ b/Pokemon/Pidgey.h @@ -6,5 +6,5 @@ class Pidgey : public Pokemon public: Pidgey(); private: - void wingAttack(Pokemon& target); + void attack(Pokemon* target)override; }; diff --git a/Pokemon/Pikachu.cpp b/Pokemon/Pikachu.cpp index ff66e029..22e096dc 100644 --- a/Pokemon/Pikachu.cpp +++ b/Pokemon/Pikachu.cpp @@ -5,7 +5,8 @@ using namespace std; Pikachu::Pikachu() : Pokemon("Pikachu", PokemonType::ELECTRIC, 100, 20) {} -void Pikachu::thunderShock(Pokemon& target) { - cout << name << "uses Tunder shock on " << target.name << "\n"; +void Pikachu::attack(Pokemon* target) { + thunderShock(target); + cout << name << "uses Thunder shock on " << target.name << "\n"; target.TakeDamage(20); } \ No newline at end of file diff --git a/Pokemon/Pikachu.h b/Pokemon/Pikachu.h index 7f913248..b01abd71 100644 --- a/Pokemon/Pikachu.h +++ b/Pokemon/Pikachu.h @@ -6,6 +6,6 @@ class Pikachu : public Pokemon public: Pikachu(); private: - void thunderShock(Pokemon& target); + void attack(Pokemon* target)override; }; diff --git a/Pokemon/Pokemon.cpp b/Pokemon/Pokemon.cpp index f75314bd..a65230d8 100644 --- a/Pokemon/Pokemon.cpp +++ b/Pokemon/Pokemon.cpp @@ -18,11 +18,11 @@ Pokemon::~Pokemon() { // Destructor message removed } -void Pokemon::attack(Pokemon& target) { +/*void Pokemon::attack(Pokemon& target) { int damage = attackPower; // Example damage value, could be based on type or other factors target.TakeDamage(damage); // Example damage value cout << name << " attacks " << target.name << " for " << damage << " damage!\\n"; -} +}*/ void Pokemon::TakeDamage(int Damage) { health -= Damage;// Reduce health by the damage taken diff --git a/Pokemon/Pokemon.h b/Pokemon/Pokemon.h index 513d6736..b78da72f 100644 --- a/Pokemon/Pokemon.h +++ b/Pokemon/Pokemon.h @@ -23,7 +23,7 @@ class Pokemon { // Destructor ~Pokemon(); - void attack(Pokemon & target); + virtual void attack(Pokemon * target)=0; void TakeDamage(int damage); diff --git a/Pokemon/Squirtle.cpp b/Pokemon/Squirtle.cpp index 4cfd8033..48dfbcce 100644 --- a/Pokemon/Squirtle.cpp +++ b/Pokemon/Squirtle.cpp @@ -6,7 +6,8 @@ using namespace std; Squirtle::Squirtle() : Pokemon("Squirtle", PokemonType::WATER, 100, 35) {} -void Squirtle::waterSplash(Pokemon& target) { +void Squirtle::attack(Pokemon* target) { + WaterSplash(target); cout << name << " uses Water Splash on " << target.name << "!\n"; target.TakeDamage(20); } \ No newline at end of file diff --git a/Pokemon/Squirtle.h b/Pokemon/Squirtle.h index 0b5faa3f..f62e8f1b 100644 --- a/Pokemon/Squirtle.h +++ b/Pokemon/Squirtle.h @@ -5,6 +5,6 @@ class Squirtle: public Pokemon public: Squirtle(); private: - void waterSplash(Pokemon& target); + void attack(Pokemon* target)override; }; diff --git a/Pokemon/Zubat.cpp b/Pokemon/Zubat.cpp index e69de29b..b4d555d4 100644 --- a/Pokemon/Zubat.cpp +++ b/Pokemon/Zubat.cpp @@ -0,0 +1,13 @@ +#include "Zubat.h" +#include "PokemonType.h" +#include + +using namespace std; + +Zubat::Zubat() : Pokemon("Zubat", PokemonType::POISON, 100, 20) {} + +void Zubat::attack(Pokemon* target){ + supersonic(target); + cout << name << " uses Supersonic on " << target.name << "!\n"; + target.TakeDamage(20); +} diff --git a/Pokemon/Zubat.h b/Pokemon/Zubat.h index f9fd0faf..f7567b46 100644 --- a/Pokemon/Zubat.h +++ b/Pokemon/Zubat.h @@ -4,5 +4,5 @@ class Zubat :public Pokemon { public: Zubat(); - void superSonic(Pokemon& target); + void attack(Pokemon* target)override; }; \ No newline at end of file From c013c1f35a4cc5d6e5a6aa483e0073a5c64f0a87 Mon Sep 17 00:00:00 2001 From: Pranav Bardiwale Date: Sun, 17 Aug 2025 20:00:32 +0530 Subject: [PATCH 27/27] Complex! --- Pokemon/BattleManager.cpp | 42 +++++------ Pokemon/BattleManager.h | 18 +++-- Pokemon/BattleState.h | 11 +-- Pokemon/Bulbasaur.cpp | 28 ++++++-- Pokemon/Bulbasaur.h | 12 ++-- Pokemon/Caterpie.cpp | 22 ++++-- Pokemon/Caterpie.h | 8 +-- Pokemon/Charmander.cpp | 25 +++++-- Pokemon/Charmander.h | 8 +-- Pokemon/Game.cpp | 52 +++++++++----- Pokemon/Game.h | 16 +++-- Pokemon/Grass.cpp | 21 ++++-- Pokemon/Grass.h | 11 +-- Pokemon/Move.cpp | 1 + Pokemon/Move.h | 16 +++++ Pokemon/MoveName.cpp | 1 + Pokemon/MoveName.h | 17 +++++ Pokemon/Pidgey.cpp | 28 ++++++-- Pokemon/Pidgey.h | 10 ++- Pokemon/Pikachu.cpp | 29 ++++++-- Pokemon/Pikachu.h | 11 ++- Pokemon/Pokemon.cpp | 116 +++++++++++++++++++++++++------ Pokemon/Pokemon.h | 42 +++++------ Pokemon/PokemonType.h | 3 +- Pokemon/ProfessorOak.cpp | 54 ++++++-------- Pokemon/ProfessorOak.h | 19 +++-- Pokemon/Squirtle.cpp | 29 ++++++-- Pokemon/Squirtle.h | 9 ++- Pokemon/WildEncounterManager.cpp | 10 ++- Pokemon/WildEncounterManager.h | 14 ++-- Pokemon/Zubat.cpp | 30 ++++++-- Pokemon/Zubat.h | 7 +- Pokemon/player.cpp | 44 ++++++++---- Pokemon/player.h | 10 +-- 34 files changed, 521 insertions(+), 253 deletions(-) create mode 100644 Pokemon/Move.cpp create mode 100644 Pokemon/Move.h create mode 100644 Pokemon/MoveName.cpp create mode 100644 Pokemon/MoveName.h diff --git a/Pokemon/BattleManager.cpp b/Pokemon/BattleManager.cpp index 406ec9ac..0ebe0fe0 100644 --- a/Pokemon/BattleManager.cpp +++ b/Pokemon/BattleManager.cpp @@ -7,33 +7,32 @@ #include "BattleState.h" using namespace std; -void BattleManager::startBattle(Player& player, Pokemon& wildPokemon) { - battleState.playerPokemon = &player.chosenPokemon; - battleState.wildPokemon = &wildPokemon; - battleState.playerTurn = true; // Player starts first +BattleState BattleManager::battleState; + +void BattleManager::startBattle(Player* player, Pokemon* wildPokemon) { + battleState.playerPokemon = player->chosenPokemon; + battleState.wildPokemon = wildPokemon; + battleState.playerTurn = true; battleState.battleOngoing = true; - std::cout << "A wild " << wildPokemon.name << " appeared!\\n"; + cout << "A wild " << wildPokemon->name << " appeared!\n"; + Utility::waitForEnter(); + battle(); } +void BattleManager::stopBattle() { battleState.battleOngoing = false; } + void BattleManager::battle() { - while (battleState.battleOngoing) { - if (battleState.playerTurn) { - // Player's turn to attack - battleState.playerPokemon->attack(*battleState.wildPokemon); - } - else { - // Wild Pokémon's turn to attack - battleState.wildPokemon->attack(*battleState.playerPokemon); - } - - // Update the battle state after the turn - updateBattleState(); + while (battleState.battleOngoing) + { + if (battleState.playerTurn) + battleState.playerPokemon->selectAndUseMove(battleState.wildPokemon); + else + battleState.wildPokemon->selectAndUseMove(battleState.playerPokemon); - // Switch turns + updateBattleState(); battleState.playerTurn = !battleState.playerTurn; - Utility::waitForEnter(); } @@ -51,9 +50,10 @@ void BattleManager::updateBattleState() { void BattleManager::handleBattleOutcome() { if (battleState.playerPokemon->isFainted()) { - std::cout << battleState.playerPokemon->name << " has fainted! You lose the battle.\\n"; + cout << battleState.playerPokemon->name + << " has fainted! You lose the battle.\n"; } else { - std::cout << "You defeated the wild " << battleState.wildPokemon->name << "!\\n"; + cout << "You defeated the wild " << battleState.wildPokemon->name << "!\n"; } } \ No newline at end of file diff --git a/Pokemon/BattleManager.h b/Pokemon/BattleManager.h index d9c8ce6c..b477e553 100644 --- a/Pokemon/BattleManager.h +++ b/Pokemon/BattleManager.h @@ -1,14 +1,18 @@ -#include "Pokemon.h" -#include "player.h" -#include"BattleState.h" +#pragma once +#include "BattleState.h" +#include "Player.h" + + +class Pokemon; class BattleManager { public: - void startBattle(Player& player, Pokemon& wildPokemon); + void startBattle(Player* player, Pokemon* wildPokemon); + static void stopBattle(); private: - BattleState battleState; // New BattleState object to track the battle + static BattleState battleState; void battle(); void handleBattleOutcome(); - void updateBattleState(); // Method to update the battle state after each turn -}; \ No newline at end of file + void updateBattleState(); +}; diff --git a/Pokemon/BattleState.h b/Pokemon/BattleState.h index 63766235..ecef7ae2 100644 --- a/Pokemon/BattleState.h +++ b/Pokemon/BattleState.h @@ -1,8 +1,9 @@ +#pragma once #include "Pokemon.h" struct BattleState { - Pokemon* playerPokemon; // Pointer to the player's Pokémon - Pokemon* wildPokemon; // Pointer to the wild Pokémon - bool playerTurn; // True if it's the player's turn, false if it's the wild Pokémon's turn - bool battleOngoing; // True if the battle is ongoing, false if the battle has ended -}; \ No newline at end of file + Pokemon* playerPokemon; + Pokemon* wildPokemon; + bool playerTurn; + bool battleOngoing; +}; diff --git a/Pokemon/Bulbasaur.cpp b/Pokemon/Bulbasaur.cpp index d5847bcb..cb070222 100644 --- a/Pokemon/Bulbasaur.cpp +++ b/Pokemon/Bulbasaur.cpp @@ -3,10 +3,28 @@ #include "PokemonType.h" using namespace std; -Bulbasaur::Bulbasaur() : Pokemon("Bulbasaur", PokemonType::GRASS, 100, 35) {} +Bulbasaur::Bulbasaur() + : Pokemon("Bulbasaur", PokemonType::GRASS, 110, { + Move("VINE WHIP", 25), + Move("TACKLE", 10) + }) { +} -void Bulbasaur::attack(Pokemon* target) { - vineWhip(target); - cout << name << " uses Vine Whip on " << target.name << "!\n"; - target.TakeDamage(20); +void Bulbasaur::attack(Move selectedMove, Pokemon* target) +{ + Pokemon::attack(selectedMove, target); + + if (selectedMove.name == "VINE WHIP") + { + // Chance for a second hit (50% chance) + int secondHitChance = rand() % 2; + + if (secondHitChance == 1) + { + Pokemon::attack(selectedMove, target); + std::cout << name << " hits again with a second " << selectedMove.name << "!\n"; + } + else + std::cout << target->name << " dodged the second hit!\n"; + } } \ No newline at end of file diff --git a/Pokemon/Bulbasaur.h b/Pokemon/Bulbasaur.h index 1c19a2a7..5d5192c3 100644 --- a/Pokemon/Bulbasaur.h +++ b/Pokemon/Bulbasaur.h @@ -1,11 +1,9 @@ #pragma once -#include"Pokemon.h" -class Bulbasaur:public Pokemon -{ -public: - Bulbasaur(); -private: - void attack(Pokemon* target)override; +#include "Pokemon.h" +class Bulbasaur : public Pokemon { +public: + Bulbasaur(); + void attack(Move selectedMove, Pokemon* target) override; }; diff --git a/Pokemon/Caterpie.cpp b/Pokemon/Caterpie.cpp index e3b91d1e..316d1119 100644 --- a/Pokemon/Caterpie.cpp +++ b/Pokemon/Caterpie.cpp @@ -3,9 +3,23 @@ #include using namespace std; -Caterpie::Caterpie() : Pokemon("Caterpie", PokemonType::BUG, 100, 35) {} +Caterpie::Caterpie() + : Pokemon("Caterpie", PokemonType::BUG, 75, { + Move("TACKLE", 10), + Move("STRING SHOT", 5), + Move("STICKY WEB", 10) + }) { +} -void Caterpie::attack(Pokemon* target) { - bugBite(target); - target.TakeDamage(20); +void Caterpie::attack(Move selectedMove, Pokemon* target) +{ + Pokemon::attack(selectedMove, target); + + if (selectedMove.name == "STICKY WEB") + { + // Reduce the target's next attack damage (for simplicity, reducing by a fixed value) + int reducedDamage = 5; + target->reduceAttackPower(reducedDamage); + std::cout << target->name << "'s next attack will be reduced by " << reducedDamage << " damage!\n"; + } } \ No newline at end of file diff --git a/Pokemon/Caterpie.h b/Pokemon/Caterpie.h index f81da526..433e8ca2 100644 --- a/Pokemon/Caterpie.h +++ b/Pokemon/Caterpie.h @@ -1,10 +1,8 @@ #include"Pokemon.h" #pragma once -class Caterpie : public Pokemon -{ +class Caterpie : public Pokemon { public: - Caterpie(); -private: - void attack(Pokemon* target)override; + Caterpie(); + void attack(Move selectedMove, Pokemon* target) override; }; diff --git a/Pokemon/Charmander.cpp b/Pokemon/Charmander.cpp index 5c5eddf3..59ee8e40 100644 --- a/Pokemon/Charmander.cpp +++ b/Pokemon/Charmander.cpp @@ -1,12 +1,27 @@ #include "Charmander.h" #include "PokemonType.h" +#include "Move.h" +#include "Utility.h" #include using namespace std; -Charmander::Charmander() : Pokemon("Charmander", PokemonType::FIRE, 100, 35) {} +Charmander::Charmander() + : Pokemon("Charmander", PokemonType::FIRE, 95, { + Move("EMBER", 20), + Move("SCRATCH", 15), + Move("BLAZING CHARGE", 70) + }) { +} -void Charmander::attack(Pokemon* target) { - flameThrower(target); - cout << name << " uses Flame Thrower on " << target.name << "!\n"; - target.TakeDamage(20); +void Charmander::attack(Move selectedMove, Pokemon* target) +{ + Pokemon::attack(selectedMove, target); + + if (selectedMove.name == "BLAZING CHARGE") + { + // Recoil effect: Charmander takes recoil damage + this->takeDamage(10); // Fixed recoil damage + std::cout << name << " takes 10 recoil damage from the Blazing Charge!\n"; + Utility::Utility::waitForEnter(); + } } \ No newline at end of file diff --git a/Pokemon/Charmander.h b/Pokemon/Charmander.h index 64fbeb0b..6ad3bbba 100644 --- a/Pokemon/Charmander.h +++ b/Pokemon/Charmander.h @@ -1,10 +1,8 @@ #include"Pokemon.h" #pragma once -class Charmander : public Pokemon -{ +class Charmander : public Pokemon { public: - Charmander(); -private: - void attack(Pokemon* target)override; + Charmander(); + void attack(Move selectedMove, Pokemon* target) override; }; diff --git a/Pokemon/Game.cpp b/Pokemon/Game.cpp index 859fa8c0..366293f4 100644 --- a/Pokemon/Game.cpp +++ b/Pokemon/Game.cpp @@ -5,29 +5,31 @@ #include "WildEncounterManager.h" #include #include"BattleManager.h" +#include "Caterpie.h" +#include "Pidgey.h" +#include "Zubat.h" +#include "Utility.h" +#include using namespace std; Game::Game() { // Create a sample grass environment with actual Pokemon objects - forestGrass = { "Forest", - {Pokemon("Pidgey", PokemonType::NORMAL, 40), - Pokemon("Caterpie", PokemonType::BUG, 35), - Pokemon("Zubat", PokemonType::POISON, 30)}, - 70 }; + forestGrass = { "Forest", {new Pidgey(), new Caterpie(), new Zubat()}, 70 }; } -void Game::gameLoop(Player& player) { +void Game::gameLoop(Player* player) { - BattleManager BattleManager; int choice; bool keepPlaying = true; + BattleManager* battleManager = new BattleManager(); + WildEncounterManager* encounterManager = new WildEncounterManager(); while (keepPlaying) { // Clear console before showing options Utility::clearConsole(); // Display options to the player - cout << "\nWhat would you like to do next, " << player.name << "?\n"; + cout << "\nWhat would you like to do next, " << player->name << "?\n"; cout << "1. Battle Wild Pokémon\n"; cout << "2. Visit PokeCenter\n"; cout << "3. Challenge Gyms\n"; @@ -41,16 +43,12 @@ void Game::gameLoop(Player& player) { // Process the player's choice and display the corresponding message switch (choice) { case 1: { - // Create a scope within case 1 - WildEncounterManager encounterManager; - Pokemon wildPokemon = encounterManager.getRandomPokemonFromGrass(forestGrass); - BattleManager.startBattle(player,wildPokemon);; + wildPokemon = encounterManager->getRandomPokemonFromGrass(forestGrass); + battleManager->startBattle(player, wildPokemon); break; } case 2: { - cout << "You head to the PokeCenter.\\n"; - player.chosenPokemon.heal(); - cout << player.chosenPokemon.name << " has been healed to full health!\n"; + visitPokeCenter(player); break; } case 3: { @@ -85,5 +83,27 @@ void Game::gameLoop(Player& player) { Utility::waitForEnter(); } - cout << "Goodbye, " << player.name << "! Thanks for playing!\n"; + cout << "Goodbye, " << player->name << "! Thanks for playing!\n"; + + delete(encounterManager); + delete(battleManager); +} + +void Game::visitPokeCenter(Player* player) { + if (player->chosenPokemon->health == player->chosenPokemon->maxHealth) { + std::cout << "Your Pokémon is already at full health!\n"; + } + else { + std::cout << "You head to the PokeCenter.\n"; + std::cout << "Healing your Pokémon...\n"; + Utility::waitForEnter(); // Simulate a short pause for the + // healing process + player->chosenPokemon->heal(); // Heal the player's Pokémon + std::cout << player->chosenPokemon->name << "'s health is fully restored!\n"; + } +} + +Game::~Game() +{ + delete(wildPokemon); } \ No newline at end of file diff --git a/Pokemon/Game.h b/Pokemon/Game.h index e5d3602a..1284dd9f 100644 --- a/Pokemon/Game.h +++ b/Pokemon/Game.h @@ -1,11 +1,17 @@ +#pragma once +#include "Player.h" #include "Grass.h" -class Player; +// class Player; class Game { private: - Grass forestGrass; + Grass forestGrass; + Pokemon* wildPokemon; + public: - Game(); - void gameLoop(Player& player); -}; \ No newline at end of file + Game(); + ~Game(); + void gameLoop(Player* player); + void visitPokeCenter(Player* player); +}; diff --git a/Pokemon/Grass.cpp b/Pokemon/Grass.cpp index 7378afdd..0de5d572 100644 --- a/Pokemon/Grass.cpp +++ b/Pokemon/Grass.cpp @@ -1,14 +1,21 @@ #include "Grass.h" -#include"PokemonType.h" +#include "PokemonType.h" +#include "Move.h" Grass forestGrass = { - "Forest", - {{"Pidgey", PokemonType::NORMAL, 40}, {"Caterpie", PokemonType::BUG, 35}}, - 70 + "Forest", + { + new Pokemon("Pidgey", PokemonType::NORMAL, 40, {Move("GUST", 15), Move("TACKLE", 10)}), + new Pokemon("Caterpie", PokemonType::BUG, 35, {Move("TACKLE", 10), Move("STRING SHOT", 5)}) + }, + 70 }; Grass caveGrass = { - "Cave", - {{"Zubat", PokemonType::POISON, 30}, {"Geodude", PokemonType::ROCK, 50}}, - 80 + "Cave", + { + new Pokemon("Zubat", PokemonType::POISON, 30, {Move("BITE", 12), Move("WING ATTACK", 10)}), + new Pokemon("Geodude", PokemonType::ROCK, 50, {Move("TACKLE", 10), Move("DEFENSE CURL", 5)}) + }, + 80 }; \ No newline at end of file diff --git a/Pokemon/Grass.h b/Pokemon/Grass.h index 0c0c9516..41a9423e 100644 --- a/Pokemon/Grass.h +++ b/Pokemon/Grass.h @@ -1,12 +1,13 @@ #include #include #include"Pokemon.h" +#include using namespace std; +class Pokemon; -struct Grass{ - string environmentType; // Example: "Forest", "Cave", "Riverbank" - vector wildPokemonList; // List of wild Pokémon that live in this grass - int encounterRate; // Likelihood of encountering a wild Pokémon, out of 100 - +struct Grass { + std::string environmentType; // Example: "Forest", "Cave", "Riverbank" + std::vector wildPokemonList; // List of wild Pokémon in this grass + int encounterRate; // Likelihood of encountering a wild Pokémon, out of 100 }; diff --git a/Pokemon/Move.cpp b/Pokemon/Move.cpp new file mode 100644 index 00000000..40185c88 --- /dev/null +++ b/Pokemon/Move.cpp @@ -0,0 +1 @@ +#include "Move.h" diff --git a/Pokemon/Move.h b/Pokemon/Move.h new file mode 100644 index 00000000..6c2a023e --- /dev/null +++ b/Pokemon/Move.h @@ -0,0 +1,16 @@ +#pragma once +#include +using namespace std; + + +struct Move +{ + string name; + int power; + + Move(const string& moveName, int movePower) + { + name = moveName; + power = movePower; + } +}; diff --git a/Pokemon/MoveName.cpp b/Pokemon/MoveName.cpp new file mode 100644 index 00000000..441d1119 --- /dev/null +++ b/Pokemon/MoveName.cpp @@ -0,0 +1 @@ +#include "MoveName.h" diff --git a/Pokemon/MoveName.h b/Pokemon/MoveName.h new file mode 100644 index 00000000..46f3201e --- /dev/null +++ b/Pokemon/MoveName.h @@ -0,0 +1,17 @@ +#pragma once + +enum class MoveName +{ + BUG_BITE, + TACKLE, + EMBER, + THUNDERSHOCK, + QUICK_ATTACK, + GUST, + WATER_GUN, + VINE_WHIP, + STRING_SHOT, + SCRATCH, + BITE, + LEECH_LIFE +}; \ No newline at end of file diff --git a/Pokemon/Pidgey.cpp b/Pokemon/Pidgey.cpp index 5a19e273..92521ca4 100644 --- a/Pokemon/Pidgey.cpp +++ b/Pokemon/Pidgey.cpp @@ -1,12 +1,30 @@ #include "Pidgey.h" #include #include "PokemonType.h" +#include "Move.h" +#include "BattleManager.h" +#include "Utility.h" using namespace std; -Pidgey::Pidgey() : Pokemon("Pidgey", PokemonType::NORMAL, 100, 35) {} +Pidgey::Pidgey() + : Pokemon("Pidgey", PokemonType::FLYING, 80, { + Move("GUST", 15), + Move("TACKLE", 10) + }) { +} -void Pidgey::attack(Pokemon* target) { - wingAttack(target); - cout << name << " uses Vine Whip on " << target.name << "!\n"; - target.TakeDamage(20); +void Pidgey::attack(Move selectedMove, Pokemon* target) +{ + Pokemon::attack(selectedMove, target); + + if (selectedMove.name == "GUST") + { + // 20% chance to blow the opponent away + if (rand() % 100 < 20) + { + std::cout << "... and blew the opponent away!\n"; + BattleManager::stopBattle(); + Utility::Utility::waitForEnter(); + } + } } \ No newline at end of file diff --git a/Pokemon/Pidgey.h b/Pokemon/Pidgey.h index b2e8cb77..e7e3efe1 100644 --- a/Pokemon/Pidgey.h +++ b/Pokemon/Pidgey.h @@ -1,10 +1,8 @@ #include"Pokemon.h" #pragma once -class Pidgey : public Pokemon -{ +class Pidgey : public Pokemon { public: - Pidgey(); -private: - void attack(Pokemon* target)override; -}; + Pidgey(); + void attack(Move selectedMove, Pokemon* target) override; +}; \ No newline at end of file diff --git a/Pokemon/Pikachu.cpp b/Pokemon/Pikachu.cpp index 22e096dc..3387aef8 100644 --- a/Pokemon/Pikachu.cpp +++ b/Pokemon/Pikachu.cpp @@ -1,12 +1,31 @@ #include "Pikachu.h" #include #include"PokemonType.h" +#include "Move.h" using namespace std; -Pikachu::Pikachu() : Pokemon("Pikachu", PokemonType::ELECTRIC, 100, 20) {} +Pikachu::Pikachu() + : Pokemon("Pikachu", PokemonType::ELECTRIC, 100, { + Move("THUNDER SHOCK", 20), + Move("QUICK ATTACK", 10), + Move("THUNDER BOLT", 80) + }) { +} + +void Pikachu::attack(Move selectedMove, Pokemon* target) +{ + if (selectedMove.name == "THUNDER BOLT") + { + // 80% chance to hit + if (rand() % 100 < 80) + { + Pokemon::attack(selectedMove, target); + std::cout << "... and it hit successfully!\n"; + } + else + std::cout << "... but it missed!\n"; + } + else + Pokemon::attack(selectedMove, target); -void Pikachu::attack(Pokemon* target) { - thunderShock(target); - cout << name << "uses Thunder shock on " << target.name << "\n"; - target.TakeDamage(20); } \ No newline at end of file diff --git a/Pokemon/Pikachu.h b/Pokemon/Pikachu.h index b01abd71..b3bbff6c 100644 --- a/Pokemon/Pikachu.h +++ b/Pokemon/Pikachu.h @@ -1,11 +1,8 @@ #include"Pokemon.h" #pragma once -class Pikachu : public Pokemon -{ +class Pikachu : public Pokemon { public: - Pikachu(); -private: - void attack(Pokemon* target)override; -}; - + Pikachu(); + void attack(Move selectedMove, Pokemon* target) override; +}; \ No newline at end of file diff --git a/Pokemon/Pokemon.cpp b/Pokemon/Pokemon.cpp index a65230d8..8a1cae51 100644 --- a/Pokemon/Pokemon.cpp +++ b/Pokemon/Pokemon.cpp @@ -1,40 +1,110 @@ #include "Pokemon.h" #include #include"PokemonType.h" +#include "Move.h" +#include "Utility.h" + +// Default constructor +Pokemon::Pokemon() { + name = "Unknown"; + type = PokemonType::NORMAL; + health = 50; + maxHealth = 50; +} -Pokemon::Pokemon():name("unknown"),type(PokemonType::NORMAL),health(50),attackPower(10){} // Parameterized constructor -Pokemon::Pokemon(string p_name, PokemonType p_type, int p_health,int p_attackPower): name(p_name), -type(p_type), -health(p_health), -attackPower(p_attackPower){ +Pokemon::Pokemon(string p_name, PokemonType p_type, int p_health, vector p_moves) { + name = p_name; + type = p_type; + maxHealth = p_health; + health = p_health; + moves = p_moves; } // Copy constructor -Pokemon::Pokemon(const Pokemon& other):name(other.name),type(other.type),health(other.health),attackPower(other.attackPower) {} +Pokemon::Pokemon(Pokemon* other) { + name = other->name; + type = other->type; + health = other->health; + maxHealth = other->maxHealth; + moves = other->moves; +} -// Destructor -Pokemon::~Pokemon() { - // Destructor message removed +// Reduce HP by the damage amount +void Pokemon::takeDamage(int damage) { + health -= damage; + if (health < 0) { + health = 0; + } } -/*void Pokemon::attack(Pokemon& target) { - int damage = attackPower; // Example damage value, could be based on type or other factors - target.TakeDamage(damage); // Example damage value - cout << name << " attacks " << target.name << " for " << damage << " damage!\\n"; -}*/ -void Pokemon::TakeDamage(int Damage) { - health -= Damage;// Reduce health by the damage taken +void Pokemon::selectAndUseMove(Pokemon* target) +{ + printAvailableMoves(); - if (health < 0) { - health = 0; // Ensure health doesn't go below 0 + int choice = selectMove(); + Move selectedMove = moves[choice - 1]; + + useMove(selectedMove, target); +} + +void Pokemon::reduceAttackPower(int reduced_damage) +{ + for (int i = 0; i < moves.size(); i++) + { + moves[i].power -= reduced_damage; + if (moves[i].power < 0) + moves[i].power = 0; + } +} + +void Pokemon::printAvailableMoves() +{ + cout << name << "'s available moves:\n"; + + // List out all moves for the player to choose from + for (size_t i = 0; i < moves.size(); ++i) { + cout << i + 1 << ": " << moves[i].name << " (Power: " << moves[i].power << ")\n"; + } +} + +int Pokemon::selectMove() +{ + // Ask the player to select a move + int choice; + cout << "Choose a move: "; + cin >> choice; + + // Validate the choice + while (choice < 1 || choice > static_cast(moves.size())) { + cout << "Invalid choice. Try again: "; + cin >> choice; } + + return choice; } -bool Pokemon::isFainted() const { - return health <= 0; // Check if health is 0 or less + +void Pokemon::useMove(Move selectedMove, Pokemon* target) +{ + cout << name << " used " << selectedMove.name << "!\n"; + attack(selectedMove, target); + + Utility::Utility::waitForEnter(); + + cout << "...\n"; + Utility::Utility::waitForEnter(); + + if (target->isFainted()) + cout << target->name << " fainted!\n"; + else + cout << target->name << " has " << target->health << " HP left.\n"; } -int Pokemon::heal() { - int healAmount = maxHealth; // Example heal amount - return health; // Return the new health value +void Pokemon::attack(Move selectedMove, Pokemon* target) { target->takeDamage(selectedMove.power); } + +// Check if the Pokemon has fainted +bool Pokemon::isFainted() const { return health <= 0; } + +// Restore health to full +void Pokemon::heal() { health = maxHealth; } \ No newline at end of file diff --git a/Pokemon/Pokemon.h b/Pokemon/Pokemon.h index b78da72f..25c728dd 100644 --- a/Pokemon/Pokemon.h +++ b/Pokemon/Pokemon.h @@ -1,33 +1,35 @@ #include +#include +#include "Move.h" using namespace std; enum class PokemonType; +struct Move; +enum class PokemonType; + class Pokemon { -protected: - string name; +public: + std::string name; PokemonType type; int health; int maxHealth; - int attackPower; -public: - // Default constructor - Pokemon(); + vector moves; // Store the list of moves - // Parameterized constructor - Pokemon(string p_name, PokemonType p_type, int p_health,int attackPower); - - // Copy constructor - Pokemon(const Pokemon& other); - - // Destructor - ~Pokemon(); - - virtual void attack(Pokemon * target)=0; - - void TakeDamage(int damage); + Pokemon(); + Pokemon(std::string p_name, PokemonType p_type, int p_health, vector); + Pokemon(Pokemon* other); - bool isFainted() const; + bool isFainted() const; + void heal(); + virtual void attack(Move selectedMove, Pokemon* target); + void takeDamage(int damage); + void selectAndUseMove(Pokemon* target); + void reduceAttackPower(int reduced_damage); - int heal(); +protected: + // Base implementation for selecting and using a move + void printAvailableMoves(); + int selectMove(); + void useMove(Move selectedMove, Pokemon* target); }; \ No newline at end of file diff --git a/Pokemon/PokemonType.h b/Pokemon/PokemonType.h index 7ee5187a..5b99db86 100644 --- a/Pokemon/PokemonType.h +++ b/Pokemon/PokemonType.h @@ -7,5 +7,6 @@ enum class PokemonType { NORMAL, BUG, POISON, - ROCK // Added for the default constructor + ROCK, + FLYING// Added for the default constructor }; \ No newline at end of file diff --git a/Pokemon/ProfessorOak.cpp b/Pokemon/ProfessorOak.cpp index 66ea0e0b..f33942bd 100644 --- a/Pokemon/ProfessorOak.cpp +++ b/Pokemon/ProfessorOak.cpp @@ -5,33 +5,29 @@ // Parameterized constructor ProfessorOak::ProfessorOak(string p_name) { name = p_name; } -void ProfessorOak::greetPlayer(Player& player) { +void ProfessorOak::greetPlayer(Player* player) { + cout << name << ": Hello there! Welcome to the world of Pokemon!\n"; Utility::waitForEnter(); - cout << name - << ": My name is Oak. People call me the Pokemon Professor!\n"; + cout << name << ": My name is Oak. People call me the Pokemon Professor!\n"; Utility::waitForEnter(); cout << name << ": But enough about me. Let's talk about you!\n"; Utility::waitForEnter(); } -void ProfessorOak::offerPokemonChoices(Player& player) { - cout - << name - << ": First, tell me, what’s your name? \t [Please Enter Your Name]\n"; - getline(cin, player.name); - cout << name << ": Ah, " << player.name - << "! What a fantastic name!\n"; +void ProfessorOak::offerPokemonChoices(Player* player) { + + std::cout << name << ": First, tell me, what’s your name? \t [Please Enter Your Name]\n"; + std::getline(std::cin, player->name); + std::cout << name << ": Ah, " << player->name << "! What a fantastic name!\n"; Utility::waitForEnter(); - cout << name + std::cout << name << ": You must be eager to start your adventure. But first, " "you’ll need a Pokemon of your own!\n"; Utility::waitForEnter(); // Presenting Pokemon choices - cout - << name - << ": I have three Pokemon here with me. They’re all quite feisty!\n"; + cout << name << ": I have three Pokemon here with me. They’re all quite feisty!\n"; Utility::waitForEnter(); cout << name << ": Choose wisely...\n"; cout << "1. Charmander - The fire type. A real hothead!\n"; @@ -39,40 +35,37 @@ void ProfessorOak::offerPokemonChoices(Player& player) { cout << "3. Squirtle - The water type. Cool as a cucumber!\n"; int choice; - cout - << name - << ": So, which one will it be? Enter the number of your choice: "; + cout << name << ": So, which one will it be? Enter the number of your choice: "; cin >> choice; - player.choosePokemon(choice); + player->choosePokemon(choice); Utility::waitForEnter(); } -// New method for the main quest conversation -void ProfessorOak::explainMainQuest(Player& player) { +void ProfessorOak::explainMainQuest(Player* player) { + // Clear the console Utility::clearConsole(); - cout << "Professor Oak: " << player.name + cout << "Professor Oak: " << player->name << "!, I am about to explain you about your upcoming grand " "adventure.\n"; Utility::waitForEnter(); cout << "Professor Oak: You see, becoming a Pokémon Master is no easy " "feat. It takes courage, wisdom, and a bit of luck!\n"; Utility::waitForEnter(); - cout - << "Professor Oak: Your mission, should you choose to accept it—and " + cout << "Professor Oak: Your mission, should you choose to accept it—and " "trust me, you really don’t have a choice—is to collect all the " "Pokémon Badges and conquer the Pokémon League.\n"; Utility::waitForEnter(); cout << "\n" - << player.name + << player->name << ": Wait... that sounds a lot like every other Pokémon game " "out there...\n"; Utility::waitForEnter(); - cout << "Professor Oak: Shhh! Don't break the fourth wall, " - << player.name << "! This is serious business!\n"; + cout << "Professor Oak: Shhh! Don't break the fourth wall, " << player->name + << "! This is serious business!\n"; Utility::waitForEnter(); cout << "\nProfessor Oak: To achieve this, you’ll need to battle wild " @@ -84,8 +77,7 @@ void ProfessorOak::explainMainQuest(Player& player) { "many Pokémon you can carry, so choose wisely!\n"; Utility::waitForEnter(); - cout << "\n" - << player.name << ": Sounds like a walk in the park... right?\n"; + cout << "\n" << player->name << ": Sounds like a walk in the park... right?\n"; Utility::waitForEnter(); cout << "Professor Oak: Hah! That’s what they all say! But beware, " "young Trainer, the path to victory is fraught with " @@ -96,14 +88,12 @@ void ProfessorOak::explainMainQuest(Player& player) { cout << "\nProfessor Oak: So, what do you say? Are you ready to " "become the next Pokémon Champion?\n"; Utility::waitForEnter(); - cout << "\n" << player.name << ": Ready as I’ll ever be, Professor!\n"; + cout << "\n" << player->name << ": Ready as I’ll ever be, Professor!\n"; Utility::waitForEnter(); - cout - << "\nProfessor Oak: That’s the spirit! Now, your journey begins...\n"; + cout << "\nProfessor Oak: That’s the spirit! Now, your journey begins...\n"; Utility::waitForEnter(); cout << "Professor Oak: But first... let's just pretend I didn't " "forget to set up the actual game loop... Ahem, onwards!\n"; Utility::waitForEnter(); } - diff --git a/Pokemon/ProfessorOak.h b/Pokemon/ProfessorOak.h index 8463d19f..14e7bf46 100644 --- a/Pokemon/ProfessorOak.h +++ b/Pokemon/ProfessorOak.h @@ -1,20 +1,17 @@ -#include -#include "player.h" +#include +#include "Player.h" + +class Player; + using namespace std; -// ProfessorOak class definition class ProfessorOak { public: string name; - // Parameterized constructor ProfessorOak(string p_name); - - void greetPlayer(Player& player); - - void offerPokemonChoices(Player& player); - - // New method for the main quest conversation - void explainMainQuest(Player& player); + void greetPlayer(Player* player); + void offerPokemonChoices(Player* player); + void explainMainQuest(Player* player); }; \ No newline at end of file diff --git a/Pokemon/Squirtle.cpp b/Pokemon/Squirtle.cpp index 48dfbcce..4c845422 100644 --- a/Pokemon/Squirtle.cpp +++ b/Pokemon/Squirtle.cpp @@ -1,13 +1,32 @@ #include "Squirtle.h" #include #include "PokemonType.h" +#include "Move.h" using namespace std; -Squirtle::Squirtle() : Pokemon("Squirtle", PokemonType::WATER, 100, 35) {} +Squirtle::Squirtle() + : Pokemon("Squirtle", PokemonType::WATER, 105, { + Move("WATER GUN", 20), + Move("TACKLE", 10), + Move("RAPID SPIN", 5) + }) { +} -void Squirtle::attack(Pokemon* target) { - WaterSplash(target); - cout << name << " uses Water Splash on " << target.name << "!\n"; - target.TakeDamage(20); +void Squirtle::attack(Move selectedMove, Pokemon* target) +{ + Pokemon::attack(selectedMove, target); + + if (selectedMove.name == "RAPID SPIN") + { + // Random number of hits between 2 and 5 + int hits = (rand() % 4) + 2; + + // Split damage across hits + for (int i = 0; i < hits; ++i) { + Pokemon::attack(selectedMove, target); + } + + std::cout << "... and hit " << hits << " times!\\n"; + } } \ No newline at end of file diff --git a/Pokemon/Squirtle.h b/Pokemon/Squirtle.h index f62e8f1b..1ff3b3b1 100644 --- a/Pokemon/Squirtle.h +++ b/Pokemon/Squirtle.h @@ -1,10 +1,9 @@ #pragma once #include"Pokemon.h" -class Squirtle: public Pokemon -{ +class Squirtle : public Pokemon { public: - Squirtle(); -private: - void attack(Pokemon* target)override; + Squirtle(); + void attack(Move selectedMove, Pokemon* target) override; }; + diff --git a/Pokemon/WildEncounterManager.cpp b/Pokemon/WildEncounterManager.cpp index a9f116c8..86645895 100644 --- a/Pokemon/WildEncounterManager.cpp +++ b/Pokemon/WildEncounterManager.cpp @@ -1,13 +1,19 @@ #include "WildEncounterManager.h" +#include "Grass.h" // Assuming the Grass struct is defined here +#include "Pokemon.h" // Assuming the Pokemon class is defined here #include // For rand() #include // For time() + WildEncounterManager::WildEncounterManager() { srand(time(0)); // Seed the random number generator } -Pokemon WildEncounterManager::getRandomPokemonFromGrass(const Grass& grass) { +Pokemon* WildEncounterManager::getRandomPokemonFromGrass(const Grass& grass) { int randomIndex = rand() % grass.wildPokemonList.size(); - return grass.wildPokemonList[randomIndex]; + + Pokemon* wildPokemon = grass.wildPokemonList[randomIndex]; + + return wildPokemon; } \ No newline at end of file diff --git a/Pokemon/WildEncounterManager.h b/Pokemon/WildEncounterManager.h index 534cc6aa..d9d8cc02 100644 --- a/Pokemon/WildEncounterManager.h +++ b/Pokemon/WildEncounterManager.h @@ -1,8 +1,12 @@ -#include -#include "Grass.h" // Assuming the Grass struct is defined here +#include "Pokemon.h" + +struct Grass; +class Pokemon; + + class WildEncounterManager { public: - Pokemon getRandomPokemonFromGrass(const Grass& grass - ); -}; + WildEncounterManager(); + Pokemon* getRandomPokemonFromGrass(const Grass& grass); +}; \ No newline at end of file diff --git a/Pokemon/Zubat.cpp b/Pokemon/Zubat.cpp index b4d555d4..208ac68e 100644 --- a/Pokemon/Zubat.cpp +++ b/Pokemon/Zubat.cpp @@ -1,13 +1,31 @@ #include "Zubat.h" #include "PokemonType.h" #include +#include "Move.h" using namespace std; -Zubat::Zubat() : Pokemon("Zubat", PokemonType::POISON, 100, 20) {} - -void Zubat::attack(Pokemon* target){ - supersonic(target); - cout << name << " uses Supersonic on " << target.name << "!\n"; - target.TakeDamage(20); +Zubat::Zubat() + : Pokemon("Zubat", PokemonType::POISON, 85, { + Move("BITE", 18), + Move("LEECH LIFE", 10) + }) { } + +void Zubat::attack(Move selectedMove, Pokemon* target) +{ + // Call the base class method from child class. + Pokemon::attack(selectedMove, target); + + if (selectedMove.name == "LEECH LIFE") + { + // Restore 50% of the damage dealt + this->health += selectedMove.power * 0.5; + + // Ensure health does not exceed maxHealth + if (this->health > this->maxHealth) + this->health = this->maxHealth; + + std::cout << "... and regained health!\n"; + } +} \ No newline at end of file diff --git a/Pokemon/Zubat.h b/Pokemon/Zubat.h index f7567b46..337dcbb6 100644 --- a/Pokemon/Zubat.h +++ b/Pokemon/Zubat.h @@ -1,8 +1,7 @@ #pragma once #include"Pokemon.h" -class Zubat :public Pokemon -{ +class Zubat : public Pokemon { public: - Zubat(); - void attack(Pokemon* target)override; + Zubat(); + void attack(Move selectedMove, Pokemon* target) override; }; \ No newline at end of file diff --git a/Pokemon/player.cpp b/Pokemon/player.cpp index 133c9c11..5cc18bd5 100644 --- a/Pokemon/player.cpp +++ b/Pokemon/player.cpp @@ -1,38 +1,52 @@ -// Player.cpp -#include "player.h" -#include "PokemonChoice.h" +#include "Game.h" +#include "BattleManager.h" +#include "WildEncounterManager.h" +#include "Player.h" +#include "Caterpie.h" +#include "Pidgey.h" +#include "Zubat.h" +#include "Utility.h" +#include +#include"PokemonChoice.h" #include "PokemonType.h" -#include "Pokemon.h" +#include "Charmander.h" +#include "Bulbasaur.h" +#include "Squirtle.h" #include "Pikachu.h" -#include "utility.h" -#include "iostream" +#include using namespace std; + + +Game::Game() { + // Create a sample grass environment with actual Pokemon objects + forestGrass = { "Forest", {new Pidgey(), new Caterpie(), new Zubat()}, 70 }; +} + Player::Player() { name = "Trainer"; - chosenPokemon = Pokemon(); // Using the default Pokemon constructor } -Player::Player(string p_name, Pokemon p_chosenPokemon) { +Player::Player(std::string p_name) { name = p_name; - chosenPokemon = p_chosenPokemon; } void Player::choosePokemon(int choice) { switch ((PokemonChoice)choice) { case PokemonChoice::CHARMANDER: - chosenPokemon = Pokemon("Charmander", PokemonType::FIRE, 100,10); + chosenPokemon = new Charmander(); break; case PokemonChoice::BULBASAUR: - chosenPokemon = Pokemon("Bulbasaur", PokemonType::GRASS, 100,8); + chosenPokemon = new Bulbasaur(); break; case PokemonChoice::SQUIRTLE: - chosenPokemon = Pokemon("Squirtle", PokemonType::WATER, 100,9); + chosenPokemon = new Squirtle(); break; default: - chosenPokemon = Pikachu(); + chosenPokemon = new Pikachu(); break; } - cout << "Player " << name << " chose " << chosenPokemon.name << "!\n"; - Utility::waitForEnter(); // Wait for user to press Enter before proceeding + std::cout << "Player " << name << " chose " << chosenPokemon->name << "!\n"; + Utility::waitForEnter(); // Wait for user to press Enter before + // proceeding } \ No newline at end of file diff --git a/Pokemon/player.h b/Pokemon/player.h index 25fa68f2..0dbed8b9 100644 --- a/Pokemon/player.h +++ b/Pokemon/player.h @@ -1,15 +1,17 @@ -// Player.h +#pragma once #include #include "Pokemon.h" + using namespace std; + class Player { public: string name; - Pokemon chosenPokemon; + Pokemon* chosenPokemon; Player(); // Default constructor - Player(string p_name, Pokemon p_chosenPokemon); // Parameterized constructor + Player(string p_name); // Parameterized constructor void choosePokemon(int choice); // Method to choose a Pokemon -}; \ No newline at end of file +};