From dd4f9ada0e5fb6f261753838b0053dbdbf2fbde9 Mon Sep 17 00:00:00 2001 From: rangamach <117797904+rangamach@users.noreply.github.com> Date: Tue, 29 Oct 2024 18:50:18 +0530 Subject: [PATCH 01/30] Enter Name --- Pokemon/Pokemon/Pokemon.cpp | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/Pokemon/Pokemon/Pokemon.cpp b/Pokemon/Pokemon/Pokemon.cpp index 70d0cba..b484d92 100644 --- a/Pokemon/Pokemon/Pokemon.cpp +++ b/Pokemon/Pokemon/Pokemon.cpp @@ -1,20 +1,11 @@ -// Pokemon.cpp : This file contains the 'main' function. Program execution begins and ends there. -// - #include +using namespace std; + int main() { - std::cout << "Hello World!\n"; -} - -// Run program: Ctrl + F5 or Debug > Start Without Debugging menu -// Debug program: F5 or Debug > Start Debugging menu - -// Tips for Getting Started: -// 1. Use the Solution Explorer window to add/manage files -// 2. Use the Team Explorer window to connect to source control -// 3. Use the Output window to see build output and other messages -// 4. Use the Error List window to view errors -// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project -// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file + string player_name; + cout << "Enter your Name: "; + cin >> player_name; + cout << "Welcone to world of Pokemon " + player_name + "!"; +} \ No newline at end of file From c05b631be78eff1295080d895faad2a0e43c2cb8 Mon Sep 17 00:00:00 2001 From: rangamach <117797904+rangamach@users.noreply.github.com> Date: Tue, 29 Oct 2024 19:16:20 +0530 Subject: [PATCH 02/30] Choose First Pokemon --- Pokemon/Pokemon/Pokemon.cpp | 55 ++++++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 4 deletions(-) diff --git a/Pokemon/Pokemon/Pokemon.cpp b/Pokemon/Pokemon/Pokemon.cpp index b484d92..51dfb85 100644 --- a/Pokemon/Pokemon/Pokemon.cpp +++ b/Pokemon/Pokemon/Pokemon.cpp @@ -2,10 +2,57 @@ using namespace std; -int main() +static string EnterName() { - string player_name; + string name; cout << "Enter your Name: "; - cin >> player_name; - cout << "Welcone to world of Pokemon " + player_name + "!"; + cin >> name; + return name; +} + +static void WelcomeMessage(string name) +{ + cout << "Welcome " + name + "!\n"; +} + +static void ChooseFirstPokemon() +{ + cout << "Welcome to the world of Pokemon! I am Professor Oak.\n"; + cout << "You can choose one of the following Pokemon:\n"; + cout << "1. Bulbasaur\n2. Charmander\n3. Squirtle\n"; + cout << "Which Pokemon would you like to choose? Enter the number: "; + + int choice; + cin >> choice; + + switch (choice) + { + case 1: + cout << "You chose Bulbasaur! A wise choice.\n"; + break; + case 2: + cout << "You chose Charmander! A fiery choice.\n"; + break; + case 3: + cout << "You chose Squirtle! A cool choice.\n"; + break; + default: + cout << "Invalid choice. Please restart the game.\n"; + break; + } + + cout << "Ah, an excellent choice!\n"; + cout << "But beware, Trainer,\n"; + cout << "this is only the beginning.\n"; + cout << "Your journey is about to unfold.\n"; + cout << "Now let's see if you've got what it takes to keep going!\n"; + cout << "Good luck, and remember. . . Choose Wisely!\n"; +} + + + +int main() +{ + WelcomeMessage(EnterName()); + ChooseFirstPokemon(); } \ No newline at end of file From 6c2b609fc6fdb8ffec0f8fd33263958b491c37fe Mon Sep 17 00:00:00 2001 From: rangamach <117797904+rangamach@users.noreply.github.com> Date: Wed, 30 Oct 2024 09:13:52 +0530 Subject: [PATCH 03/30] Professor Oak Dialogue --- Pokemon/Pokemon/Pokemon.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/Pokemon/Pokemon/Pokemon.cpp b/Pokemon/Pokemon/Pokemon.cpp index 51dfb85..45d2791 100644 --- a/Pokemon/Pokemon/Pokemon.cpp +++ b/Pokemon/Pokemon/Pokemon.cpp @@ -2,6 +2,8 @@ using namespace std; +string player_name; + static string EnterName() { string name; @@ -22,30 +24,40 @@ static void ChooseFirstPokemon() cout << "1. Bulbasaur\n2. Charmander\n3. Squirtle\n"; cout << "Which Pokemon would you like to choose? Enter the number: "; + string chosen_pokemon; int choice; cin >> choice; switch (choice) { case 1: + chosen_pokemon = "Bulbasaur"; cout << "You chose Bulbasaur! A wise choice.\n"; break; case 2: + chosen_pokemon = "Charmander"; cout << "You chose Charmander! A fiery choice.\n"; break; case 3: + chosen_pokemon = "Squirtle"; cout << "You chose Squirtle! A cool choice.\n"; break; default: - cout << "Invalid choice. Please restart the game.\n"; + cout << "Professor Oak: Hmm, that doesn't seem right. Let me choose for you...\n"; + chosen_pokemon = "Pikachu"; + cout << "Professor Oak: Just kidding! Let's go with Pikachu, the surprise guest!\n"; break; } cout << "Ah, an excellent choice!\n"; + cout << "Professor Oak: " << chosen_pokemon << " and you, " + << player_name << ", are going to be the best of friends!\n"; cout << "But beware, Trainer,\n"; cout << "this is only the beginning.\n"; cout << "Your journey is about to unfold.\n"; cout << "Now let's see if you've got what it takes to keep going!\n"; + cout << "Professor Oak: Your journey begins now!"; + cout << "Get ready to explore the vast world of Pokemon!\n"; cout << "Good luck, and remember. . . Choose Wisely!\n"; } @@ -53,6 +65,7 @@ static void ChooseFirstPokemon() int main() { - WelcomeMessage(EnterName()); + player_name = EnterName(); + WelcomeMessage(player_name); ChooseFirstPokemon(); } \ No newline at end of file From 427f70cd650cd6f5f8d32bc7ae0f15988d8cdacc Mon Sep 17 00:00:00 2001 From: rangamach <117797904+rangamach@users.noreply.github.com> Date: Wed, 30 Oct 2024 10:22:29 +0530 Subject: [PATCH 04/30] Optimized Choosing of Pokemon --- Pokemon/Pokemon/Pokemon.cpp | 43 ++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/Pokemon/Pokemon/Pokemon.cpp b/Pokemon/Pokemon/Pokemon.cpp index 45d2791..ebe25d8 100644 --- a/Pokemon/Pokemon/Pokemon.cpp +++ b/Pokemon/Pokemon/Pokemon.cpp @@ -4,6 +4,15 @@ using namespace std; string player_name; +enum Pokemon_Choice +{ + Charmander, + Bulbasaur, + Squirtle, + Chosen_For_You +}; + +Pokemon_Choice chosen_pokemon; static string EnterName() { string name; @@ -24,34 +33,47 @@ static void ChooseFirstPokemon() cout << "1. Bulbasaur\n2. Charmander\n3. Squirtle\n"; cout << "Which Pokemon would you like to choose? Enter the number: "; - string chosen_pokemon; int choice; cin >> choice; switch (choice) { case 1: - chosen_pokemon = "Bulbasaur"; - cout << "You chose Bulbasaur! A wise choice.\n"; + chosen_pokemon = Charmander; break; case 2: - chosen_pokemon = "Charmander"; - cout << "You chose Charmander! A fiery choice.\n"; + chosen_pokemon = Bulbasaur; + break; case 3: - chosen_pokemon = "Squirtle"; + chosen_pokemon = Squirtle; + + break; + default: + chosen_pokemon = Chosen_For_You; + break; + } + + switch (chosen_pokemon) + { + case Charmander: + cout << "You chose Bulbasaur! A wise choice.\n"; + break; + case Bulbasaur: + cout << "You chose Charmander! A fiery choice.\n"; + break; + case Squirtle: cout << "You chose Squirtle! A cool choice.\n"; break; default: cout << "Professor Oak: Hmm, that doesn't seem right. Let me choose for you...\n"; - chosen_pokemon = "Pikachu"; - cout << "Professor Oak: Just kidding! Let's go with Pikachu, the surprise guest!\n"; + chosen_pokemon = Charmander; + cout << "Professor Oak: Just kidding! Let's go with Charmander, the surprise guest!\n"; break; } cout << "Ah, an excellent choice!\n"; - cout << "Professor Oak: " << chosen_pokemon << " and you, " - << player_name << ", are going to be the best of friends!\n"; + 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 << "But beware, Trainer,\n"; cout << "this is only the beginning.\n"; cout << "Your journey is about to unfold.\n"; @@ -66,6 +88,7 @@ static void ChooseFirstPokemon() int main() { player_name = EnterName(); + chosen_pokemon = Chosen_For_You; WelcomeMessage(player_name); ChooseFirstPokemon(); } \ No newline at end of file From 1fdc2c41a1228b8c22ae4a29d7ce6e4687d0d6f4 Mon Sep 17 00:00:00 2001 From: rangamach <117797904+rangamach@users.noreply.github.com> Date: Wed, 30 Oct 2024 11:01:01 +0530 Subject: [PATCH 05/30] Changed enum to enum classes --- Pokemon/Pokemon/Pokemon.cpp | 69 +++++++++++++++++++++++++------------ 1 file changed, 47 insertions(+), 22 deletions(-) diff --git a/Pokemon/Pokemon/Pokemon.cpp b/Pokemon/Pokemon/Pokemon.cpp index ebe25d8..d98f678 100644 --- a/Pokemon/Pokemon/Pokemon.cpp +++ b/Pokemon/Pokemon/Pokemon.cpp @@ -1,10 +1,10 @@ #include +#include using namespace std; -string player_name; - -enum Pokemon_Choice +//Enum Classes +enum class Pokemon_Choice { Charmander, Bulbasaur, @@ -12,7 +12,34 @@ enum Pokemon_Choice Chosen_For_You }; -Pokemon_Choice chosen_pokemon; +enum class Pokemon_Types +{ + Normal_Type, + Fire_Type, + Water_Type, + Electric_Type, + Grass_Type, + Ice_Type, + Fighting_Type, + Poison_Type, + Ground_Type, + Flying_Type, + Psychic_Type, + Bug_Type, + Rock_Type, + Ghost_Type, + Dragon_Type, + Dark_Type, + Steel_Type, + Fairy_Type +}; + + +//Variables +string player_name; +vector captured_pokemon; + +//Functions static string EnterName() { string name; @@ -26,8 +53,9 @@ static void WelcomeMessage(string name) cout << "Welcome " + name + "!\n"; } -static void ChooseFirstPokemon() +Pokemon_Choice ChooseFirstPokemon() { + Pokemon_Choice chosen_pokemon; cout << "Welcome to the world of Pokemon! I am Professor Oak.\n"; cout << "You can choose one of the following Pokemon:\n"; cout << "1. Bulbasaur\n2. Charmander\n3. Squirtle\n"; @@ -39,41 +67,39 @@ static void ChooseFirstPokemon() switch (choice) { case 1: - chosen_pokemon = Charmander; + chosen_pokemon = Pokemon_Choice::Charmander; break; case 2: - chosen_pokemon = Bulbasaur; - + chosen_pokemon = Pokemon_Choice::Bulbasaur; break; case 3: - chosen_pokemon = Squirtle; - + chosen_pokemon = Pokemon_Choice::Squirtle; break; default: - chosen_pokemon = Chosen_For_You; + chosen_pokemon = Pokemon_Choice::Chosen_For_You; break; } switch (chosen_pokemon) { - case Charmander: - cout << "You chose Bulbasaur! A wise choice.\n"; - break; - case Bulbasaur: + case Pokemon_Choice::Charmander: cout << "You chose Charmander! A fiery choice.\n"; break; - case Squirtle: + case Pokemon_Choice::Bulbasaur: + cout << "You chose Bulbasaur! A wise choice.\n"; + break; + case Pokemon_Choice::Squirtle: cout << "You chose Squirtle! A cool choice.\n"; break; default: cout << "Professor Oak: Hmm, that doesn't seem right. Let me choose for you...\n"; - chosen_pokemon = Charmander; + chosen_pokemon = Pokemon_Choice::Charmander; cout << "Professor Oak: Just kidding! Let's go with Charmander, the surprise guest!\n"; break; } cout << "Ah, an excellent choice!\n"; - 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: " << (chosen_pokemon == Pokemon_Choice::Charmander ? "Charmander" : chosen_pokemon == Pokemon_Choice::Bulbasaur ? "Bulbasaur" : "Squirtle") << " and you, " << player_name << ", are going to be the best of friends!\n"; cout << "But beware, Trainer,\n"; cout << "this is only the beginning.\n"; cout << "Your journey is about to unfold.\n"; @@ -81,14 +107,13 @@ static void ChooseFirstPokemon() cout << "Professor Oak: Your journey begins now!"; cout << "Get ready to explore the vast world of Pokemon!\n"; cout << "Good luck, and remember. . . Choose Wisely!\n"; -} - + return chosen_pokemon; +} int main() { player_name = EnterName(); - chosen_pokemon = Chosen_For_You; WelcomeMessage(player_name); - ChooseFirstPokemon(); + captured_pokemon.push_back(ChooseFirstPokemon()); } \ No newline at end of file From 967a46e611af461138bd52071cd656edff88cfcf Mon Sep 17 00:00:00 2001 From: rangamach <117797904+rangamach@users.noreply.github.com> Date: Thu, 31 Oct 2024 08:44:28 +0530 Subject: [PATCH 06/30] Created Player, ProfessorOak, Pokemon classes --- Pokemon/Pokemon/Pokemon.cpp | 163 ++++++++++++++++++++---------------- 1 file changed, 93 insertions(+), 70 deletions(-) diff --git a/Pokemon/Pokemon/Pokemon.cpp b/Pokemon/Pokemon/Pokemon.cpp index d98f678..3a422ac 100644 --- a/Pokemon/Pokemon/Pokemon.cpp +++ b/Pokemon/Pokemon/Pokemon.cpp @@ -1,15 +1,15 @@ #include -#include +#include using namespace std; //Enum Classes enum class Pokemon_Choice { - Charmander, + Charmander = 1, Bulbasaur, Squirtle, - Chosen_For_You + Pikachu }; enum class Pokemon_Types @@ -34,86 +34,109 @@ enum class Pokemon_Types Fairy_Type }; - -//Variables -string player_name; -vector captured_pokemon; - -//Functions -static string EnterName() +//Classes +class Pokemon { +public: string name; - cout << "Enter your Name: "; - cin >> name; - return name; -} + Pokemon_Types type; + int health; -static void WelcomeMessage(string name) -{ - cout << "Welcome " + name + "!\n"; -} - -Pokemon_Choice ChooseFirstPokemon() -{ - Pokemon_Choice chosen_pokemon; - cout << "Welcome to the world of Pokemon! I am Professor Oak.\n"; - cout << "You can choose one of the following Pokemon:\n"; - cout << "1. Bulbasaur\n2. Charmander\n3. Squirtle\n"; - cout << "Which Pokemon would you like to choose? Enter the number: "; + Pokemon() + { - int choice; - cin >> choice; + } - switch (choice) + Pokemon(string poke_name, Pokemon_Types poke_type, int poke_health) { - case 1: - chosen_pokemon = Pokemon_Choice::Charmander; - break; - case 2: - chosen_pokemon = Pokemon_Choice::Bulbasaur; - break; - case 3: - chosen_pokemon = Pokemon_Choice::Squirtle; - break; - default: - chosen_pokemon = Pokemon_Choice::Chosen_For_You; - break; + name = poke_name; + type = poke_type; + health = poke_health; } - switch (chosen_pokemon) + void Attack() { - case Pokemon_Choice::Charmander: - cout << "You chose Charmander! A fiery choice.\n"; - break; - case Pokemon_Choice::Bulbasaur: - cout << "You chose Bulbasaur! A wise choice.\n"; - break; - case Pokemon_Choice::Squirtle: - cout << "You chose Squirtle! A cool choice.\n"; - break; - default: - cout << "Professor Oak: Hmm, that doesn't seem right. Let me choose for you...\n"; - chosen_pokemon = Pokemon_Choice::Charmander; - cout << "Professor Oak: Just kidding! Let's go with Charmander, the surprise guest!\n"; - break; + cout << name << " attacks with a powerful move!\n"; } +}; - cout << "Ah, an excellent choice!\n"; - cout << "Professor Oak: " << (chosen_pokemon == Pokemon_Choice::Charmander ? "Charmander" : chosen_pokemon == Pokemon_Choice::Bulbasaur ? "Bulbasaur" : "Squirtle") << " and you, " << player_name << ", are going to be the best of friends!\n"; - cout << "But beware, Trainer,\n"; - cout << "this is only the beginning.\n"; - cout << "Your journey is about to unfold.\n"; - cout << "Now let's see if you've got what it takes to keep going!\n"; - cout << "Professor Oak: Your journey begins now!"; - cout << "Get ready to explore the vast world of Pokemon!\n"; - cout << "Good luck, and remember. . . Choose Wisely!\n"; +class Player +{ + public: + string name; + Pokemon captured_pokemon; - return chosen_pokemon; -} + void ChosenPokemon(int choice) + { + switch ((Pokemon_Choice)choice) + { + case Pokemon_Choice::Charmander: + captured_pokemon = Pokemon("Charmander", Pokemon_Types::Fire_Type, 100); + break; + case Pokemon_Choice::Bulbasaur: + captured_pokemon = Pokemon("Bulbasaur", Pokemon_Types::Grass_Type, 100); + break; + case Pokemon_Choice::Squirtle: + captured_pokemon = Pokemon("Squirtle", Pokemon_Types::Water_Type, 100); + break; + default: + captured_pokemon = Pokemon("Pikachu", Pokemon_Types::Electric_Type, 100); + break; + } + cout << name << " chose " << captured_pokemon.name << "\n"; + } +}; + +class ProfessorOak +{ + public: + string name; + void GreetPlayer(Player& player) + { + cout << name << ": Welcome to the world of Pokemon! I am Professor Oak.\n"; + cout << name << ": People call me the Pokemon Professor!\n"; + cout << name << ": But enough about me. Let's talk about you!\n"; + } + + void PlayerIntro(Player& player) + { + cout << name << ": First, tell me what is 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 will need a Pokemon of your own!\n"; + } + void FirstPokemon(Player& player) + { + int choice; + cout << name << ": I have three Pokemon here with me. They are all quite feisty!\n"; + cout << name << ": Choose wisely...\n"; + cout << name << ": 1. Charmander - The fire type. A real hothead!\n"; + cout << name << ": 2. Bulbasaur - The grass type. Calm and collected!\n"; + cout << name << ": 3. Squirtle - The water type. Cool as a cucumber!\n"; + + cout << name << ": So, which one will it be? Enter the number of your choice:"; + cin >> choice; + player.ChosenPokemon(choice); + } +}; int main() { - player_name = EnterName(); - WelcomeMessage(player_name); - captured_pokemon.push_back(ChooseFirstPokemon()); + ProfessorOak Oak; + Pokemon placeholderPokemon; + Player player; + + placeholderPokemon.name = "Pikachu"; + placeholderPokemon.type = Pokemon_Types::Electric_Type; + placeholderPokemon.health = 40; + + player.name = "Trainer"; + Oak.name = "Professor Oak"; + + Oak.GreetPlayer(player); + Oak.PlayerIntro(player); + Oak.FirstPokemon(player); + + cout << "Professor Oak: " << player.captured_pokemon.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"; } \ No newline at end of file From 74abf2037d7e28fee82532e26c428b8cb3d119d9 Mon Sep 17 00:00:00 2001 From: rangamach <117797904+rangamach@users.noreply.github.com> Date: Thu, 31 Oct 2024 09:41:05 +0530 Subject: [PATCH 07/30] Added Constructors and Destructor. --- Pokemon/Pokemon/Pokemon.cpp | 63 ++++++++++++++++++++++++++++++++++--- 1 file changed, 59 insertions(+), 4 deletions(-) diff --git a/Pokemon/Pokemon/Pokemon.cpp b/Pokemon/Pokemon/Pokemon.cpp index 3a422ac..fdc778f 100644 --- a/Pokemon/Pokemon/Pokemon.cpp +++ b/Pokemon/Pokemon/Pokemon.cpp @@ -44,7 +44,10 @@ class Pokemon Pokemon() { - + name = "Unknown"; + type = Pokemon_Types::Normal_Type; + health = 50; + cout << "A new Pokemon has been created with the default constructor!\n"; } Pokemon(string poke_name, Pokemon_Types poke_type, int poke_health) @@ -54,6 +57,19 @@ class Pokemon health = poke_health; } + Pokemon(const Pokemon &other) + { + name = other.name; + type = other.type; + health = other.health; + cout << "A new Pokemon has been copied from " << other.name << "!\n"; + } + + ~Pokemon() + { + cout << name << " has been released.\n"; + } + void Attack() { cout << name << " attacks with a powerful move!\n"; @@ -66,6 +82,16 @@ class Player string name; Pokemon captured_pokemon; + Player() + { + captured_pokemon = Pokemon(); + } + + Player(string playerName, Pokemon playerCapturedPokemon) + { + name = playerName; + captured_pokemon = playerCapturedPokemon; + } void ChosenPokemon(int choice) { switch ((Pokemon_Choice)choice) @@ -98,6 +124,11 @@ class ProfessorOak cout << name << ": But enough about me. Let's talk about you!\n"; } + ProfessorOak(string prof_name) + { + name = prof_name; + } + void PlayerIntro(Player& player) { cout << name << ": First, tell me what is your name?\n"; @@ -122,9 +153,33 @@ class ProfessorOak int main() { - ProfessorOak Oak; - Pokemon placeholderPokemon; - Player player; + // Task 1: Test default and parameterized constructors + Pokemon defaultPokemon; // Using default constructor + Pokemon charmander("Charmander", Pokemon_Types::Fire_Type, 100); // Using parameterized constructor + + 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"; + + // Task 2: Test the copy constructor + Pokemon bulbasaur("Bulbasaur", Pokemon_Types::Grass_Type, 100); // Create a Pokemon + Pokemon bulbasaurCopy = bulbasaur; // Copy the Pokemon + cout << "Original Pokemon Health: " << bulbasaur.health << "\n"; + cout << "Copied Pokemon Health: " << bulbasaurCopy.health << "\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"; + + // Task 3: Test the destructor + { + Pokemon squirtle("Squirtle", Pokemon_Types::Water_Type, 100); // Pokemon will be destroyed at the end of this scope + } // Destructor will be called here + ProfessorOak Oak("Professor Oak"); + Pokemon placeholderPokemon("Placeholder", Pokemon_Types::Fire_Type, 0); + Player player("", placeholderPokemon); placeholderPokemon.name = "Pikachu"; placeholderPokemon.type = Pokemon_Types::Electric_Type; From 1d0d5e1240ef2ee2ef1b97267bfed826aa5e25ce Mon Sep 17 00:00:00 2001 From: rangamach <117797904+rangamach@users.noreply.github.com> Date: Thu, 31 Oct 2024 11:02:34 +0530 Subject: [PATCH 08/30] Added Main Quest Explanation --- Pokemon/Pokemon/Pokemon.cpp | 135 ++++++++++++++++++++++++++---------- 1 file changed, 100 insertions(+), 35 deletions(-) diff --git a/Pokemon/Pokemon/Pokemon.cpp b/Pokemon/Pokemon/Pokemon.cpp index fdc778f..cef7818 100644 --- a/Pokemon/Pokemon/Pokemon.cpp +++ b/Pokemon/Pokemon/Pokemon.cpp @@ -3,6 +3,16 @@ using namespace std; +void WaitForEnter() +{ + cin.get(); +} + +void ClearConsole() +{ + system("cls"); +} + //Enum Classes enum class Pokemon_Choice { @@ -47,7 +57,6 @@ class Pokemon name = "Unknown"; type = Pokemon_Types::Normal_Type; health = 50; - cout << "A new Pokemon has been created with the default constructor!\n"; } Pokemon(string poke_name, Pokemon_Types poke_type, int poke_health) @@ -62,12 +71,11 @@ class Pokemon name = other.name; type = other.type; health = other.health; - cout << "A new Pokemon has been copied from " << other.name << "!\n"; } ~Pokemon() { - cout << name << " has been released.\n"; + } void Attack() @@ -120,8 +128,11 @@ class ProfessorOak void GreetPlayer(Player& player) { cout << name << ": Welcome to the world of Pokemon! I am Professor Oak.\n"; + WaitForEnter(); cout << name << ": People call me the Pokemon Professor!\n"; + WaitForEnter(); cout << name << ": But enough about me. Let's talk about you!\n"; + WaitForEnter(); } ProfessorOak(string prof_name) @@ -134,12 +145,15 @@ class ProfessorOak cout << name << ": First, tell me what is your name?\n"; getline(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 will need a Pokemon of your own!\n"; + WaitForEnter(); } void FirstPokemon(Player& player) { int choice; cout << name << ": I have three Pokemon here with me. They are all quite feisty!\n"; + WaitForEnter(); cout << name << ": Choose wisely...\n"; cout << name << ": 1. Charmander - The fire type. A real hothead!\n"; cout << name << ": 2. Bulbasaur - The grass type. Calm and collected!\n"; @@ -148,50 +162,101 @@ class ProfessorOak cout << name << ": So, which one will it be? Enter the number of your choice:"; cin >> choice; player.ChosenPokemon(choice); + + cout << "Professor Oak: " << player.captured_pokemon.name << " and you, " << player.name << ", are going to be the best of friends!\n"; + WaitForEnter(); + WaitForEnter(); + } + + void ExplainMainQuest(Player player) + { + ClearConsole(); + cout << name << ": Ok, " << player.name << ", I am about to explain you about your upcoming grand adventure.\n"; + WaitForEnter(); + cout << name << ": You see, becoming a Pokemon Master is no easy feat, it takes courage, wisdom, and a bit of luck.\n"; + WaitForEnter(); + cout << name << ": Your mission, should you choose to accept it (and trust me, you really don’t have a choice) is to collect all the Pokemon Badges and conquer the Pokemon League. \n"; + WaitForEnter(); + cout << player.name << ": Wait... that sounds a lot like every other Pokemon game out there.\n"; + WaitForEnter(); + cout << name << ": Shhh! Don't break the fourth wall " << player.name << "! This is serious business.\n"; + WaitForEnter(); + cout << name << ": 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 << name << ": Along the way, you'll capture new Pokemon to strengthen your team. Just remember—there’s a limit to how many Pokémon you can carry, so choose wisely!\n"; + WaitForEnter(); + cout << player.name << ": Sounds like a walk in the park... right?\n"; + WaitForEnter(); + cout << name << ": 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 << name << ": So, what do you say? Are you ready to become the next Pokemon Champion?\n"; + WaitForEnter(); + cout << player.name << ": Ready as I will ever be, Professor!\n"; + WaitForEnter(); + cout << name << ": That’s the spirit! Now, your journey begins.\n"; + WaitForEnter(); + cout << name << ": But first... let's just pretend I didn't forget to set up the actual game loop... Ahem, onwards!\n"; + WaitForEnter(); } }; +void GameLoop(Player &player) +{ + int choice; + bool keepPlaying = true; + ClearConsole(); + cout << "\nWhat would you like to do next, " << player.name << "?\n"; + cout << "1. Battle Wild Pokemon\n"; + cout << "2. Visit PokeCenter\n"; + cout << "3. Challenge Gyms\n"; + cout << "4. Enter Pokemon League\n"; + cout << "5. Quit\n"; + cout << "Enter your choice: "; + cin >> choice; + cin.ignore(numeric_limits::max(), '\n'); + 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 Pokemon 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; + }; + WaitForEnter(); + cout << "Goodbye, " << player.name << "! Thanks for playing!\n"; +} + int main() { - // Task 1: Test default and parameterized constructors - Pokemon defaultPokemon; // Using default constructor Pokemon charmander("Charmander", Pokemon_Types::Fire_Type, 100); // Using parameterized constructor - 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"; - - // Task 2: Test the copy constructor - Pokemon bulbasaur("Bulbasaur", Pokemon_Types::Grass_Type, 100); // Create a Pokemon - Pokemon bulbasaurCopy = bulbasaur; // Copy the Pokemon - cout << "Original Pokemon Health: " << bulbasaur.health << "\n"; - cout << "Copied Pokemon Health: " << bulbasaurCopy.health << "\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"; - // Task 3: Test the destructor - { - Pokemon squirtle("Squirtle", Pokemon_Types::Water_Type, 100); // Pokemon will be destroyed at the end of this scope - } // Destructor will be called here ProfessorOak Oak("Professor Oak"); - Pokemon placeholderPokemon("Placeholder", Pokemon_Types::Fire_Type, 0); - Player player("", placeholderPokemon); - - placeholderPokemon.name = "Pikachu"; - placeholderPokemon.type = Pokemon_Types::Electric_Type; - placeholderPokemon.health = 40; - - player.name = "Trainer"; - Oak.name = "Professor Oak"; + Player player("Ash", charmander); Oak.GreetPlayer(player); Oak.PlayerIntro(player); Oak.FirstPokemon(player); - cout << "Professor Oak: " << player.captured_pokemon.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"; + Oak.ExplainMainQuest(player); + + GameLoop(player); } \ No newline at end of file From 19b0fc979177ad647ea0bbf354a01ef95392c7ce Mon Sep 17 00:00:00 2001 From: rangamach <117797904+rangamach@users.noreply.github.com> Date: Thu, 31 Oct 2024 11:18:17 +0530 Subject: [PATCH 09/30] Added the Game Loop. --- Pokemon/Pokemon/Pokemon.cpp | 75 +++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 36 deletions(-) diff --git a/Pokemon/Pokemon/Pokemon.cpp b/Pokemon/Pokemon/Pokemon.cpp index cef7818..0236d45 100644 --- a/Pokemon/Pokemon/Pokemon.cpp +++ b/Pokemon/Pokemon/Pokemon.cpp @@ -204,43 +204,46 @@ void GameLoop(Player &player) { int choice; bool keepPlaying = true; - ClearConsole(); - cout << "\nWhat would you like to do next, " << player.name << "?\n"; - cout << "1. Battle Wild Pokemon\n"; - cout << "2. Visit PokeCenter\n"; - cout << "3. Challenge Gyms\n"; - cout << "4. Enter Pokemon League\n"; - cout << "5. Quit\n"; - cout << "Enter your choice: "; - cin >> choice; - cin.ignore(numeric_limits::max(), '\n'); - switch (choice) + while (keepPlaying) { - 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 Pokemon 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; - }; - WaitForEnter(); + ClearConsole(); + cout << "\nWhat would you like to do next, " << player.name << "?\n"; + cout << "1. Battle Wild Pokemon\n"; + cout << "2. Visit PokeCenter\n"; + cout << "3. Challenge Gyms\n"; + cout << "4. Enter Pokemon League\n"; + cout << "5. Quit\n"; + cout << "Enter your choice: "; + cin >> choice; + cin.ignore(numeric_limits::max(), '\n'); + switch (choice) + { + case 1: + cout << "You look around... but all the wild Pokemon 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 Pokemon 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 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; + }; + WaitForEnter(); + } cout << "Goodbye, " << player.name << "! Thanks for playing!\n"; } From e8c785b7012a7b6203edf763bfaae03fe07b1638 Mon Sep 17 00:00:00 2001 From: rangamach <117797904+rangamach@users.noreply.github.com> Date: Fri, 1 Nov 2024 07:38:21 +0530 Subject: [PATCH 10/30] Added a header file --- Pokemon/Pokemon/Pokemon.cpp | 6 +++--- Pokemon/Pokemon/Pokemon.hpp | 1 + Pokemon/Pokemon/Pokemon.vcxproj | 3 +++ Pokemon/Pokemon/Pokemon.vcxproj.filters | 5 +++++ 4 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 Pokemon/Pokemon/Pokemon.hpp diff --git a/Pokemon/Pokemon/Pokemon.cpp b/Pokemon/Pokemon/Pokemon.cpp index 0236d45..2ce3a89 100644 --- a/Pokemon/Pokemon/Pokemon.cpp +++ b/Pokemon/Pokemon/Pokemon.cpp @@ -1,6 +1,7 @@ #include #include + using namespace std; void WaitForEnter() @@ -249,8 +250,7 @@ void GameLoop(Player &player) int main() { - Pokemon charmander("Charmander", Pokemon_Types::Fire_Type, 100); // Using parameterized constructor - + Pokemon charmander("Charmander", Pokemon_Types::Fire_Type, 100); ProfessorOak Oak("Professor Oak"); Player player("Ash", charmander); @@ -262,4 +262,4 @@ int main() Oak.ExplainMainQuest(player); GameLoop(player); -} \ No newline at end of file +#include "Pokemon.hpp" \ No newline at end of file diff --git a/Pokemon/Pokemon/Pokemon.hpp b/Pokemon/Pokemon/Pokemon.hpp new file mode 100644 index 0000000..ff30235 --- /dev/null +++ b/Pokemon/Pokemon/Pokemon.hpp @@ -0,0 +1 @@ +} \ No newline at end of file diff --git a/Pokemon/Pokemon/Pokemon.vcxproj b/Pokemon/Pokemon/Pokemon.vcxproj index 3cb6302..c93a84f 100644 --- a/Pokemon/Pokemon/Pokemon.vcxproj +++ b/Pokemon/Pokemon/Pokemon.vcxproj @@ -129,6 +129,9 @@ + + + diff --git a/Pokemon/Pokemon/Pokemon.vcxproj.filters b/Pokemon/Pokemon/Pokemon.vcxproj.filters index 8e148e6..c183e1a 100644 --- a/Pokemon/Pokemon/Pokemon.vcxproj.filters +++ b/Pokemon/Pokemon/Pokemon.vcxproj.filters @@ -19,4 +19,9 @@ Source Files + + + Header Files + + \ No newline at end of file From 05c270a52f2d000400b08bfd2d3b38850a4e86bd Mon Sep 17 00:00:00 2001 From: rangamach <117797904+rangamach@users.noreply.github.com> Date: Fri, 1 Nov 2024 07:49:10 +0530 Subject: [PATCH 11/30] Added Pokemon Type and Choice Headers. --- Pokemon/Pokemon/Pokemon.cpp | 35 +++---------------------------- Pokemon/Pokemon/Pokemon.hpp | 1 - Pokemon/Pokemon/PokemonChoice.hpp | 7 +++++++ Pokemon/Pokemon/PokemonType.hpp | 0 4 files changed, 10 insertions(+), 33 deletions(-) delete mode 100644 Pokemon/Pokemon/Pokemon.hpp create mode 100644 Pokemon/Pokemon/PokemonChoice.hpp create mode 100644 Pokemon/Pokemon/PokemonType.hpp diff --git a/Pokemon/Pokemon/Pokemon.cpp b/Pokemon/Pokemon/Pokemon.cpp index 2ce3a89..f0b5670 100644 --- a/Pokemon/Pokemon/Pokemon.cpp +++ b/Pokemon/Pokemon/Pokemon.cpp @@ -1,5 +1,7 @@ #include #include +#include "PokemonType.hpp" +#include "PokemonChoice.hpp" using namespace std; @@ -14,37 +16,6 @@ void ClearConsole() system("cls"); } -//Enum Classes -enum class Pokemon_Choice -{ - Charmander = 1, - Bulbasaur, - Squirtle, - Pikachu -}; - -enum class Pokemon_Types -{ - Normal_Type, - Fire_Type, - Water_Type, - Electric_Type, - Grass_Type, - Ice_Type, - Fighting_Type, - Poison_Type, - Ground_Type, - Flying_Type, - Psychic_Type, - Bug_Type, - Rock_Type, - Ghost_Type, - Dragon_Type, - Dark_Type, - Steel_Type, - Fairy_Type -}; - //Classes class Pokemon { @@ -262,4 +233,4 @@ int main() Oak.ExplainMainQuest(player); GameLoop(player); -#include "Pokemon.hpp" \ No newline at end of file +} \ No newline at end of file diff --git a/Pokemon/Pokemon/Pokemon.hpp b/Pokemon/Pokemon/Pokemon.hpp deleted file mode 100644 index ff30235..0000000 --- a/Pokemon/Pokemon/Pokemon.hpp +++ /dev/null @@ -1 +0,0 @@ -} \ No newline at end of file diff --git a/Pokemon/Pokemon/PokemonChoice.hpp b/Pokemon/Pokemon/PokemonChoice.hpp new file mode 100644 index 0000000..c5bdc99 --- /dev/null +++ b/Pokemon/Pokemon/PokemonChoice.hpp @@ -0,0 +1,7 @@ +enum class Pokemon_Choice +{ + Charmander = 1, + Bulbasaur, + Squirtle, + Pikachu +}; \ No newline at end of file diff --git a/Pokemon/Pokemon/PokemonType.hpp b/Pokemon/Pokemon/PokemonType.hpp new file mode 100644 index 0000000..e69de29 From 66ab9c27d1a494808482ad94345bf7dc20046daa Mon Sep 17 00:00:00 2001 From: rangamach <117797904+rangamach@users.noreply.github.com> Date: Fri, 1 Nov 2024 08:35:57 +0530 Subject: [PATCH 12/30] Added Utility Class. --- Pokemon/Pokemon/Pokemon.cpp | 67 +++++++++++-------------- Pokemon/Pokemon/Pokemon.vcxproj | 4 ++ Pokemon/Pokemon/Pokemon.vcxproj.filters | 12 +++++ Pokemon/Pokemon/PokemonType.hpp | 21 ++++++++ Pokemon/Pokemon/Utility.cpp | 19 +++++++ Pokemon/Pokemon/Utility.hpp | 7 +++ 6 files changed, 92 insertions(+), 38 deletions(-) create mode 100644 Pokemon/Pokemon/Utility.cpp create mode 100644 Pokemon/Pokemon/Utility.hpp diff --git a/Pokemon/Pokemon/Pokemon.cpp b/Pokemon/Pokemon/Pokemon.cpp index f0b5670..aa551ec 100644 --- a/Pokemon/Pokemon/Pokemon.cpp +++ b/Pokemon/Pokemon/Pokemon.cpp @@ -2,20 +2,11 @@ #include #include "PokemonType.hpp" #include "PokemonChoice.hpp" +#include "Utility.hpp" using namespace std; -void WaitForEnter() -{ - cin.get(); -} - -void ClearConsole() -{ - system("cls"); -} - //Classes class Pokemon { @@ -100,11 +91,11 @@ class ProfessorOak void GreetPlayer(Player& player) { cout << name << ": Welcome to the world of Pokemon! I am Professor Oak.\n"; - WaitForEnter(); + Utility::WaitForEnter(); cout << name << ": 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(); } ProfessorOak(string prof_name) @@ -117,15 +108,15 @@ class ProfessorOak cout << name << ": First, tell me what is your name?\n"; 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 will need a Pokemon of your own!\n"; - WaitForEnter(); + Utility::WaitForEnter(); } void FirstPokemon(Player& player) { int choice; cout << name << ": I have three Pokemon here with me. They are all quite feisty!\n"; - WaitForEnter(); + Utility::WaitForEnter(); cout << name << ": Choose wisely...\n"; cout << name << ": 1. Charmander - The fire type. A real hothead!\n"; cout << name << ": 2. Bulbasaur - The grass type. Calm and collected!\n"; @@ -136,39 +127,39 @@ class ProfessorOak player.ChosenPokemon(choice); cout << "Professor Oak: " << player.captured_pokemon.name << " and you, " << player.name << ", are going to be the best of friends!\n"; - WaitForEnter(); - WaitForEnter(); + Utility::WaitForEnter(); + Utility::WaitForEnter(); } void ExplainMainQuest(Player player) { - ClearConsole(); + Utility::ClearConsole(); cout << name << ": Ok, " << player.name << ", I am about to explain you about your upcoming grand adventure.\n"; - WaitForEnter(); + Utility::WaitForEnter(); cout << name << ": You see, becoming a Pokemon Master is no easy feat, it takes courage, wisdom, and a bit of luck.\n"; - WaitForEnter(); + Utility::WaitForEnter(); cout << name << ": Your mission, should you choose to accept it (and trust me, you really don’t have a choice) is to collect all the Pokemon Badges and conquer the Pokemon League. \n"; - WaitForEnter(); + Utility::WaitForEnter(); cout << player.name << ": Wait... that sounds a lot like every other Pokemon game out there.\n"; - WaitForEnter(); + Utility::WaitForEnter(); cout << name << ": Shhh! Don't break the fourth wall " << player.name << "! This is serious business.\n"; - WaitForEnter(); - cout << name << ": 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 << name << ": To achieve this, you will need to battle wild Pokemon, challenge gym leaders, and of course, keep your Pokemon healthy at the PokeCenter.\n"; + Utility::WaitForEnter(); cout << name << ": Along the way, you'll capture new Pokemon 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 << player.name << ": Sounds like a walk in the park... right?\n"; - WaitForEnter(); + Utility::WaitForEnter(); cout << name << ": 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 << name << ": So, what do you say? Are you ready to become the next Pokemon Champion?\n"; - WaitForEnter(); + Utility::WaitForEnter(); cout << player.name << ": Ready as I will ever be, Professor!\n"; - WaitForEnter(); - cout << name << ": That’s the spirit! Now, your journey begins.\n"; - WaitForEnter(); + Utility::WaitForEnter(); + cout << name << ": That is the spirit! Now, your journey begins.\n"; + Utility::WaitForEnter(); cout << name << ": But first... let's just pretend I didn't forget to set up the actual game loop... Ahem, onwards!\n"; - WaitForEnter(); + Utility::WaitForEnter(); } }; @@ -178,7 +169,7 @@ void GameLoop(Player &player) bool keepPlaying = true; while (keepPlaying) { - ClearConsole(); + Utility::ClearConsole(); cout << "\nWhat would you like to do next, " << player.name << "?\n"; cout << "1. Battle Wild Pokemon\n"; cout << "2. Visit PokeCenter\n"; @@ -187,7 +178,7 @@ void GameLoop(Player &player) cout << "5. Quit\n"; cout << "Enter your choice: "; cin >> choice; - cin.ignore(numeric_limits::max(), '\n'); + Utility::ClearInputBuffer(); switch (choice) { case 1: @@ -200,7 +191,7 @@ void GameLoop(Player &player) 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"; + cout << "You boldly step towards the Pokemon 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 Pokemon training!'\n"; @@ -214,7 +205,7 @@ void GameLoop(Player &player) cout << "That's not a valid choice. Try again!\n"; break; }; - WaitForEnter(); + Utility::WaitForEnter(); } cout << "Goodbye, " << player.name << "! Thanks for playing!\n"; } diff --git a/Pokemon/Pokemon/Pokemon.vcxproj b/Pokemon/Pokemon/Pokemon.vcxproj index c93a84f..d64af27 100644 --- a/Pokemon/Pokemon/Pokemon.vcxproj +++ b/Pokemon/Pokemon/Pokemon.vcxproj @@ -128,9 +128,13 @@ + + + + diff --git a/Pokemon/Pokemon/Pokemon.vcxproj.filters b/Pokemon/Pokemon/Pokemon.vcxproj.filters index c183e1a..3e90547 100644 --- a/Pokemon/Pokemon/Pokemon.vcxproj.filters +++ b/Pokemon/Pokemon/Pokemon.vcxproj.filters @@ -18,10 +18,22 @@ Source Files + + Source Files + Header Files + + Header Files + + + Header Files + + + Header Files + \ No newline at end of file diff --git a/Pokemon/Pokemon/PokemonType.hpp b/Pokemon/Pokemon/PokemonType.hpp index e69de29..48fa71c 100644 --- a/Pokemon/Pokemon/PokemonType.hpp +++ b/Pokemon/Pokemon/PokemonType.hpp @@ -0,0 +1,21 @@ +enum class Pokemon_Types +{ + Normal_Type, + Fire_Type, + Water_Type, + Electric_Type, + Grass_Type, + Ice_Type, + Fighting_Type, + Poison_Type, + Ground_Type, + Flying_Type, + Psychic_Type, + Bug_Type, + Rock_Type, + Ghost_Type, + Dragon_Type, + Dark_Type, + Steel_Type, + Fairy_Type +}; \ No newline at end of file diff --git a/Pokemon/Pokemon/Utility.cpp b/Pokemon/Pokemon/Utility.cpp new file mode 100644 index 0000000..309f587 --- /dev/null +++ b/Pokemon/Pokemon/Utility.cpp @@ -0,0 +1,19 @@ +#include "Utility.hpp" +#include + +using namespace std; + +void Utility::WaitForEnter() +{ + cin.get(); +} + +void Utility::ClearConsole() +{ + system("cls"); +} + +void Utility::ClearInputBuffer() +{ + cin.ignore(numeric_limits::max(), '\n'); +} \ No newline at end of file diff --git a/Pokemon/Pokemon/Utility.hpp b/Pokemon/Pokemon/Utility.hpp new file mode 100644 index 0000000..c6a467c --- /dev/null +++ b/Pokemon/Pokemon/Utility.hpp @@ -0,0 +1,7 @@ +class Utility +{ + public: + static void WaitForEnter(); + static void ClearConsole(); + static void ClearInputBuffer(); +}; \ No newline at end of file From 1e29a3d38ba2f9c143bb1908f4be6236799fad79 Mon Sep 17 00:00:00 2001 From: rangamach <117797904+rangamach@users.noreply.github.com> Date: Fri, 1 Nov 2024 09:00:36 +0530 Subject: [PATCH 13/30] Added Player seperate header and cpp file --- Pokemon/Pokemon/Player.cpp | 0 Pokemon/Pokemon/Player.hpp | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 Pokemon/Pokemon/Player.cpp create mode 100644 Pokemon/Pokemon/Player.hpp diff --git a/Pokemon/Pokemon/Player.cpp b/Pokemon/Pokemon/Player.cpp new file mode 100644 index 0000000..e69de29 diff --git a/Pokemon/Pokemon/Player.hpp b/Pokemon/Pokemon/Player.hpp new file mode 100644 index 0000000..e69de29 From 2013102c186d73efa76e8c81a0405e557fc3948b Mon Sep 17 00:00:00 2001 From: rangamach <117797904+rangamach@users.noreply.github.com> Date: Fri, 1 Nov 2024 13:01:51 +0530 Subject: [PATCH 14/30] Added Pokemons seperate cpp and header files. --- Pokemon/Pokemon/Player.cpp | 35 ++++++ Pokemon/Pokemon/Player.hpp | 22 ++++ Pokemon/Pokemon/Pokemon.cpp | 160 ++++++++++++------------ Pokemon/Pokemon/Pokemon.vcxproj | 4 + Pokemon/Pokemon/Pokemon.vcxproj.filters | 12 ++ Pokemon/Pokemon/PokemonChoice.hpp | 2 + Pokemon/Pokemon/PokemonType.hpp | 2 + Pokemon/Pokemon/Pokemons.cpp | 36 ++++++ Pokemon/Pokemon/Pokemons.h | 0 Pokemon/Pokemon/Pokemons.hpp | 20 +++ Pokemon/Pokemon/Utility.hpp | 2 + 11 files changed, 215 insertions(+), 80 deletions(-) create mode 100644 Pokemon/Pokemon/Pokemons.cpp create mode 100644 Pokemon/Pokemon/Pokemons.h create mode 100644 Pokemon/Pokemon/Pokemons.hpp diff --git a/Pokemon/Pokemon/Player.cpp b/Pokemon/Pokemon/Player.cpp index e69de29..ebef4de 100644 --- a/Pokemon/Pokemon/Player.cpp +++ b/Pokemon/Pokemon/Player.cpp @@ -0,0 +1,35 @@ +#include "Player.hpp" +#include + +using namespace std; + +Player::Player() +{ + Player::captured_pokemon = Pokemons(); +} + +Player::Player(string playerName, Pokemons playerCapturedPokemon) +{ + Player::name = playerName; + Player::captured_pokemon = playerCapturedPokemon; +} +void Player::ChosenPokemon(int choice) +{ + switch ((Pokemon_Choice)choice) + { + case Pokemon_Choice::Charmander: + Player::captured_pokemon = Pokemons("Charmander", Pokemon_Types::Fire_Type, 100); + break; + case Pokemon_Choice::Bulbasaur: + Player::captured_pokemon = Pokemons("Bulbasaur", Pokemon_Types::Grass_Type, 100); + break; + case Pokemon_Choice::Squirtle: + Player::captured_pokemon = Pokemons("Squirtle", Pokemon_Types::Water_Type, 100); + break; + default: + Player::captured_pokemon = Pokemons("Pikachu", Pokemon_Types::Electric_Type, 100); + break; + } + cout << name << " chose " << captured_pokemon.name << "\n"; + Utility::WaitForEnter(); +} \ No newline at end of file diff --git a/Pokemon/Pokemon/Player.hpp b/Pokemon/Pokemon/Player.hpp index e69de29..4c1b904 100644 --- a/Pokemon/Pokemon/Player.hpp +++ b/Pokemon/Pokemon/Player.hpp @@ -0,0 +1,22 @@ +#pragma once + +#include + +#include "PokemonType.hpp" +#include "PokemonChoice.hpp" +#include "Utility.hpp" +#include "Pokemons.hpp" + +using namespace std; + +class Player +{ + public: + string name; + Pokemons captured_pokemon; + + Player(); + Player(string playerName, Pokemons playerCapturedPokemon); + void ChosenPokemon(int choice); + +}; \ No newline at end of file diff --git a/Pokemon/Pokemon/Pokemon.cpp b/Pokemon/Pokemon/Pokemon.cpp index aa551ec..3031005 100644 --- a/Pokemon/Pokemon/Pokemon.cpp +++ b/Pokemon/Pokemon/Pokemon.cpp @@ -3,86 +3,87 @@ #include "PokemonType.hpp" #include "PokemonChoice.hpp" #include "Utility.hpp" - +#include "Pokemons.hpp" +#include "Player.hpp" using namespace std; //Classes -class Pokemon -{ -public: - string name; - Pokemon_Types type; - int health; - - Pokemon() - { - name = "Unknown"; - type = Pokemon_Types::Normal_Type; - health = 50; - } - - Pokemon(string poke_name, Pokemon_Types poke_type, int poke_health) - { - name = poke_name; - type = poke_type; - health = poke_health; - } - - Pokemon(const Pokemon &other) - { - name = other.name; - type = other.type; - health = other.health; - } - - ~Pokemon() - { - - } - - void Attack() - { - cout << name << " attacks with a powerful move!\n"; - } -}; - -class Player -{ - public: - string name; - Pokemon captured_pokemon; - - Player() - { - captured_pokemon = Pokemon(); - } - - Player(string playerName, Pokemon playerCapturedPokemon) - { - name = playerName; - captured_pokemon = playerCapturedPokemon; - } - void ChosenPokemon(int choice) - { - switch ((Pokemon_Choice)choice) - { - case Pokemon_Choice::Charmander: - captured_pokemon = Pokemon("Charmander", Pokemon_Types::Fire_Type, 100); - break; - case Pokemon_Choice::Bulbasaur: - captured_pokemon = Pokemon("Bulbasaur", Pokemon_Types::Grass_Type, 100); - break; - case Pokemon_Choice::Squirtle: - captured_pokemon = Pokemon("Squirtle", Pokemon_Types::Water_Type, 100); - break; - default: - captured_pokemon = Pokemon("Pikachu", Pokemon_Types::Electric_Type, 100); - break; - } - cout << name << " chose " << captured_pokemon.name << "\n"; - } -}; +//class Pokemon +//{ +//public: +// string name; +// Pokemon_Types type; +// int health; +// +// Pokemon() +// { +// name = "Unknown"; +// type = Pokemon_Types::Normal_Type; +// health = 50; +// } +// +// Pokemon(string poke_name, Pokemon_Types poke_type, int poke_health) +// { +// name = poke_name; +// type = poke_type; +// health = poke_health; +// } +// +// Pokemon(const Pokemon &other) +// { +// name = other.name; +// type = other.type; +// health = other.health; +// } +// +// ~Pokemon() +// { +// +// } +// +// void Attack() +// { +// cout << name << " attacks with a powerful move!\n"; +// } +//}; + +//class Player +//{ +// public: +// string name; +// Pokemon captured_pokemon; +// +// Player() +// { +// captured_pokemon = Pokemon(); +// } +// +// Player(string playerName, Pokemon playerCapturedPokemon) +// { +// name = playerName; +// captured_pokemon = playerCapturedPokemon; +// } +// void ChosenPokemon(int choice) +// { +// switch ((Pokemon_Choice)choice) +// { +// case Pokemon_Choice::Charmander: +// captured_pokemon = Pokemon("Charmander", Pokemon_Types::Fire_Type, 100); +// break; +// case Pokemon_Choice::Bulbasaur: +// captured_pokemon = Pokemon("Bulbasaur", Pokemon_Types::Grass_Type, 100); +// break; +// case Pokemon_Choice::Squirtle: +// captured_pokemon = Pokemon("Squirtle", Pokemon_Types::Water_Type, 100); +// break; +// default: +// captured_pokemon = Pokemon("Pikachu", Pokemon_Types::Electric_Type, 100); +// break; +// } +// cout << name << " chose " << captured_pokemon.name << "\n"; +// } +//}; class ProfessorOak { @@ -128,7 +129,6 @@ class ProfessorOak cout << "Professor Oak: " << player.captured_pokemon.name << " and you, " << player.name << ", are going to be the best of friends!\n"; Utility::WaitForEnter(); - Utility::WaitForEnter(); } void ExplainMainQuest(Player player) @@ -138,7 +138,7 @@ class ProfessorOak Utility::WaitForEnter(); cout << name << ": You see, becoming a Pokemon Master is no easy feat, it takes courage, wisdom, and a bit of luck.\n"; Utility::WaitForEnter(); - cout << name << ": Your mission, should you choose to accept it (and trust me, you really don’t have a choice) is to collect all the Pokemon Badges and conquer the Pokemon League. \n"; + cout << name << ": Your mission, should you choose to accept it (and trust me, you really do not have a choice) is to collect all the Pokemon Badges and conquer the Pokemon League. \n"; Utility::WaitForEnter(); cout << player.name << ": Wait... that sounds a lot like every other Pokemon game out there.\n"; Utility::WaitForEnter(); @@ -150,7 +150,7 @@ class ProfessorOak Utility::WaitForEnter(); cout << player.name << ": Sounds like a walk in the park... right?\n"; Utility::WaitForEnter(); - cout << name << ": 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 << name << ": Hah! That is 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 << name << ": So, what do you say? Are you ready to become the next Pokemon Champion?\n"; Utility::WaitForEnter(); @@ -212,7 +212,7 @@ void GameLoop(Player &player) int main() { - Pokemon charmander("Charmander", Pokemon_Types::Fire_Type, 100); + Pokemons charmander("Charmander", Pokemon_Types::Fire_Type, 100); ProfessorOak Oak("Professor Oak"); Player player("Ash", charmander); diff --git a/Pokemon/Pokemon/Pokemon.vcxproj b/Pokemon/Pokemon/Pokemon.vcxproj index d64af27..352eefc 100644 --- a/Pokemon/Pokemon/Pokemon.vcxproj +++ b/Pokemon/Pokemon/Pokemon.vcxproj @@ -127,12 +127,16 @@ + + + + diff --git a/Pokemon/Pokemon/Pokemon.vcxproj.filters b/Pokemon/Pokemon/Pokemon.vcxproj.filters index 3e90547..07d8316 100644 --- a/Pokemon/Pokemon/Pokemon.vcxproj.filters +++ b/Pokemon/Pokemon/Pokemon.vcxproj.filters @@ -21,6 +21,12 @@ Source Files + + Source Files + + + Source Files + @@ -35,5 +41,11 @@ Header Files + + Header Files + + + Header Files + \ No newline at end of file diff --git a/Pokemon/Pokemon/PokemonChoice.hpp b/Pokemon/Pokemon/PokemonChoice.hpp index c5bdc99..0abd64e 100644 --- a/Pokemon/Pokemon/PokemonChoice.hpp +++ b/Pokemon/Pokemon/PokemonChoice.hpp @@ -1,3 +1,5 @@ +#pragma once + enum class Pokemon_Choice { Charmander = 1, diff --git a/Pokemon/Pokemon/PokemonType.hpp b/Pokemon/Pokemon/PokemonType.hpp index 48fa71c..2e8afd0 100644 --- a/Pokemon/Pokemon/PokemonType.hpp +++ b/Pokemon/Pokemon/PokemonType.hpp @@ -1,3 +1,5 @@ +#pragma once + enum class Pokemon_Types { Normal_Type, diff --git a/Pokemon/Pokemon/Pokemons.cpp b/Pokemon/Pokemon/Pokemons.cpp new file mode 100644 index 0000000..26aad55 --- /dev/null +++ b/Pokemon/Pokemon/Pokemons.cpp @@ -0,0 +1,36 @@ +#include +#include "Pokemons.hpp" + +using namespace std; + +Pokemons::Pokemons() +{ + Pokemons::name = "Unknown"; + Pokemons::type = Pokemon_Types::Normal_Type; + Pokemons::health = 50; +} + +Pokemons::Pokemons(string poke_name, Pokemon_Types poke_type, int poke_health) +{ + Pokemons::name = poke_name; + Pokemons::type = poke_type; + Pokemons::health = poke_health; +} + +Pokemons::Pokemons(const Pokemons& other) +{ + Pokemons::name = other.name; + Pokemons::type = other.type; + Pokemons::health = other.health; +} + +Pokemons::~Pokemons() +{ + +} + +void Pokemons::Attack() +{ + cout << name << " attacks with a powerful move!\n"; +} + diff --git a/Pokemon/Pokemon/Pokemons.h b/Pokemon/Pokemon/Pokemons.h new file mode 100644 index 0000000..e69de29 diff --git a/Pokemon/Pokemon/Pokemons.hpp b/Pokemon/Pokemon/Pokemons.hpp new file mode 100644 index 0000000..1560928 --- /dev/null +++ b/Pokemon/Pokemon/Pokemons.hpp @@ -0,0 +1,20 @@ +#pragma once + +#include +#include "PokemonType.hpp" + +using namespace std; + +class Pokemons +{ +public: + string name; + Pokemon_Types type; + int health; + + Pokemons(); + Pokemons(string poke_name, Pokemon_Types poke_type, int poke_health); + Pokemons(const Pokemons& other); + ~Pokemons(); + void Attack(); +}; \ No newline at end of file diff --git a/Pokemon/Pokemon/Utility.hpp b/Pokemon/Pokemon/Utility.hpp index c6a467c..e45b677 100644 --- a/Pokemon/Pokemon/Utility.hpp +++ b/Pokemon/Pokemon/Utility.hpp @@ -1,3 +1,5 @@ +#pragma once + class Utility { public: From 6b6efffcdac757de5cd0fb3cee87f101d8f2656c Mon Sep 17 00:00:00 2001 From: rangamach <117797904+rangamach@users.noreply.github.com> Date: Fri, 1 Nov 2024 13:27:01 +0530 Subject: [PATCH 15/30] Refactored Code. --- Pokemon/Pokemon/Player.cpp | 1 + Pokemon/Pokemon/Pokemon.cpp | 80 +----------------------------------- Pokemon/Pokemon/Pokemons.cpp | 1 + 3 files changed, 3 insertions(+), 79 deletions(-) diff --git a/Pokemon/Pokemon/Player.cpp b/Pokemon/Pokemon/Player.cpp index ebef4de..6a4b7d6 100644 --- a/Pokemon/Pokemon/Player.cpp +++ b/Pokemon/Pokemon/Player.cpp @@ -1,4 +1,5 @@ #include "Player.hpp" +#include "Pokemons.hpp" #include using namespace std; diff --git a/Pokemon/Pokemon/Pokemon.cpp b/Pokemon/Pokemon/Pokemon.cpp index 3031005..3efdc7a 100644 --- a/Pokemon/Pokemon/Pokemon.cpp +++ b/Pokemon/Pokemon/Pokemon.cpp @@ -3,88 +3,10 @@ #include "PokemonType.hpp" #include "PokemonChoice.hpp" #include "Utility.hpp" -#include "Pokemons.hpp" #include "Player.hpp" using namespace std; -//Classes -//class Pokemon -//{ -//public: -// string name; -// Pokemon_Types type; -// int health; -// -// Pokemon() -// { -// name = "Unknown"; -// type = Pokemon_Types::Normal_Type; -// health = 50; -// } -// -// Pokemon(string poke_name, Pokemon_Types poke_type, int poke_health) -// { -// name = poke_name; -// type = poke_type; -// health = poke_health; -// } -// -// Pokemon(const Pokemon &other) -// { -// name = other.name; -// type = other.type; -// health = other.health; -// } -// -// ~Pokemon() -// { -// -// } -// -// void Attack() -// { -// cout << name << " attacks with a powerful move!\n"; -// } -//}; - -//class Player -//{ -// public: -// string name; -// Pokemon captured_pokemon; -// -// Player() -// { -// captured_pokemon = Pokemon(); -// } -// -// Player(string playerName, Pokemon playerCapturedPokemon) -// { -// name = playerName; -// captured_pokemon = playerCapturedPokemon; -// } -// void ChosenPokemon(int choice) -// { -// switch ((Pokemon_Choice)choice) -// { -// case Pokemon_Choice::Charmander: -// captured_pokemon = Pokemon("Charmander", Pokemon_Types::Fire_Type, 100); -// break; -// case Pokemon_Choice::Bulbasaur: -// captured_pokemon = Pokemon("Bulbasaur", Pokemon_Types::Grass_Type, 100); -// break; -// case Pokemon_Choice::Squirtle: -// captured_pokemon = Pokemon("Squirtle", Pokemon_Types::Water_Type, 100); -// break; -// default: -// captured_pokemon = Pokemon("Pikachu", Pokemon_Types::Electric_Type, 100); -// break; -// } -// cout << name << " chose " << captured_pokemon.name << "\n"; -// } -//}; - class ProfessorOak { public: @@ -150,7 +72,7 @@ class ProfessorOak Utility::WaitForEnter(); cout << player.name << ": Sounds like a walk in the park... right?\n"; Utility::WaitForEnter(); - cout << name << ": Hah! That is 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 << name << ": Hah! Thats 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 << name << ": So, what do you say? Are you ready to become the next Pokemon Champion?\n"; Utility::WaitForEnter(); diff --git a/Pokemon/Pokemon/Pokemons.cpp b/Pokemon/Pokemon/Pokemons.cpp index 26aad55..d26d6fe 100644 --- a/Pokemon/Pokemon/Pokemons.cpp +++ b/Pokemon/Pokemon/Pokemons.cpp @@ -1,5 +1,6 @@ #include #include "Pokemons.hpp" +#include "PokemonType.hpp" using namespace std; From 423a130b7fae1fd0c3238f3c4feb58627b8a8119 Mon Sep 17 00:00:00 2001 From: rangamach <117797904+rangamach@users.noreply.github.com> Date: Sat, 2 Nov 2024 09:44:55 +0530 Subject: [PATCH 16/30] Added struct Grass. --- Pokemon/Pokemon/Grass.hpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Pokemon/Pokemon/Grass.hpp diff --git a/Pokemon/Pokemon/Grass.hpp b/Pokemon/Pokemon/Grass.hpp new file mode 100644 index 0000000..fbaedb9 --- /dev/null +++ b/Pokemon/Pokemon/Grass.hpp @@ -0,0 +1,20 @@ +#pragma once + +#include +#include +#include "Pokemons.hpp" + +using namespace std; + +struct Grass +{ + string environment; + vector wild_pokemons_list; + int pokemon_encounter_rate; +}; + +Grass forestGrass = { + "Cave", + {{"Zubat",Pokemon_Types::Poison_Type,30},{"Geodude",Pokemon_Types::Rock_Type,50},{"Caterpie",Pokemon_Types::Bug_Type,10}}, + 80 +}; \ No newline at end of file From 21c46a2ce30fdd3dc48212535f5aec31166eb1ed Mon Sep 17 00:00:00 2001 From: rangamach <117797904+rangamach@users.noreply.github.com> Date: Sat, 2 Nov 2024 11:04:23 +0530 Subject: [PATCH 17/30] Added Wild Pokemon Encounters Implementation. --- Pokemon/Pokemon/Game.cpp | 70 +++++++++++++ Pokemon/Pokemon/Game.hpp | 12 +++ Pokemon/Pokemon/Grass.hpp | 10 +- Pokemon/Pokemon/Pokemon.cpp | 97 ++++++++++--------- Pokemon/Pokemon/Pokemon.vcxproj | 5 + Pokemon/Pokemon/Pokemon.vcxproj.filters | 15 +++ .../Pokemon/WildPokemonEncounterHandler.cpp | 14 +++ .../Pokemon/WildPokemonEncounterHandler.hpp | 9 ++ 8 files changed, 180 insertions(+), 52 deletions(-) create mode 100644 Pokemon/Pokemon/Game.cpp create mode 100644 Pokemon/Pokemon/Game.hpp create mode 100644 Pokemon/Pokemon/WildPokemonEncounterHandler.cpp create mode 100644 Pokemon/Pokemon/WildPokemonEncounterHandler.hpp diff --git a/Pokemon/Pokemon/Game.cpp b/Pokemon/Pokemon/Game.cpp new file mode 100644 index 0000000..6fa84ef --- /dev/null +++ b/Pokemon/Pokemon/Game.cpp @@ -0,0 +1,70 @@ +#include "Game.hpp" +#include "Player.hpp" +#include "PokemonType.hpp" +#include "Utility.hpp" +#include "WildPokemonEncounterHandler.hpp" +#include + +using namespace std; + +Game::Game() +{ + forest_grass = { + "Forest", + {{"Pidgey",Pokemon_Types::Normal_Type,40}, + {"Zubat",Pokemon_Types::Poison_Type,30}, + {"Caterpie",Pokemon_Types::Bug_Type,35}}, + 70 }; +} +void Game::GameLoop(Player& player) +{ + int choice; + bool keepPlaying = true; + while (keepPlaying) + { + Utility::ClearConsole(); + cout << "\nWhat would you like to do next, " << player.name << "?\n"; + cout << "1. Battle Wild Pokemon\n"; + cout << "2. Visit PokeCenter\n"; + cout << "3. Challenge Gyms\n"; + cout << "4. Enter Pokemon League\n"; + cout << "5. Quit\n"; + cout << "Enter your choice: "; + cin >> choice; + Utility::ClearInputBuffer(); + switch (choice) + { + case 1: + { + WildPokemonEncounterHandler encounters; + Pokemons encountered_pokemon = encounters.GetRandomWildPokemonFromGrass(forest_grass); + cout << "A wild " << encountered_pokemon.name << " appeared!\n"; + break; + } + case 2: + cout << "You head to the PokeCenter, but Nurse Joy is out on a coffee break. Guess your Pokemon 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 Pokemon 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 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; + }; + Utility::WaitForEnter(); + } + cout << "Goodbye, " << player.name << "! Thanks for playing!\n"; +} \ No newline at end of file diff --git a/Pokemon/Pokemon/Game.hpp b/Pokemon/Pokemon/Game.hpp new file mode 100644 index 0000000..e01f21b --- /dev/null +++ b/Pokemon/Pokemon/Game.hpp @@ -0,0 +1,12 @@ +#include "Grass.hpp" + +class Player; + +class Game +{ + private: + Grass forest_grass; + public: + Game(); + void GameLoop(Player &player); +}; \ No newline at end of file diff --git a/Pokemon/Pokemon/Grass.hpp b/Pokemon/Pokemon/Grass.hpp index fbaedb9..9a98da9 100644 --- a/Pokemon/Pokemon/Grass.hpp +++ b/Pokemon/Pokemon/Grass.hpp @@ -13,8 +13,8 @@ struct Grass int pokemon_encounter_rate; }; -Grass forestGrass = { - "Cave", - {{"Zubat",Pokemon_Types::Poison_Type,30},{"Geodude",Pokemon_Types::Rock_Type,50},{"Caterpie",Pokemon_Types::Bug_Type,10}}, - 80 -}; \ No newline at end of file +//Grass forestGrass = { +// "Cave", +// {{"Zubat",Pokemon_Types::Poison_Type,30},{"Geodude",Pokemon_Types::Rock_Type,50},{"Caterpie",Pokemon_Types::Bug_Type,10}}, +// 80 +//}; \ No newline at end of file diff --git a/Pokemon/Pokemon/Pokemon.cpp b/Pokemon/Pokemon/Pokemon.cpp index 3efdc7a..33110d0 100644 --- a/Pokemon/Pokemon/Pokemon.cpp +++ b/Pokemon/Pokemon/Pokemon.cpp @@ -4,6 +4,7 @@ #include "PokemonChoice.hpp" #include "Utility.hpp" #include "Player.hpp" +#include "Game.hpp" using namespace std; @@ -85,55 +86,57 @@ class ProfessorOak } }; -void GameLoop(Player &player) -{ - int choice; - bool keepPlaying = true; - while (keepPlaying) - { - Utility::ClearConsole(); - cout << "\nWhat would you like to do next, " << player.name << "?\n"; - cout << "1. Battle Wild Pokemon\n"; - cout << "2. Visit PokeCenter\n"; - cout << "3. Challenge Gyms\n"; - cout << "4. Enter Pokemon League\n"; - cout << "5. Quit\n"; - cout << "Enter your choice: "; - cin >> choice; - Utility::ClearInputBuffer(); - switch (choice) - { - case 1: - cout << "You look around... but all the wild Pokemon 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 Pokemon 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 Pokemon 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 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; - }; - Utility::WaitForEnter(); - } - cout << "Goodbye, " << player.name << "! Thanks for playing!\n"; -} +//void GameLoop(Player &player) +//{ +// int choice; +// bool keepPlaying = true; +// while (keepPlaying) +// { +// Utility::ClearConsole(); +// cout << "\nWhat would you like to do next, " << player.name << "?\n"; +// cout << "1. Battle Wild Pokemon\n"; +// cout << "2. Visit PokeCenter\n"; +// cout << "3. Challenge Gyms\n"; +// cout << "4. Enter Pokemon League\n"; +// cout << "5. Quit\n"; +// cout << "Enter your choice: "; +// cin >> choice; +// Utility::ClearInputBuffer(); +// switch (choice) +// { +// case 1: +// cout << "You look around... but all the wild Pokemon 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 Pokemon 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 Pokemon 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 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; +// }; +// Utility::WaitForEnter(); +// } +// cout << "Goodbye, " << player.name << "! Thanks for playing!\n"; +//} int main() { + Game loop; + Pokemons charmander("Charmander", Pokemon_Types::Fire_Type, 100); ProfessorOak Oak("Professor Oak"); @@ -145,5 +148,5 @@ int main() Oak.ExplainMainQuest(player); - GameLoop(player); + loop.GameLoop(player); } \ No newline at end of file diff --git a/Pokemon/Pokemon/Pokemon.vcxproj b/Pokemon/Pokemon/Pokemon.vcxproj index 352eefc..87d6068 100644 --- a/Pokemon/Pokemon/Pokemon.vcxproj +++ b/Pokemon/Pokemon/Pokemon.vcxproj @@ -127,18 +127,23 @@ + + + + + diff --git a/Pokemon/Pokemon/Pokemon.vcxproj.filters b/Pokemon/Pokemon/Pokemon.vcxproj.filters index 07d8316..0e7b6ac 100644 --- a/Pokemon/Pokemon/Pokemon.vcxproj.filters +++ b/Pokemon/Pokemon/Pokemon.vcxproj.filters @@ -27,6 +27,12 @@ Source Files + + Source Files + + + Source Files + @@ -47,5 +53,14 @@ Header Files + + Header Files + + + Header Files + + + Header Files + \ No newline at end of file diff --git a/Pokemon/Pokemon/WildPokemonEncounterHandler.cpp b/Pokemon/Pokemon/WildPokemonEncounterHandler.cpp new file mode 100644 index 0000000..d508697 --- /dev/null +++ b/Pokemon/Pokemon/WildPokemonEncounterHandler.cpp @@ -0,0 +1,14 @@ +#include "WildPokemonEncounterHandler.hpp" +#include +#include + +WildPokemonEncounterHandler::WildPokemonEncounterHandler() +{ + srand(time(0)); +} + +Pokemons WildPokemonEncounterHandler::GetRandomWildPokemonFromGrass(const Grass& grass) +{ + int random_index = rand() % grass.wild_pokemons_list.size(); + return grass.wild_pokemons_list[random_index]; +} diff --git a/Pokemon/Pokemon/WildPokemonEncounterHandler.hpp b/Pokemon/Pokemon/WildPokemonEncounterHandler.hpp new file mode 100644 index 0000000..4bee1e9 --- /dev/null +++ b/Pokemon/Pokemon/WildPokemonEncounterHandler.hpp @@ -0,0 +1,9 @@ +#include "Grass.hpp" +#include + +class WildPokemonEncounterHandler +{ +public: + WildPokemonEncounterHandler(); + Pokemons GetRandomWildPokemonFromGrass(const Grass& grass); +}; \ No newline at end of file From 665c83ab9238b07e26e76dd499570a02ddcff72a Mon Sep 17 00:00:00 2001 From: rangamach <117797904+rangamach@users.noreply.github.com> Date: Sat, 2 Nov 2024 12:00:03 +0530 Subject: [PATCH 18/30] Implemented a battle loop. --- Pokemon/Pokemon/Game.cpp | 2 +- Pokemon/Pokemon/Pokemons.cpp | 33 +++++++++++++++++++++++++++++++-- Pokemon/Pokemon/Pokemons.hpp | 6 +++++- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/Pokemon/Pokemon/Game.cpp b/Pokemon/Pokemon/Game.cpp index 6fa84ef..96a8cd3 100644 --- a/Pokemon/Pokemon/Game.cpp +++ b/Pokemon/Pokemon/Game.cpp @@ -38,7 +38,7 @@ void Game::GameLoop(Player& player) { WildPokemonEncounterHandler encounters; Pokemons encountered_pokemon = encounters.GetRandomWildPokemonFromGrass(forest_grass); - cout << "A wild " << encountered_pokemon.name << " appeared!\n"; + encountered_pokemon.Battle(player.captured_pokemon, encountered_pokemon); break; } case 2: diff --git a/Pokemon/Pokemon/Pokemons.cpp b/Pokemon/Pokemon/Pokemons.cpp index d26d6fe..c12f083 100644 --- a/Pokemon/Pokemon/Pokemons.cpp +++ b/Pokemon/Pokemon/Pokemons.cpp @@ -30,8 +30,37 @@ Pokemons::~Pokemons() } -void Pokemons::Attack() +void Pokemons::Attack(Pokemons &target_pokemon) { - cout << name << " attacks with a powerful move!\n"; + int damage = 10; + cout << name << " inflicts an attack to " << target_pokemon.name << " that does " << damage << " damage!\n"; + target_pokemon.TakeDamage(damage); +} + +void Pokemons::TakeDamage(int damage) +{ + health -= damage; + if (health < 0) + health = 0; +} + +bool Pokemons::IsFainted() const +{ + return health <= 0; +} + +void Pokemons::Battle(Pokemons& player_pokemon, Pokemons& wild_pokemon) +{ + cout << "A wild " << wild_pokemon.name << " appeared!\n"; + while (!player_pokemon.IsFainted() && !wild_pokemon.IsFainted()) + { + player_pokemon.Attack(wild_pokemon); + if (!wild_pokemon.IsFainted()) + wild_pokemon.Attack(player_pokemon); + if (player_pokemon.IsFainted()) + cout << player_pokemon.name << " has fainted! You lose the battle.\n"; + else if(wild_pokemon.IsFainted()) + cout << wild_pokemon.name << " has fainted! You win the battle.\n"; + } } diff --git a/Pokemon/Pokemon/Pokemons.hpp b/Pokemon/Pokemon/Pokemons.hpp index 1560928..6beedc4 100644 --- a/Pokemon/Pokemon/Pokemons.hpp +++ b/Pokemon/Pokemon/Pokemons.hpp @@ -11,10 +11,14 @@ class Pokemons string name; Pokemon_Types type; int health; + int max_health; Pokemons(); Pokemons(string poke_name, Pokemon_Types poke_type, int poke_health); Pokemons(const Pokemons& other); ~Pokemons(); - void Attack(); + void Attack(Pokemons &target_pokemon); + void TakeDamage(int damage); + bool IsFainted() const; + void Battle(Pokemons &player_pokemon, Pokemons &wild_pokemon); }; \ No newline at end of file From 99b08593b910bfb62344c85e76a9af551790b284 Mon Sep 17 00:00:00 2001 From: rangamach <117797904+rangamach@users.noreply.github.com> Date: Sat, 2 Nov 2024 12:17:07 +0530 Subject: [PATCH 19/30] Added attack power and heal mechanism. --- Pokemon/Pokemon/Game.cpp | 11 +++++++---- Pokemon/Pokemon/Player.cpp | 8 ++++---- Pokemon/Pokemon/Pokemon.cpp | 2 +- Pokemon/Pokemon/Pokemons.cpp | 11 +++++++++-- Pokemon/Pokemon/Pokemons.hpp | 4 +++- 5 files changed, 24 insertions(+), 12 deletions(-) diff --git a/Pokemon/Pokemon/Game.cpp b/Pokemon/Pokemon/Game.cpp index 96a8cd3..d3c7ee0 100644 --- a/Pokemon/Pokemon/Game.cpp +++ b/Pokemon/Pokemon/Game.cpp @@ -11,9 +11,9 @@ Game::Game() { forest_grass = { "Forest", - {{"Pidgey",Pokemon_Types::Normal_Type,40}, - {"Zubat",Pokemon_Types::Poison_Type,30}, - {"Caterpie",Pokemon_Types::Bug_Type,35}}, + {{"Pidgey",Pokemon_Types::Normal_Type,40,2}, + {"Zubat",Pokemon_Types::Poison_Type,30,10}, + {"Caterpie",Pokemon_Types::Bug_Type,35,5}}, 70 }; } void Game::GameLoop(Player& player) @@ -42,8 +42,11 @@ 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 Pokemon will have to tough it out for now!\n"; + { + player.captured_pokemon.Heal(); + cout << player.captured_pokemon.name << "'s health is fully restored."; 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; diff --git a/Pokemon/Pokemon/Player.cpp b/Pokemon/Pokemon/Player.cpp index 6a4b7d6..a8c4812 100644 --- a/Pokemon/Pokemon/Player.cpp +++ b/Pokemon/Pokemon/Player.cpp @@ -19,16 +19,16 @@ void Player::ChosenPokemon(int choice) switch ((Pokemon_Choice)choice) { case Pokemon_Choice::Charmander: - Player::captured_pokemon = Pokemons("Charmander", Pokemon_Types::Fire_Type, 100); + Player::captured_pokemon = Pokemons("Charmander", Pokemon_Types::Fire_Type, 100, 20); break; case Pokemon_Choice::Bulbasaur: - Player::captured_pokemon = Pokemons("Bulbasaur", Pokemon_Types::Grass_Type, 100); + Player::captured_pokemon = Pokemons("Bulbasaur", Pokemon_Types::Grass_Type, 100, 10); break; case Pokemon_Choice::Squirtle: - Player::captured_pokemon = Pokemons("Squirtle", Pokemon_Types::Water_Type, 100); + Player::captured_pokemon = Pokemons("Squirtle", Pokemon_Types::Water_Type, 100, 15); break; default: - Player::captured_pokemon = Pokemons("Pikachu", Pokemon_Types::Electric_Type, 100); + Player::captured_pokemon = Pokemons("Pikachu", Pokemon_Types::Electric_Type, 100, 20); break; } cout << name << " chose " << captured_pokemon.name << "\n"; diff --git a/Pokemon/Pokemon/Pokemon.cpp b/Pokemon/Pokemon/Pokemon.cpp index 33110d0..83523f2 100644 --- a/Pokemon/Pokemon/Pokemon.cpp +++ b/Pokemon/Pokemon/Pokemon.cpp @@ -137,7 +137,7 @@ int main() { Game loop; - Pokemons charmander("Charmander", Pokemon_Types::Fire_Type, 100); + Pokemons charmander("Charmander", Pokemon_Types::Fire_Type, 100, 15); ProfessorOak Oak("Professor Oak"); Player player("Ash", charmander); diff --git a/Pokemon/Pokemon/Pokemons.cpp b/Pokemon/Pokemon/Pokemons.cpp index c12f083..1a08d93 100644 --- a/Pokemon/Pokemon/Pokemons.cpp +++ b/Pokemon/Pokemon/Pokemons.cpp @@ -11,11 +11,12 @@ Pokemons::Pokemons() Pokemons::health = 50; } -Pokemons::Pokemons(string poke_name, Pokemon_Types poke_type, int poke_health) +Pokemons::Pokemons(string poke_name, Pokemon_Types poke_type, int poke_health, int poke_attack_power) { Pokemons::name = poke_name; Pokemons::type = poke_type; Pokemons::health = poke_health; + Pokemons::attack_power = poke_attack_power; } Pokemons::Pokemons(const Pokemons& other) @@ -23,6 +24,7 @@ Pokemons::Pokemons(const Pokemons& other) Pokemons::name = other.name; Pokemons::type = other.type; Pokemons::health = other.health; + Pokemons::attack_power = other.attack_power; } Pokemons::~Pokemons() @@ -32,7 +34,7 @@ Pokemons::~Pokemons() void Pokemons::Attack(Pokemons &target_pokemon) { - int damage = 10; + int damage = attack_power; cout << name << " inflicts an attack to " << target_pokemon.name << " that does " << damage << " damage!\n"; target_pokemon.TakeDamage(damage); } @@ -64,3 +66,8 @@ void Pokemons::Battle(Pokemons& player_pokemon, Pokemons& wild_pokemon) } } +void Pokemons::Heal() +{ + health = max_health; +} + diff --git a/Pokemon/Pokemon/Pokemons.hpp b/Pokemon/Pokemon/Pokemons.hpp index 6beedc4..b5893ad 100644 --- a/Pokemon/Pokemon/Pokemons.hpp +++ b/Pokemon/Pokemon/Pokemons.hpp @@ -12,13 +12,15 @@ class Pokemons Pokemon_Types type; int health; int max_health; + int attack_power; Pokemons(); - Pokemons(string poke_name, Pokemon_Types poke_type, int poke_health); + Pokemons(string poke_name, Pokemon_Types poke_type, int poke_health, int poke_attack_power); Pokemons(const Pokemons& other); ~Pokemons(); void Attack(Pokemons &target_pokemon); void TakeDamage(int damage); bool IsFainted() const; void Battle(Pokemons &player_pokemon, Pokemons &wild_pokemon); + void Heal(); }; \ No newline at end of file From 95471e294584380bdbeb63f9c7de1f99d2217eb7 Mon Sep 17 00:00:00 2001 From: rangamach <117797904+rangamach@users.noreply.github.com> Date: Sat, 2 Nov 2024 13:17:57 +0530 Subject: [PATCH 20/30] Almost perfected battle loop. --- Pokemon/Pokemon/BattleManager.cpp | 32 +++++++++++++++++++++++++ Pokemon/Pokemon/BattleManager.hpp | 11 +++++++++ Pokemon/Pokemon/Game.cpp | 6 ++++- Pokemon/Pokemon/Pokemon.vcxproj | 2 ++ Pokemon/Pokemon/Pokemon.vcxproj.filters | 6 +++++ Pokemon/Pokemon/Pokemons.cpp | 6 ++--- 6 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 Pokemon/Pokemon/BattleManager.cpp create mode 100644 Pokemon/Pokemon/BattleManager.hpp diff --git a/Pokemon/Pokemon/BattleManager.cpp b/Pokemon/Pokemon/BattleManager.cpp new file mode 100644 index 0000000..4c93041 --- /dev/null +++ b/Pokemon/Pokemon/BattleManager.cpp @@ -0,0 +1,32 @@ +#include "BattleManager.hpp" +#include "Pokemons.hpp" +#include "Player.hpp" +#include + +using namespace std; + +void BattleManager::StartBattle(Player &player, Pokemons &wild_pokemon) +{ + cout << "A wild " << wild_pokemon.name << " appeared!\n"; + Battle(player.captured_pokemon, wild_pokemon); +} + +void BattleManager::Battle(Pokemons& player_pokemon, Pokemons& wild_pokemon) +{ + while (!player_pokemon.IsFainted() && !wild_pokemon.IsFainted()) + { + player_pokemon.Attack(wild_pokemon); + if (!wild_pokemon.IsFainted()) + wild_pokemon.Attack(player_pokemon); + Utility::WaitForEnter(); + } + BattleOutcome(player_pokemon,player_pokemon.IsFainted()); +} + +void BattleManager::BattleOutcome(Pokemons &player_pokemon, bool playerWon) +{ + if(playerWon) + cout << player_pokemon.name << " is victorious! Keep an eye on your Pokémon's health.\n"; + else + cout << "Oh no! " << player_pokemon.name << " fainted! You need to visit the PokeCenter.\n"; +} \ No newline at end of file diff --git a/Pokemon/Pokemon/BattleManager.hpp b/Pokemon/Pokemon/BattleManager.hpp new file mode 100644 index 0000000..debe4af --- /dev/null +++ b/Pokemon/Pokemon/BattleManager.hpp @@ -0,0 +1,11 @@ +class Player; +class Pokemons; + +class BattleManager +{ + public: + void StartBattle(Player &player, Pokemons &wild_pokemon); + private: + void Battle(Pokemons &player_pokemon, Pokemons &wild_pokemon); + void BattleOutcome(Pokemons &player_pokemon, bool playerWon); +}; \ No newline at end of file diff --git a/Pokemon/Pokemon/Game.cpp b/Pokemon/Pokemon/Game.cpp index d3c7ee0..bc7db8a 100644 --- a/Pokemon/Pokemon/Game.cpp +++ b/Pokemon/Pokemon/Game.cpp @@ -3,8 +3,10 @@ #include "PokemonType.hpp" #include "Utility.hpp" #include "WildPokemonEncounterHandler.hpp" +#include "BattleManager.hpp" #include + using namespace std; Game::Game() @@ -18,6 +20,7 @@ Game::Game() } void Game::GameLoop(Player& player) { + BattleManager battle_manager; int choice; bool keepPlaying = true; while (keepPlaying) @@ -38,7 +41,8 @@ void Game::GameLoop(Player& player) { WildPokemonEncounterHandler encounters; Pokemons encountered_pokemon = encounters.GetRandomWildPokemonFromGrass(forest_grass); - encountered_pokemon.Battle(player.captured_pokemon, encountered_pokemon); + //encountered_pokemon.Battle(player.captured_pokemon, encountered_pokemon); + battle_manager.StartBattle(player,encountered_pokemon); break; } case 2: diff --git a/Pokemon/Pokemon/Pokemon.vcxproj b/Pokemon/Pokemon/Pokemon.vcxproj index 87d6068..b1d9966 100644 --- a/Pokemon/Pokemon/Pokemon.vcxproj +++ b/Pokemon/Pokemon/Pokemon.vcxproj @@ -127,6 +127,7 @@ + @@ -135,6 +136,7 @@ + diff --git a/Pokemon/Pokemon/Pokemon.vcxproj.filters b/Pokemon/Pokemon/Pokemon.vcxproj.filters index 0e7b6ac..cce1c34 100644 --- a/Pokemon/Pokemon/Pokemon.vcxproj.filters +++ b/Pokemon/Pokemon/Pokemon.vcxproj.filters @@ -33,6 +33,9 @@ Source Files + + Source Files + @@ -62,5 +65,8 @@ Header Files + + Header Files + \ No newline at end of file diff --git a/Pokemon/Pokemon/Pokemons.cpp b/Pokemon/Pokemon/Pokemons.cpp index 1a08d93..e22255f 100644 --- a/Pokemon/Pokemon/Pokemons.cpp +++ b/Pokemon/Pokemon/Pokemons.cpp @@ -53,8 +53,8 @@ bool Pokemons::IsFainted() const void Pokemons::Battle(Pokemons& player_pokemon, Pokemons& wild_pokemon) { - cout << "A wild " << wild_pokemon.name << " appeared!\n"; - while (!player_pokemon.IsFainted() && !wild_pokemon.IsFainted()) + //cout << "A wild " << wild_pokemon.name << " appeared!\n"; + /*while (!player_pokemon.IsFainted() && !wild_pokemon.IsFainted()) { player_pokemon.Attack(wild_pokemon); if (!wild_pokemon.IsFainted()) @@ -63,7 +63,7 @@ void Pokemons::Battle(Pokemons& player_pokemon, Pokemons& wild_pokemon) cout << player_pokemon.name << " has fainted! You lose the battle.\n"; else if(wild_pokemon.IsFainted()) cout << wild_pokemon.name << " has fainted! You win the battle.\n"; - } + }*/ } void Pokemons::Heal() From 95c93e185b8a294f3ee92246dc7efb7fc15bd2d4 Mon Sep 17 00:00:00 2001 From: rangamach <117797904+rangamach@users.noreply.github.com> Date: Mon, 4 Nov 2024 10:00:13 +0530 Subject: [PATCH 21/30] Added Battle State. --- Pokemon/Pokemon/BattleManager.cpp | 35 ++++++++++++++++++------- Pokemon/Pokemon/BattleManager.hpp | 7 ++++- Pokemon/Pokemon/BattleState.hpp | 9 +++++++ Pokemon/Pokemon/Game.cpp | 11 ++++---- Pokemon/Pokemon/Player.cpp | 8 +++--- Pokemon/Pokemon/Pokemon.cpp | 2 +- Pokemon/Pokemon/Pokemon.vcxproj | 1 + Pokemon/Pokemon/Pokemon.vcxproj.filters | 3 +++ Pokemon/Pokemon/Pokemons.cpp | 22 +++++----------- Pokemon/Pokemon/Pokemons.hpp | 4 +-- 10 files changed, 64 insertions(+), 38 deletions(-) create mode 100644 Pokemon/Pokemon/BattleState.hpp diff --git a/Pokemon/Pokemon/BattleManager.cpp b/Pokemon/Pokemon/BattleManager.cpp index 4c93041..b41d2de 100644 --- a/Pokemon/Pokemon/BattleManager.cpp +++ b/Pokemon/Pokemon/BattleManager.cpp @@ -7,26 +7,41 @@ using namespace std; void BattleManager::StartBattle(Player &player, Pokemons &wild_pokemon) { + battle_state.player_pokemon = &player.captured_pokemon; + battle_state.wild_pokemon = &wild_pokemon; + battle_state.player_turn = true; + battle_state.battle_unfinished = true; cout << "A wild " << wild_pokemon.name << " appeared!\n"; Battle(player.captured_pokemon, wild_pokemon); } void BattleManager::Battle(Pokemons& player_pokemon, Pokemons& wild_pokemon) { - while (!player_pokemon.IsFainted() && !wild_pokemon.IsFainted()) + while (battle_state.battle_unfinished) { - player_pokemon.Attack(wild_pokemon); - if (!wild_pokemon.IsFainted()) - wild_pokemon.Attack(player_pokemon); + if (battle_state.player_turn) + battle_state.player_pokemon->Attack(*battle_state.wild_pokemon); + else + battle_state.wild_pokemon->Attack(*battle_state.player_pokemon); + UpdateBattleState(); + battle_state.player_turn = !battle_state.player_turn; Utility::WaitForEnter(); } - BattleOutcome(player_pokemon,player_pokemon.IsFainted()); + BattleOutcome(); } -void BattleManager::BattleOutcome(Pokemons &player_pokemon, bool playerWon) +void BattleManager::UpdateBattleState() { - if(playerWon) - cout << player_pokemon.name << " is victorious! Keep an eye on your Pokémon's health.\n"; - else - cout << "Oh no! " << player_pokemon.name << " fainted! You need to visit the PokeCenter.\n"; + if (battle_state.player_pokemon->IsFainted()) + battle_state.battle_unfinished = false; + else if (battle_state.wild_pokemon->IsFainted()) + battle_state.battle_unfinished = false; +} + +void BattleManager::BattleOutcome() +{ + if(battle_state.player_pokemon->IsFainted()) + cout << "Oh no! " << battle_state.player_pokemon->name << " fainted! You need to visit the PokeCenter.\n"; + else if(battle_state.wild_pokemon->IsFainted()) + cout << "Congratulations!!! " << battle_state.player_pokemon->name << " is victorious! Keep an eye on the health of your Pokemon.\n"; } \ No newline at end of file diff --git a/Pokemon/Pokemon/BattleManager.hpp b/Pokemon/Pokemon/BattleManager.hpp index debe4af..1797623 100644 --- a/Pokemon/Pokemon/BattleManager.hpp +++ b/Pokemon/Pokemon/BattleManager.hpp @@ -1,3 +1,5 @@ +#include "BattleState.hpp" + class Player; class Pokemons; @@ -6,6 +8,9 @@ class BattleManager public: void StartBattle(Player &player, Pokemons &wild_pokemon); private: + BattleState battle_state; void Battle(Pokemons &player_pokemon, Pokemons &wild_pokemon); - void BattleOutcome(Pokemons &player_pokemon, bool playerWon); + //void BattleOutcome(Pokemons &pokemon, bool playerWon); + void BattleOutcome(); + void UpdateBattleState(); }; \ No newline at end of file diff --git a/Pokemon/Pokemon/BattleState.hpp b/Pokemon/Pokemon/BattleState.hpp new file mode 100644 index 0000000..53e5aec --- /dev/null +++ b/Pokemon/Pokemon/BattleState.hpp @@ -0,0 +1,9 @@ +class Pokemons; + +struct BattleState +{ + Pokemons *player_pokemon; + Pokemons *wild_pokemon; + bool player_turn; + bool battle_unfinished; +}; \ No newline at end of file diff --git a/Pokemon/Pokemon/Game.cpp b/Pokemon/Pokemon/Game.cpp index bc7db8a..44c7ea0 100644 --- a/Pokemon/Pokemon/Game.cpp +++ b/Pokemon/Pokemon/Game.cpp @@ -13,9 +13,9 @@ Game::Game() { forest_grass = { "Forest", - {{"Pidgey",Pokemon_Types::Normal_Type,40,2}, - {"Zubat",Pokemon_Types::Poison_Type,30,10}, - {"Caterpie",Pokemon_Types::Bug_Type,35,5}}, + {{"Pidgey",Pokemon_Types::Normal_Type,40, 40, 2}, + {"Zubat",Pokemon_Types::Poison_Type,30, 30, 10}, + {"Caterpie",Pokemon_Types::Bug_Type,35, 35, 5}}, 70 }; } void Game::GameLoop(Player& player) @@ -41,14 +41,15 @@ void Game::GameLoop(Player& player) { WildPokemonEncounterHandler encounters; Pokemons encountered_pokemon = encounters.GetRandomWildPokemonFromGrass(forest_grass); - //encountered_pokemon.Battle(player.captured_pokemon, encountered_pokemon); battle_manager.StartBattle(player,encountered_pokemon); + player.captured_pokemon.ShowHealth(player.captured_pokemon); break; } case 2: { player.captured_pokemon.Heal(); - cout << player.captured_pokemon.name << "'s health is fully restored."; + cout << player.captured_pokemon.name << "'s health is fully restored.\n"; + player.captured_pokemon.ShowHealth(player.captured_pokemon); break; } case 3: diff --git a/Pokemon/Pokemon/Player.cpp b/Pokemon/Pokemon/Player.cpp index a8c4812..0753482 100644 --- a/Pokemon/Pokemon/Player.cpp +++ b/Pokemon/Pokemon/Player.cpp @@ -19,16 +19,16 @@ void Player::ChosenPokemon(int choice) switch ((Pokemon_Choice)choice) { case Pokemon_Choice::Charmander: - Player::captured_pokemon = Pokemons("Charmander", Pokemon_Types::Fire_Type, 100, 20); + Player::captured_pokemon = Pokemons("Charmander", Pokemon_Types::Fire_Type, 100, 100, 20); break; case Pokemon_Choice::Bulbasaur: - Player::captured_pokemon = Pokemons("Bulbasaur", Pokemon_Types::Grass_Type, 100, 10); + Player::captured_pokemon = Pokemons("Bulbasaur", Pokemon_Types::Grass_Type, 100, 100, 10); break; case Pokemon_Choice::Squirtle: - Player::captured_pokemon = Pokemons("Squirtle", Pokemon_Types::Water_Type, 100, 15); + Player::captured_pokemon = Pokemons("Squirtle", Pokemon_Types::Water_Type, 100, 100, 15); break; default: - Player::captured_pokemon = Pokemons("Pikachu", Pokemon_Types::Electric_Type, 100, 20); + Player::captured_pokemon = Pokemons("Pikachu", Pokemon_Types::Electric_Type, 100, 100, 20); break; } cout << name << " chose " << captured_pokemon.name << "\n"; diff --git a/Pokemon/Pokemon/Pokemon.cpp b/Pokemon/Pokemon/Pokemon.cpp index 83523f2..e152aeb 100644 --- a/Pokemon/Pokemon/Pokemon.cpp +++ b/Pokemon/Pokemon/Pokemon.cpp @@ -137,7 +137,7 @@ int main() { Game loop; - Pokemons charmander("Charmander", Pokemon_Types::Fire_Type, 100, 15); + Pokemons charmander("Charmander", Pokemon_Types::Fire_Type, 100, 100, 15); ProfessorOak Oak("Professor Oak"); Player player("Ash", charmander); diff --git a/Pokemon/Pokemon/Pokemon.vcxproj b/Pokemon/Pokemon/Pokemon.vcxproj index b1d9966..6caeea9 100644 --- a/Pokemon/Pokemon/Pokemon.vcxproj +++ b/Pokemon/Pokemon/Pokemon.vcxproj @@ -137,6 +137,7 @@ + diff --git a/Pokemon/Pokemon/Pokemon.vcxproj.filters b/Pokemon/Pokemon/Pokemon.vcxproj.filters index cce1c34..48f2690 100644 --- a/Pokemon/Pokemon/Pokemon.vcxproj.filters +++ b/Pokemon/Pokemon/Pokemon.vcxproj.filters @@ -68,5 +68,8 @@ Header Files + + Header Files + \ No newline at end of file diff --git a/Pokemon/Pokemon/Pokemons.cpp b/Pokemon/Pokemon/Pokemons.cpp index e22255f..de9b4af 100644 --- a/Pokemon/Pokemon/Pokemons.cpp +++ b/Pokemon/Pokemon/Pokemons.cpp @@ -11,11 +11,12 @@ Pokemons::Pokemons() Pokemons::health = 50; } -Pokemons::Pokemons(string poke_name, Pokemon_Types poke_type, int poke_health, int poke_attack_power) +Pokemons::Pokemons(string poke_name, Pokemon_Types poke_type, int poke_health, int poke_max_health, int poke_attack_power) { Pokemons::name = poke_name; Pokemons::type = poke_type; Pokemons::health = poke_health; + Pokemons::max_health = poke_max_health; Pokemons::attack_power = poke_attack_power; } @@ -24,6 +25,7 @@ Pokemons::Pokemons(const Pokemons& other) Pokemons::name = other.name; Pokemons::type = other.type; Pokemons::health = other.health; + Pokemons::max_health = other.max_health; Pokemons::attack_power = other.attack_power; } @@ -51,23 +53,13 @@ bool Pokemons::IsFainted() const return health <= 0; } -void Pokemons::Battle(Pokemons& player_pokemon, Pokemons& wild_pokemon) +void Pokemons::Heal() { - //cout << "A wild " << wild_pokemon.name << " appeared!\n"; - /*while (!player_pokemon.IsFainted() && !wild_pokemon.IsFainted()) - { - player_pokemon.Attack(wild_pokemon); - if (!wild_pokemon.IsFainted()) - wild_pokemon.Attack(player_pokemon); - if (player_pokemon.IsFainted()) - cout << player_pokemon.name << " has fainted! You lose the battle.\n"; - else if(wild_pokemon.IsFainted()) - cout << wild_pokemon.name << " has fainted! You win the battle.\n"; - }*/ + health = max_health; } -void Pokemons::Heal() +void Pokemons::ShowHealth(Pokemons pokemon) { - health = max_health; + cout << "\n" << pokemon.name << "'s health is at " << pokemon.health << endl; } diff --git a/Pokemon/Pokemon/Pokemons.hpp b/Pokemon/Pokemon/Pokemons.hpp index b5893ad..84f8bb5 100644 --- a/Pokemon/Pokemon/Pokemons.hpp +++ b/Pokemon/Pokemon/Pokemons.hpp @@ -15,12 +15,12 @@ class Pokemons int attack_power; Pokemons(); - Pokemons(string poke_name, Pokemon_Types poke_type, int poke_health, int poke_attack_power); + Pokemons(string poke_name, Pokemon_Types poke_type, int poke_health, int poke_max_health, int poke_attack_power); Pokemons(const Pokemons& other); ~Pokemons(); void Attack(Pokemons &target_pokemon); void TakeDamage(int damage); bool IsFainted() const; - void Battle(Pokemons &player_pokemon, Pokemons &wild_pokemon); void Heal(); + void ShowHealth(Pokemons pokemon); }; \ No newline at end of file From a5c746ad00aca4af5d152d68879e0c76ac749e00 Mon Sep 17 00:00:00 2001 From: rangamach <117797904+rangamach@users.noreply.github.com> Date: Mon, 4 Nov 2024 10:44:07 +0530 Subject: [PATCH 22/30] Added Utility namespace. --- Pokemon/Pokemon/BattleManager.cpp | 4 ++- Pokemon/Pokemon/BattleManager.hpp | 3 +- Pokemon/Pokemon/Game.cpp | 4 ++- Pokemon/Pokemon/Player.cpp | 2 ++ Pokemon/Pokemon/Player.hpp | 1 - Pokemon/Pokemon/Pokemon.cpp | 50 ++----------------------------- Pokemon/Pokemon/Pokemons.cpp | 2 ++ Pokemon/Pokemon/Utility.cpp | 2 ++ Pokemon/Pokemon/Utility.hpp | 7 +++-- 9 files changed, 21 insertions(+), 54 deletions(-) diff --git a/Pokemon/Pokemon/BattleManager.cpp b/Pokemon/Pokemon/BattleManager.cpp index b41d2de..0417db6 100644 --- a/Pokemon/Pokemon/BattleManager.cpp +++ b/Pokemon/Pokemon/BattleManager.cpp @@ -5,7 +5,9 @@ using namespace std; -void BattleManager::StartBattle(Player &player, Pokemons &wild_pokemon) +using namespace N_Utility; + +void BattleManager::StartBattle(Player& player, Pokemons& wild_pokemon) { battle_state.player_pokemon = &player.captured_pokemon; battle_state.wild_pokemon = &wild_pokemon; diff --git a/Pokemon/Pokemon/BattleManager.hpp b/Pokemon/Pokemon/BattleManager.hpp index 1797623..32ad311 100644 --- a/Pokemon/Pokemon/BattleManager.hpp +++ b/Pokemon/Pokemon/BattleManager.hpp @@ -6,11 +6,10 @@ class Pokemons; class BattleManager { public: - void StartBattle(Player &player, Pokemons &wild_pokemon); + void StartBattle(Player& player, Pokemons &wild_pokemon); private: BattleState battle_state; void Battle(Pokemons &player_pokemon, Pokemons &wild_pokemon); - //void BattleOutcome(Pokemons &pokemon, bool playerWon); void BattleOutcome(); void UpdateBattleState(); }; \ No newline at end of file diff --git a/Pokemon/Pokemon/Game.cpp b/Pokemon/Pokemon/Game.cpp index 44c7ea0..aa6e746 100644 --- a/Pokemon/Pokemon/Game.cpp +++ b/Pokemon/Pokemon/Game.cpp @@ -9,6 +9,8 @@ using namespace std; +using namespace N_Utility; + Game::Game() { forest_grass = { @@ -18,7 +20,7 @@ Game::Game() {"Caterpie",Pokemon_Types::Bug_Type,35, 35, 5}}, 70 }; } -void Game::GameLoop(Player& player) +void Game::GameLoop(Player &player) { BattleManager battle_manager; int choice; diff --git a/Pokemon/Pokemon/Player.cpp b/Pokemon/Pokemon/Player.cpp index 0753482..5f35b82 100644 --- a/Pokemon/Pokemon/Player.cpp +++ b/Pokemon/Pokemon/Player.cpp @@ -4,6 +4,8 @@ using namespace std; +using namespace N_Utility; + Player::Player() { Player::captured_pokemon = Pokemons(); diff --git a/Pokemon/Pokemon/Player.hpp b/Pokemon/Pokemon/Player.hpp index 4c1b904..53c977a 100644 --- a/Pokemon/Pokemon/Player.hpp +++ b/Pokemon/Pokemon/Player.hpp @@ -18,5 +18,4 @@ class Player Player(); Player(string playerName, Pokemons playerCapturedPokemon); void ChosenPokemon(int choice); - }; \ No newline at end of file diff --git a/Pokemon/Pokemon/Pokemon.cpp b/Pokemon/Pokemon/Pokemon.cpp index e152aeb..e8a50a4 100644 --- a/Pokemon/Pokemon/Pokemon.cpp +++ b/Pokemon/Pokemon/Pokemon.cpp @@ -8,6 +8,9 @@ using namespace std; +using namespace N_Utility; + + class ProfessorOak { public: @@ -86,53 +89,6 @@ class ProfessorOak } }; -//void GameLoop(Player &player) -//{ -// int choice; -// bool keepPlaying = true; -// while (keepPlaying) -// { -// Utility::ClearConsole(); -// cout << "\nWhat would you like to do next, " << player.name << "?\n"; -// cout << "1. Battle Wild Pokemon\n"; -// cout << "2. Visit PokeCenter\n"; -// cout << "3. Challenge Gyms\n"; -// cout << "4. Enter Pokemon League\n"; -// cout << "5. Quit\n"; -// cout << "Enter your choice: "; -// cin >> choice; -// Utility::ClearInputBuffer(); -// switch (choice) -// { -// case 1: -// cout << "You look around... but all the wild Pokemon 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 Pokemon 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 Pokemon 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 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; -// }; -// Utility::WaitForEnter(); -// } -// cout << "Goodbye, " << player.name << "! Thanks for playing!\n"; -//} - int main() { Game loop; diff --git a/Pokemon/Pokemon/Pokemons.cpp b/Pokemon/Pokemon/Pokemons.cpp index de9b4af..5c8e930 100644 --- a/Pokemon/Pokemon/Pokemons.cpp +++ b/Pokemon/Pokemon/Pokemons.cpp @@ -9,6 +9,8 @@ Pokemons::Pokemons() Pokemons::name = "Unknown"; Pokemons::type = Pokemon_Types::Normal_Type; Pokemons::health = 50; + Pokemons::max_health = 100; + Pokemons::attack_power = 10; } Pokemons::Pokemons(string poke_name, Pokemon_Types poke_type, int poke_health, int poke_max_health, int poke_attack_power) diff --git a/Pokemon/Pokemon/Utility.cpp b/Pokemon/Pokemon/Utility.cpp index 309f587..9b1c285 100644 --- a/Pokemon/Pokemon/Utility.cpp +++ b/Pokemon/Pokemon/Utility.cpp @@ -3,6 +3,8 @@ using namespace std; +using namespace N_Utility; + void Utility::WaitForEnter() { cin.get(); diff --git a/Pokemon/Pokemon/Utility.hpp b/Pokemon/Pokemon/Utility.hpp index e45b677..2d064db 100644 --- a/Pokemon/Pokemon/Utility.hpp +++ b/Pokemon/Pokemon/Utility.hpp @@ -1,9 +1,12 @@ #pragma once -class Utility +namespace N_Utility { + class Utility + { public: static void WaitForEnter(); static void ClearConsole(); static void ClearInputBuffer(); -}; \ No newline at end of file + }; +} \ No newline at end of file From b5ea981fd6dc3ab61292e672696cb45151b129b5 Mon Sep 17 00:00:00 2001 From: rangamach <117797904+rangamach@users.noreply.github.com> Date: Mon, 4 Nov 2024 17:08:55 +0530 Subject: [PATCH 23/30] Added Pikachu,Caterpie,Zubat,Pidgey classes. --- Pokemon/Pokemon/Caterpie.cpp | 0 Pokemon/Pokemon/Caterpie.hpp | 0 Pokemon/Pokemon/Pidgey.cpp | 0 Pokemon/Pokemon/Pidgey.hpp | 0 Pokemon/Pokemon/Pikachu.cpp | 0 Pokemon/Pokemon/Pikachu.hpp | 8 ++++++++ Pokemon/Pokemon/Zubat.cpp | 14 ++++++++++++++ Pokemon/Pokemon/Zubat.hpp | 7 +++++++ 8 files changed, 29 insertions(+) create mode 100644 Pokemon/Pokemon/Caterpie.cpp create mode 100644 Pokemon/Pokemon/Caterpie.hpp create mode 100644 Pokemon/Pokemon/Pidgey.cpp create mode 100644 Pokemon/Pokemon/Pidgey.hpp create mode 100644 Pokemon/Pokemon/Pikachu.cpp create mode 100644 Pokemon/Pokemon/Pikachu.hpp create mode 100644 Pokemon/Pokemon/Zubat.cpp create mode 100644 Pokemon/Pokemon/Zubat.hpp diff --git a/Pokemon/Pokemon/Caterpie.cpp b/Pokemon/Pokemon/Caterpie.cpp new file mode 100644 index 0000000..e69de29 diff --git a/Pokemon/Pokemon/Caterpie.hpp b/Pokemon/Pokemon/Caterpie.hpp new file mode 100644 index 0000000..e69de29 diff --git a/Pokemon/Pokemon/Pidgey.cpp b/Pokemon/Pokemon/Pidgey.cpp new file mode 100644 index 0000000..e69de29 diff --git a/Pokemon/Pokemon/Pidgey.hpp b/Pokemon/Pokemon/Pidgey.hpp new file mode 100644 index 0000000..e69de29 diff --git a/Pokemon/Pokemon/Pikachu.cpp b/Pokemon/Pokemon/Pikachu.cpp new file mode 100644 index 0000000..e69de29 diff --git a/Pokemon/Pokemon/Pikachu.hpp b/Pokemon/Pokemon/Pikachu.hpp new file mode 100644 index 0000000..b5ff2c8 --- /dev/null +++ b/Pokemon/Pokemon/Pikachu.hpp @@ -0,0 +1,8 @@ +#include "Pokemons.hpp" + +class Pikachu : public Pokemons +{ + public: + Pikachu(); + void ThunderShock(Pokemons& target_pokemon); +}; diff --git a/Pokemon/Pokemon/Zubat.cpp b/Pokemon/Pokemon/Zubat.cpp new file mode 100644 index 0000000..3a42c5d --- /dev/null +++ b/Pokemon/Pokemon/Zubat.cpp @@ -0,0 +1,14 @@ +#include "Zubat.hpp" +#include "Pokemons.hpp" +#include + +Zubat::Zubat() +{ + Pokemons("Zubat", Pokemon_Types::Poison_Type, 100, 100, 20); +} + +void Zubat::SuperSonic(Pokemons& target_pokemon) +{ + cout << name << " uses Supersonic on " << target_pokemon.name << "!!!\n"; + target_pokemon.TakeDamage(20); +} \ No newline at end of file diff --git a/Pokemon/Pokemon/Zubat.hpp b/Pokemon/Pokemon/Zubat.hpp new file mode 100644 index 0000000..47c4832 --- /dev/null +++ b/Pokemon/Pokemon/Zubat.hpp @@ -0,0 +1,7 @@ +#include "Pokemons.hpp" + +class Zubat :public Pokemons +{ + Zubat(); + void SuperSonic(Pokemons& target_pokemon); +}; \ No newline at end of file From 64aa5182f649935729bd88392327c9aa7f1a2814 Mon Sep 17 00:00:00 2001 From: rangamach <117797904+rangamach@users.noreply.github.com> Date: Mon, 4 Nov 2024 17:43:41 +0530 Subject: [PATCH 24/30] Added abstraction and getter and setter for health. --- Pokemon/Pokemon/Pokemons.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Pokemon/Pokemon/Pokemons.cpp b/Pokemon/Pokemon/Pokemons.cpp index 5c8e930..b8a1226 100644 --- a/Pokemon/Pokemon/Pokemons.cpp +++ b/Pokemon/Pokemon/Pokemons.cpp @@ -65,3 +65,13 @@ void Pokemons::ShowHealth(Pokemons pokemon) cout << "\n" << pokemon.name << "'s health is at " << pokemon.health << endl; } +int Pokemons::GetHealth() +{ + return health; +} + +void Pokemons::SetHealth(int updated_health) +{ + health = updated_health; +} + From 59a1054ce81f432362c529828cf8559091c36a64 Mon Sep 17 00:00:00 2001 From: rangamach <117797904+rangamach@users.noreply.github.com> Date: Mon, 4 Nov 2024 18:18:19 +0530 Subject: [PATCH 25/30] Added other pokemons. --- Pokemon/Pokemon/Bulbasaur.cpp | 14 ++++++++++++++ Pokemon/Pokemon/Bulbasaur.hpp | 11 +++++++++++ Pokemon/Pokemon/Charmander.cpp | 14 ++++++++++++++ Pokemon/Pokemon/Charmander.hpp | 9 +++++++++ Pokemon/Pokemon/Pokemons.hpp | 2 ++ Pokemon/Pokemon/Squirtle.cpp | 0 Pokemon/Pokemon/Squirtle.hpp | 0 7 files changed, 50 insertions(+) create mode 100644 Pokemon/Pokemon/Bulbasaur.cpp create mode 100644 Pokemon/Pokemon/Bulbasaur.hpp create mode 100644 Pokemon/Pokemon/Charmander.cpp create mode 100644 Pokemon/Pokemon/Charmander.hpp create mode 100644 Pokemon/Pokemon/Squirtle.cpp create mode 100644 Pokemon/Pokemon/Squirtle.hpp diff --git a/Pokemon/Pokemon/Bulbasaur.cpp b/Pokemon/Pokemon/Bulbasaur.cpp new file mode 100644 index 0000000..e6c6185 --- /dev/null +++ b/Pokemon/Pokemon/Bulbasaur.cpp @@ -0,0 +1,14 @@ +#include "Bulbasaur.hpp" +#include "PokemonType.hpp" +#include + +Bulbasaur::Bulbasaur() +{ + Pokemons("Bulbasaur", Pokemon_Types::Grass_Type, 100, 100, 35); +} + +void Bulbasaur::VineWhip(Pokemons& target_pokemon) +{ + cout << name << " uses Vinewhip on " << target_pokemon.name << "!!!\n"; + target_pokemon.TakeDamage(35); +} \ No newline at end of file diff --git a/Pokemon/Pokemon/Bulbasaur.hpp b/Pokemon/Pokemon/Bulbasaur.hpp new file mode 100644 index 0000000..7a31ed2 --- /dev/null +++ b/Pokemon/Pokemon/Bulbasaur.hpp @@ -0,0 +1,11 @@ +#pragma once + +#include "Pokemons.hpp" + +class Bulbasaur :public Pokemons +{ +public: + Bulbasaur(); +private: + void VineWhip(Pokemons& target_pokemon); +}; \ No newline at end of file diff --git a/Pokemon/Pokemon/Charmander.cpp b/Pokemon/Pokemon/Charmander.cpp new file mode 100644 index 0000000..cb43e8d --- /dev/null +++ b/Pokemon/Pokemon/Charmander.cpp @@ -0,0 +1,14 @@ +#include "Charmander.hpp" +#include "PokemonType.hpp" +#include + +Charmander::Charmander() +{ + Pokemons("Charmander", Pokemon_Types::Fire_Type, 100, 100, 35); +} + +void Charmander::FlameBurst(Pokemons& target_pokemon) +{ + cout << name << " uses Supersonic on " << target_pokemon.name << "!!!\n"; + target_pokemon.TakeDamage(35); +} \ No newline at end of file diff --git a/Pokemon/Pokemon/Charmander.hpp b/Pokemon/Pokemon/Charmander.hpp new file mode 100644 index 0000000..0e6b803 --- /dev/null +++ b/Pokemon/Pokemon/Charmander.hpp @@ -0,0 +1,9 @@ +#include "Pokemons.hpp" + +class Charmander :public Pokemons +{ +public: + Charmander(); +private: + void FlameBurst(Pokemons& target_pokemon); +}; \ No newline at end of file diff --git a/Pokemon/Pokemon/Pokemons.hpp b/Pokemon/Pokemon/Pokemons.hpp index 84f8bb5..857e8e5 100644 --- a/Pokemon/Pokemon/Pokemons.hpp +++ b/Pokemon/Pokemon/Pokemons.hpp @@ -23,4 +23,6 @@ class Pokemons bool IsFainted() const; void Heal(); void ShowHealth(Pokemons pokemon); + int GetHealth(); + void SetHealth(int updated_health); }; \ No newline at end of file diff --git a/Pokemon/Pokemon/Squirtle.cpp b/Pokemon/Pokemon/Squirtle.cpp new file mode 100644 index 0000000..e69de29 diff --git a/Pokemon/Pokemon/Squirtle.hpp b/Pokemon/Pokemon/Squirtle.hpp new file mode 100644 index 0000000..e69de29 From 5878c37f40b53b2e644f66798d64a680608e3f68 Mon Sep 17 00:00:00 2001 From: rangamach <117797904+rangamach@users.noreply.github.com> Date: Tue, 5 Nov 2024 09:55:03 +0530 Subject: [PATCH 26/30] Added Pointers, new and delete operations. --- Pokemon/Pokemon/Caterpie.cpp | 14 ++++ Pokemon/Pokemon/Caterpie.hpp | 11 +++ Pokemon/Pokemon/Charmander.cpp | 2 +- Pokemon/Pokemon/Charmander.hpp | 2 + Pokemon/Pokemon/Game.cpp | 5 +- Pokemon/Pokemon/Pidgey.cpp | 14 ++++ Pokemon/Pokemon/Pidgey.hpp | 11 +++ Pokemon/Pokemon/Pikachu.cpp | 16 ++++ Pokemon/Pokemon/Pikachu.hpp | 3 + Pokemon/Pokemon/Pokemon.cpp | 102 +++--------------------- Pokemon/Pokemon/Pokemon.vcxproj | 16 ++++ Pokemon/Pokemon/Pokemon.vcxproj.filters | 48 +++++++++++ Pokemon/Pokemon/ProfessorOak.cpp | 80 +++++++++++++++++++ Pokemon/Pokemon/ProfessorOak.hpp | 16 ++++ Pokemon/Pokemon/Squirtle.cpp | 14 ++++ Pokemon/Pokemon/Squirtle.hpp | 11 +++ Pokemon/Pokemon/Zubat.hpp | 6 +- 17 files changed, 276 insertions(+), 95 deletions(-) create mode 100644 Pokemon/Pokemon/ProfessorOak.cpp create mode 100644 Pokemon/Pokemon/ProfessorOak.hpp diff --git a/Pokemon/Pokemon/Caterpie.cpp b/Pokemon/Pokemon/Caterpie.cpp index e69de29..6a6a0cc 100644 --- a/Pokemon/Pokemon/Caterpie.cpp +++ b/Pokemon/Pokemon/Caterpie.cpp @@ -0,0 +1,14 @@ +#include "Caterpie.hpp" +#include "PokemonType.hpp" +#include + +Caterpie::Caterpie() +{ + Pokemons("Caterpie", Pokemon_Types::Bug_Type, 100, 100, 10); +} + +void Caterpie::BugBite(Pokemons& target_pokemon) +{ + cout << name << " uses Bugbite on " << target_pokemon.name << "!!!\n"; + target_pokemon.TakeDamage(20); +} \ No newline at end of file diff --git a/Pokemon/Pokemon/Caterpie.hpp b/Pokemon/Pokemon/Caterpie.hpp index e69de29..e563246 100644 --- a/Pokemon/Pokemon/Caterpie.hpp +++ b/Pokemon/Pokemon/Caterpie.hpp @@ -0,0 +1,11 @@ +#pragma once + +#include "Pokemons.hpp" + +class Caterpie :public Pokemons +{ + public: + Caterpie(); + private: + void BugBite(Pokemons& target_pokemon); +}; \ No newline at end of file diff --git a/Pokemon/Pokemon/Charmander.cpp b/Pokemon/Pokemon/Charmander.cpp index cb43e8d..509b919 100644 --- a/Pokemon/Pokemon/Charmander.cpp +++ b/Pokemon/Pokemon/Charmander.cpp @@ -9,6 +9,6 @@ Charmander::Charmander() void Charmander::FlameBurst(Pokemons& target_pokemon) { - cout << name << " uses Supersonic on " << target_pokemon.name << "!!!\n"; + cout << name << " uses Flameburst on " << target_pokemon.name << "!!!\n"; target_pokemon.TakeDamage(35); } \ No newline at end of file diff --git a/Pokemon/Pokemon/Charmander.hpp b/Pokemon/Pokemon/Charmander.hpp index 0e6b803..0141be3 100644 --- a/Pokemon/Pokemon/Charmander.hpp +++ b/Pokemon/Pokemon/Charmander.hpp @@ -1,3 +1,5 @@ +#pragma once + #include "Pokemons.hpp" class Charmander :public Pokemons diff --git a/Pokemon/Pokemon/Game.cpp b/Pokemon/Pokemon/Game.cpp index aa6e746..6e5da90 100644 --- a/Pokemon/Pokemon/Game.cpp +++ b/Pokemon/Pokemon/Game.cpp @@ -22,7 +22,7 @@ Game::Game() } void Game::GameLoop(Player &player) { - BattleManager battle_manager; + BattleManager* battle_manager = new BattleManager(); int choice; bool keepPlaying = true; while (keepPlaying) @@ -43,7 +43,7 @@ void Game::GameLoop(Player &player) { WildPokemonEncounterHandler encounters; Pokemons encountered_pokemon = encounters.GetRandomWildPokemonFromGrass(forest_grass); - battle_manager.StartBattle(player,encountered_pokemon); + battle_manager->StartBattle(player,encountered_pokemon); player.captured_pokemon.ShowHealth(player.captured_pokemon); break; } @@ -77,4 +77,5 @@ void Game::GameLoop(Player &player) Utility::WaitForEnter(); } cout << "Goodbye, " << player.name << "! Thanks for playing!\n"; + delete(battle_manager); } \ No newline at end of file diff --git a/Pokemon/Pokemon/Pidgey.cpp b/Pokemon/Pokemon/Pidgey.cpp index e69de29..19a261a 100644 --- a/Pokemon/Pokemon/Pidgey.cpp +++ b/Pokemon/Pokemon/Pidgey.cpp @@ -0,0 +1,14 @@ +#include "Pidgey.hpp" +#include "PokemonType.hpp" +#include + +Pidgey::Pidgey() +{ + Pokemons("Pidgey", Pokemon_Types::Normal_Type, 100, 100, 35); +} + +void Pidgey::WingAttack(Pokemons& target_pokemon) +{ + cout << name << " uses Wingattack on " << target_pokemon.name << "!!!\n"; + target_pokemon.TakeDamage(20); +} \ No newline at end of file diff --git a/Pokemon/Pokemon/Pidgey.hpp b/Pokemon/Pokemon/Pidgey.hpp index e69de29..e181803 100644 --- a/Pokemon/Pokemon/Pidgey.hpp +++ b/Pokemon/Pokemon/Pidgey.hpp @@ -0,0 +1,11 @@ +#pragma once + +#include "Pokemons.hpp" + +class Pidgey :public Pokemons +{ + public: + Pidgey(); + private: + void WingAttack(Pokemons& target_pokemon); +}; \ No newline at end of file diff --git a/Pokemon/Pokemon/Pikachu.cpp b/Pokemon/Pokemon/Pikachu.cpp index e69de29..e0f0fba 100644 --- a/Pokemon/Pokemon/Pikachu.cpp +++ b/Pokemon/Pokemon/Pikachu.cpp @@ -0,0 +1,16 @@ +#include "Pikachu.hpp" +#include "PokemonType.hpp" +#include + +using namespace std; + +Pikachu::Pikachu() +{ + Pokemons("Pikachu", Pokemon_Types::Electric_Type, 100, 100, 15); +} + +void Pikachu::ThunderShock(Pokemons& target_pokemon) +{ + cout << name << " uses Thundershock on " << target_pokemon.name << "!!!\n"; + target_pokemon.TakeDamage(20); +} \ No newline at end of file diff --git a/Pokemon/Pokemon/Pikachu.hpp b/Pokemon/Pokemon/Pikachu.hpp index b5ff2c8..a63ad25 100644 --- a/Pokemon/Pokemon/Pikachu.hpp +++ b/Pokemon/Pokemon/Pikachu.hpp @@ -1,8 +1,11 @@ +#pragma once + #include "Pokemons.hpp" class Pikachu : public Pokemons { public: Pikachu(); + private: void ThunderShock(Pokemons& target_pokemon); }; diff --git a/Pokemon/Pokemon/Pokemon.cpp b/Pokemon/Pokemon/Pokemon.cpp index e8a50a4..636818a 100644 --- a/Pokemon/Pokemon/Pokemon.cpp +++ b/Pokemon/Pokemon/Pokemon.cpp @@ -5,104 +5,26 @@ #include "Utility.hpp" #include "Player.hpp" #include "Game.hpp" +#include "ProfessorOak.hpp" using namespace std; using namespace N_Utility; - -class ProfessorOak -{ - public: - string name; - void GreetPlayer(Player& player) - { - cout << name << ": Welcome to the world of Pokemon! I am Professor Oak.\n"; - Utility::WaitForEnter(); - cout << name << ": People call me the Pokemon Professor!\n"; - Utility::WaitForEnter(); - cout << name << ": But enough about me. Let's talk about you!\n"; - Utility::WaitForEnter(); - } - - ProfessorOak(string prof_name) - { - name = prof_name; - } - - void PlayerIntro(Player& player) - { - cout << name << ": First, tell me what is 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 will need a Pokemon of your own!\n"; - Utility::WaitForEnter(); - } - void FirstPokemon(Player& player) - { - int choice; - cout << name << ": I have three Pokemon here with me. They are all quite feisty!\n"; - Utility::WaitForEnter(); - cout << name << ": Choose wisely...\n"; - cout << name << ": 1. Charmander - The fire type. A real hothead!\n"; - cout << name << ": 2. Bulbasaur - The grass type. Calm and collected!\n"; - cout << name << ": 3. Squirtle - The water type. Cool as a cucumber!\n"; - - cout << name << ": So, which one will it be? Enter the number of your choice:"; - cin >> choice; - player.ChosenPokemon(choice); - - cout << "Professor Oak: " << player.captured_pokemon.name << " and you, " << player.name << ", are going to be the best of friends!\n"; - Utility::WaitForEnter(); - } - - void ExplainMainQuest(Player player) - { - Utility::ClearConsole(); - cout << name << ": Ok, " << player.name << ", I am about to explain you about your upcoming grand adventure.\n"; - Utility::WaitForEnter(); - cout << name << ": You see, becoming a Pokemon Master is no easy feat, it takes courage, wisdom, and a bit of luck.\n"; - Utility::WaitForEnter(); - cout << name << ": Your mission, should you choose to accept it (and trust me, you really do not have a choice) is to collect all the Pokemon Badges and conquer the Pokemon League. \n"; - Utility::WaitForEnter(); - cout << player.name << ": Wait... that sounds a lot like every other Pokemon game out there.\n"; - Utility::WaitForEnter(); - cout << name << ": Shhh! Don't break the fourth wall " << player.name << "! This is serious business.\n"; - Utility::WaitForEnter(); - cout << name << ": To achieve this, you will need to battle wild Pokemon, challenge gym leaders, and of course, keep your Pokemon healthy at the PokeCenter.\n"; - Utility::WaitForEnter(); - cout << name << ": Along the way, you'll capture new Pokemon 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 << player.name << ": Sounds like a walk in the park... right?\n"; - Utility::WaitForEnter(); - cout << name << ": Hah! Thats 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 << name << ": So, what do you say? Are you ready to become the next Pokemon Champion?\n"; - Utility::WaitForEnter(); - cout << player.name << ": Ready as I will ever be, Professor!\n"; - Utility::WaitForEnter(); - cout << name << ": That is the spirit! Now, your journey begins.\n"; - Utility::WaitForEnter(); - cout << name << ": But first... let's just pretend I didn't forget to set up the actual game loop... Ahem, onwards!\n"; - Utility::WaitForEnter(); - } -}; - int main() { - Game loop; - - Pokemons charmander("Charmander", Pokemon_Types::Fire_Type, 100, 100, 15); - - ProfessorOak Oak("Professor Oak"); - Player player("Ash", charmander); + Game* loop = new Game(); + ProfessorOak* professor = new ProfessorOak("Professor Oak"); + Player* player = new Player(); - Oak.GreetPlayer(player); - Oak.PlayerIntro(player); - Oak.FirstPokemon(player); + professor->GreetPlayer(*player); + professor->PlayerIntro(*player); + professor->FirstPokemon(*player); + professor->ExplainMainQuest(*player); - Oak.ExplainMainQuest(player); + loop->GameLoop(*player); - loop.GameLoop(player); + delete(professor); + delete(player); + delete(loop); } \ No newline at end of file diff --git a/Pokemon/Pokemon/Pokemon.vcxproj b/Pokemon/Pokemon/Pokemon.vcxproj index 6caeea9..cc5d425 100644 --- a/Pokemon/Pokemon/Pokemon.vcxproj +++ b/Pokemon/Pokemon/Pokemon.vcxproj @@ -128,25 +128,41 @@ + + + + + + + + + + + + + + + + diff --git a/Pokemon/Pokemon/Pokemon.vcxproj.filters b/Pokemon/Pokemon/Pokemon.vcxproj.filters index 48f2690..77c812a 100644 --- a/Pokemon/Pokemon/Pokemon.vcxproj.filters +++ b/Pokemon/Pokemon/Pokemon.vcxproj.filters @@ -36,6 +36,30 @@ Source Files + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + @@ -71,5 +95,29 @@ Header Files + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + \ No newline at end of file diff --git a/Pokemon/Pokemon/ProfessorOak.cpp b/Pokemon/Pokemon/ProfessorOak.cpp new file mode 100644 index 0000000..dc577c6 --- /dev/null +++ b/Pokemon/Pokemon/ProfessorOak.cpp @@ -0,0 +1,80 @@ +#include "ProfessorOak.hpp" +#include "Player.hpp" +#include + +using namespace std; +using namespace N_Utility; + +ProfessorOak::ProfessorOak(string prof_name) +{ + name = prof_name; +} + +void ProfessorOak::PlayerIntro(Player& player) +{ + cout << name << ": First, tell me what is 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 will need a Pokemon of your own!\n"; + Utility::WaitForEnter(); +} + +void ProfessorOak::GreetPlayer(Player& player) +{ + cout << name << ": Welcome to the world of Pokemon! I am Professor Oak.\n"; + Utility::WaitForEnter(); + cout << name << ": 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::FirstPokemon(Player& player) +{ + int choice; + cout << name << ": I have three Pokemon here with me. They are all quite feisty!\n"; + Utility::WaitForEnter(); + cout << name << ": Choose wisely...\n"; + cout << name << ": 1. Charmander - The fire type. A real hothead!\n"; + cout << name << ": 2. Bulbasaur - The grass type. Calm and collected!\n"; + cout << name << ": 3. Squirtle - The water type. Cool as a cucumber!\n"; + + cout << name << ": So, which one will it be? Enter the number of your choice:"; + cin >> choice; + player.ChosenPokemon(choice); + + cout << "Professor Oak: " << player.captured_pokemon.name << " and you, " << player.name << ", are going to be the best of friends!\n"; + Utility::WaitForEnter(); +} + +void ProfessorOak::ExplainMainQuest(Player player) +{ + Utility::ClearConsole(); + cout << name << ": Ok, " << player.name << ", I am about to explain you about your upcoming grand adventure.\n"; + Utility::WaitForEnter(); + cout << name << ": You see, becoming a Pokemon Master is no easy feat, it takes courage, wisdom, and a bit of luck.\n"; + Utility::WaitForEnter(); + cout << name << ": Your mission, should you choose to accept it (and trust me, you really do not have a choice) is to collect all the Pokemon Badges and conquer the Pokemon League. \n"; + Utility::WaitForEnter(); + cout << player.name << ": Wait... that sounds a lot like every other Pokemon game out there.\n"; + Utility::WaitForEnter(); + cout << name << ": Shhh! Don't break the fourth wall " << player.name << "! This is serious business.\n"; + Utility::WaitForEnter(); + cout << name << ": To achieve this, you will need to battle wild Pokemon, challenge gym leaders, and of course, keep your Pokemon healthy at the PokeCenter.\n"; + Utility::WaitForEnter(); + cout << name << ": Along the way, you'll capture new Pokemon 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 << player.name << ": Sounds like a walk in the park... right?\n"; + Utility::WaitForEnter(); + cout << name << ": Hah! Thats 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 << name << ": So, what do you say? Are you ready to become the next Pokemon Champion?\n"; + Utility::WaitForEnter(); + cout << player.name << ": Ready as I will ever be, Professor!\n"; + Utility::WaitForEnter(); + cout << name << ": That is the spirit! Now, your journey begins.\n"; + Utility::WaitForEnter(); + cout << name << ": But first... let's just pretend I didn't forget to set up the actual game loop... Ahem, onwards!\n"; + Utility::WaitForEnter(); +} \ No newline at end of file diff --git a/Pokemon/Pokemon/ProfessorOak.hpp b/Pokemon/Pokemon/ProfessorOak.hpp new file mode 100644 index 0000000..ce8cb58 --- /dev/null +++ b/Pokemon/Pokemon/ProfessorOak.hpp @@ -0,0 +1,16 @@ +#include + +using namespace std; + +class Player; + +class ProfessorOak +{ +public: + string name; + ProfessorOak(string prof_name); + void GreetPlayer(Player& player); + void PlayerIntro(Player& player); + void FirstPokemon(Player& player); + void ExplainMainQuest(Player player); +}; \ No newline at end of file diff --git a/Pokemon/Pokemon/Squirtle.cpp b/Pokemon/Pokemon/Squirtle.cpp index e69de29..00ced77 100644 --- a/Pokemon/Pokemon/Squirtle.cpp +++ b/Pokemon/Pokemon/Squirtle.cpp @@ -0,0 +1,14 @@ +#include "Squirtle.hpp" +#include "PokemonType.hpp" +#include + +Squirtle::Squirtle() +{ + Pokemons("Squirtle", Pokemon_Types::Water_Type, 100, 100, 35); +} + +void Squirtle::WaterSplash(Pokemons& target_pokemon) +{ + cout << name << " uses Watersplash on " << target_pokemon.name << "!!!\n"; + target_pokemon.TakeDamage(35); +} \ No newline at end of file diff --git a/Pokemon/Pokemon/Squirtle.hpp b/Pokemon/Pokemon/Squirtle.hpp index e69de29..a051f14 100644 --- a/Pokemon/Pokemon/Squirtle.hpp +++ b/Pokemon/Pokemon/Squirtle.hpp @@ -0,0 +1,11 @@ +#pragma once + +#include "Pokemons.hpp" + +class Squirtle :public Pokemons +{ +public: + Squirtle(); +private: + void WaterSplash(Pokemons& target_pokemon); +}; \ No newline at end of file diff --git a/Pokemon/Pokemon/Zubat.hpp b/Pokemon/Pokemon/Zubat.hpp index 47c4832..1f26b39 100644 --- a/Pokemon/Pokemon/Zubat.hpp +++ b/Pokemon/Pokemon/Zubat.hpp @@ -2,6 +2,8 @@ class Zubat :public Pokemons { - Zubat(); - void SuperSonic(Pokemons& target_pokemon); + public: + Zubat(); + private: + void SuperSonic(Pokemons& target_pokemon); }; \ No newline at end of file From 37b6b4d79de7db76f95aa557b37bd6732e2a32bf Mon Sep 17 00:00:00 2001 From: rangamach <117797904+rangamach@users.noreply.github.com> Date: Tue, 5 Nov 2024 10:49:42 +0530 Subject: [PATCH 27/30] Changed Attack function to abstract function. --- Pokemon/Pokemon/Bulbasaur.cpp | 5 +++++ Pokemon/Pokemon/Caterpie.cpp | 5 +++++ Pokemon/Pokemon/Charmander.hpp | 2 ++ Pokemon/Pokemon/Pidgey.hpp | 2 ++ Pokemon/Pokemon/Pokemons.cpp | 12 ++++++------ Pokemon/Pokemon/Pokemons.hpp | 2 +- 6 files changed, 21 insertions(+), 7 deletions(-) diff --git a/Pokemon/Pokemon/Bulbasaur.cpp b/Pokemon/Pokemon/Bulbasaur.cpp index e6c6185..60b0d05 100644 --- a/Pokemon/Pokemon/Bulbasaur.cpp +++ b/Pokemon/Pokemon/Bulbasaur.cpp @@ -11,4 +11,9 @@ void Bulbasaur::VineWhip(Pokemons& target_pokemon) { cout << name << " uses Vinewhip on " << target_pokemon.name << "!!!\n"; target_pokemon.TakeDamage(35); +} + +void Bulbasaur::Attack(Pokemons& target_pokemon) +{ + VineWhip(target_pokemon); } \ No newline at end of file diff --git a/Pokemon/Pokemon/Caterpie.cpp b/Pokemon/Pokemon/Caterpie.cpp index 6a6a0cc..9eae37c 100644 --- a/Pokemon/Pokemon/Caterpie.cpp +++ b/Pokemon/Pokemon/Caterpie.cpp @@ -11,4 +11,9 @@ void Caterpie::BugBite(Pokemons& target_pokemon) { cout << name << " uses Bugbite on " << target_pokemon.name << "!!!\n"; target_pokemon.TakeDamage(20); +} + +void Caterpie::Attack(Pokemons& target_pokemon) +{ + BugBite(target_pokemon); } \ No newline at end of file diff --git a/Pokemon/Pokemon/Charmander.hpp b/Pokemon/Pokemon/Charmander.hpp index 0141be3..a8ba70c 100644 --- a/Pokemon/Pokemon/Charmander.hpp +++ b/Pokemon/Pokemon/Charmander.hpp @@ -8,4 +8,6 @@ class Charmander :public Pokemons Charmander(); private: void FlameBurst(Pokemons& target_pokemon); + + void Attack(Pokemons& target_pokemon) override; }; \ No newline at end of file diff --git a/Pokemon/Pokemon/Pidgey.hpp b/Pokemon/Pokemon/Pidgey.hpp index e181803..892ec3c 100644 --- a/Pokemon/Pokemon/Pidgey.hpp +++ b/Pokemon/Pokemon/Pidgey.hpp @@ -8,4 +8,6 @@ class Pidgey :public Pokemons Pidgey(); private: void WingAttack(Pokemons& target_pokemon); + + void Attack(Pokemons& target_pokemon) override; }; \ No newline at end of file diff --git a/Pokemon/Pokemon/Pokemons.cpp b/Pokemon/Pokemon/Pokemons.cpp index b8a1226..46eeadc 100644 --- a/Pokemon/Pokemon/Pokemons.cpp +++ b/Pokemon/Pokemon/Pokemons.cpp @@ -36,12 +36,12 @@ Pokemons::~Pokemons() } -void Pokemons::Attack(Pokemons &target_pokemon) -{ - int damage = attack_power; - cout << name << " inflicts an attack to " << target_pokemon.name << " that does " << damage << " damage!\n"; - target_pokemon.TakeDamage(damage); -} +//void Pokemons::Attack(Pokemons &target_pokemon) +//{ +// int damage = attack_power; +// cout << name << " inflicts an attack to " << target_pokemon.name << " that does " << damage << " damage!\n"; +// target_pokemon.TakeDamage(damage); +//} void Pokemons::TakeDamage(int damage) { diff --git a/Pokemon/Pokemon/Pokemons.hpp b/Pokemon/Pokemon/Pokemons.hpp index 857e8e5..1808acf 100644 --- a/Pokemon/Pokemon/Pokemons.hpp +++ b/Pokemon/Pokemon/Pokemons.hpp @@ -18,7 +18,7 @@ class Pokemons Pokemons(string poke_name, Pokemon_Types poke_type, int poke_health, int poke_max_health, int poke_attack_power); Pokemons(const Pokemons& other); ~Pokemons(); - void Attack(Pokemons &target_pokemon); + virtual void Attack(Pokemons &target_pokemon) = 0; void TakeDamage(int damage); bool IsFainted() const; void Heal(); From 39063b1881619d390bc1f15cd15b2af6482185ee Mon Sep 17 00:00:00 2001 From: rangamach <117797904+rangamach@users.noreply.github.com> Date: Tue, 5 Nov 2024 14:55:31 +0530 Subject: [PATCH 28/30] Fixed All Errors after changing Pokemons to abstract. --- Pokemon/Pokemon/BattleManager.cpp | 14 ++++----- Pokemon/Pokemon/BattleManager.hpp | 2 +- Pokemon/Pokemon/Bulbasaur.cpp | 17 ++++++----- Pokemon/Pokemon/Bulbasaur.hpp | 7 +++-- Pokemon/Pokemon/Caterpie.cpp | 16 +++++----- Pokemon/Pokemon/Caterpie.hpp | 6 ++-- Pokemon/Pokemon/Charmander.cpp | 15 ++++++---- Pokemon/Pokemon/Charmander.hpp | 6 ++-- Pokemon/Pokemon/Game.cpp | 29 ++++++++++++------- Pokemon/Pokemon/Game.hpp | 2 ++ Pokemon/Pokemon/Grass.hpp | 10 ++----- Pokemon/Pokemon/Pidgey.cpp | 15 ++++++---- Pokemon/Pokemon/Pidgey.hpp | 6 ++-- Pokemon/Pokemon/Pikachu.cpp | 15 ++++++---- Pokemon/Pokemon/Pikachu.hpp | 6 ++-- Pokemon/Pokemon/Player.cpp | 29 ++++++++++++++----- Pokemon/Pokemon/Player.hpp | 5 ++-- Pokemon/Pokemon/Pokemons.cpp | 5 ---- Pokemon/Pokemon/Pokemons.hpp | 5 ++-- Pokemon/Pokemon/ProfessorOak.cpp | 2 +- Pokemon/Pokemon/Squirtle.cpp | 15 ++++++---- Pokemon/Pokemon/Squirtle.hpp | 6 ++-- .../Pokemon/WildPokemonEncounterHandler.cpp | 4 ++- .../Pokemon/WildPokemonEncounterHandler.hpp | 2 +- Pokemon/Pokemon/Zubat.cpp | 15 ++++++---- Pokemon/Pokemon/Zubat.hpp | 6 ++-- 26 files changed, 156 insertions(+), 104 deletions(-) diff --git a/Pokemon/Pokemon/BattleManager.cpp b/Pokemon/Pokemon/BattleManager.cpp index 0417db6..b62ffdc 100644 --- a/Pokemon/Pokemon/BattleManager.cpp +++ b/Pokemon/Pokemon/BattleManager.cpp @@ -7,14 +7,14 @@ using namespace std; using namespace N_Utility; -void BattleManager::StartBattle(Player& player, Pokemons& wild_pokemon) +void BattleManager::StartBattle(Player& player, Pokemons* wild_pokemon) { - battle_state.player_pokemon = &player.captured_pokemon; - battle_state.wild_pokemon = &wild_pokemon; + battle_state.player_pokemon = player.captured_pokemon; + battle_state.wild_pokemon = wild_pokemon; battle_state.player_turn = true; battle_state.battle_unfinished = true; - cout << "A wild " << wild_pokemon.name << " appeared!\n"; - Battle(player.captured_pokemon, wild_pokemon); + cout << "A wild " << wild_pokemon->name << " appeared!\n"; + Battle(*player.captured_pokemon, *wild_pokemon); } void BattleManager::Battle(Pokemons& player_pokemon, Pokemons& wild_pokemon) @@ -22,9 +22,9 @@ void BattleManager::Battle(Pokemons& player_pokemon, Pokemons& wild_pokemon) while (battle_state.battle_unfinished) { if (battle_state.player_turn) - battle_state.player_pokemon->Attack(*battle_state.wild_pokemon); + battle_state.player_pokemon->Attack(battle_state.wild_pokemon); else - battle_state.wild_pokemon->Attack(*battle_state.player_pokemon); + battle_state.wild_pokemon->Attack(battle_state.player_pokemon); UpdateBattleState(); battle_state.player_turn = !battle_state.player_turn; Utility::WaitForEnter(); diff --git a/Pokemon/Pokemon/BattleManager.hpp b/Pokemon/Pokemon/BattleManager.hpp index 32ad311..803c42a 100644 --- a/Pokemon/Pokemon/BattleManager.hpp +++ b/Pokemon/Pokemon/BattleManager.hpp @@ -6,7 +6,7 @@ class Pokemons; class BattleManager { public: - void StartBattle(Player& player, Pokemons &wild_pokemon); + void StartBattle(Player& player, Pokemons *wild_pokemon); private: BattleState battle_state; void Battle(Pokemons &player_pokemon, Pokemons &wild_pokemon); diff --git a/Pokemon/Pokemon/Bulbasaur.cpp b/Pokemon/Pokemon/Bulbasaur.cpp index 60b0d05..382fb16 100644 --- a/Pokemon/Pokemon/Bulbasaur.cpp +++ b/Pokemon/Pokemon/Bulbasaur.cpp @@ -2,18 +2,19 @@ #include "PokemonType.hpp" #include -Bulbasaur::Bulbasaur() -{ - Pokemons("Bulbasaur", Pokemon_Types::Grass_Type, 100, 100, 35); -} +//Bulbasaur::Bulbasaur() +//{ +// //Pokemons("Bulbasaur", Pokemon_Types::Grass_Type, 100, 100, 35); +// //Bulbasaur::Bulbasaur("Bulbasaur", Pokemon_Types::Grass_Type, 100, 100, 35) : Pokemons("Bulbasaur", Pokemon_Types::Grass_Type, 100, 100, 35); +//} -void Bulbasaur::VineWhip(Pokemons& target_pokemon) +void Bulbasaur::VineWhip(Pokemons* target_pokemon) { - cout << name << " uses Vinewhip on " << target_pokemon.name << "!!!\n"; - target_pokemon.TakeDamage(35); + cout << name << " uses Vinewhip on " << target_pokemon->name << "!!!\n"; + target_pokemon->TakeDamage(35); } -void Bulbasaur::Attack(Pokemons& target_pokemon) +void Bulbasaur::Attack(Pokemons* target_pokemon) { VineWhip(target_pokemon); } \ No newline at end of file diff --git a/Pokemon/Pokemon/Bulbasaur.hpp b/Pokemon/Pokemon/Bulbasaur.hpp index 7a31ed2..45c0fd0 100644 --- a/Pokemon/Pokemon/Bulbasaur.hpp +++ b/Pokemon/Pokemon/Bulbasaur.hpp @@ -5,7 +5,10 @@ class Bulbasaur :public Pokemons { public: - Bulbasaur(); + Bulbasaur() : Pokemons("Bulbasaur", Pokemon_Types::Grass_Type, 100, 100, 35) {} ; + //Bulbasaur(string poke_name, Pokemon_Types poke_type, int poke_health, int poke_max_health, int poke_attack_power); private: - void VineWhip(Pokemons& target_pokemon); + void VineWhip(Pokemons* target_pokemon); + + void Attack(Pokemons* target_pokemon) override; }; \ No newline at end of file diff --git a/Pokemon/Pokemon/Caterpie.cpp b/Pokemon/Pokemon/Caterpie.cpp index 9eae37c..d197026 100644 --- a/Pokemon/Pokemon/Caterpie.cpp +++ b/Pokemon/Pokemon/Caterpie.cpp @@ -2,18 +2,18 @@ #include "PokemonType.hpp" #include -Caterpie::Caterpie() -{ - Pokemons("Caterpie", Pokemon_Types::Bug_Type, 100, 100, 10); -} +//Caterpie::Caterpie() +//{ +// Pokemons("Caterpie", Pokemon_Types::Bug_Type, 100, 100, 10); +//} -void Caterpie::BugBite(Pokemons& target_pokemon) +void Caterpie::BugBite(Pokemons* target_pokemon) { - cout << name << " uses Bugbite on " << target_pokemon.name << "!!!\n"; - target_pokemon.TakeDamage(20); + cout << name << " uses Bugbite on " << target_pokemon->name << "!!!\n"; + target_pokemon->TakeDamage(20); } -void Caterpie::Attack(Pokemons& target_pokemon) +void Caterpie::Attack(Pokemons* target_pokemon) { BugBite(target_pokemon); } \ No newline at end of file diff --git a/Pokemon/Pokemon/Caterpie.hpp b/Pokemon/Pokemon/Caterpie.hpp index e563246..f396c6f 100644 --- a/Pokemon/Pokemon/Caterpie.hpp +++ b/Pokemon/Pokemon/Caterpie.hpp @@ -5,7 +5,9 @@ class Caterpie :public Pokemons { public: - Caterpie(); + Caterpie() : Pokemons("Caterpie", Pokemon_Types::Bug_Type, 100, 100, 10) {}; private: - void BugBite(Pokemons& target_pokemon); + void BugBite(Pokemons* target_pokemon); + + void Attack(Pokemons* target_pokemon) override; }; \ No newline at end of file diff --git a/Pokemon/Pokemon/Charmander.cpp b/Pokemon/Pokemon/Charmander.cpp index 509b919..05dddb3 100644 --- a/Pokemon/Pokemon/Charmander.cpp +++ b/Pokemon/Pokemon/Charmander.cpp @@ -2,13 +2,18 @@ #include "PokemonType.hpp" #include -Charmander::Charmander() +//Charmander::Charmander() +//{ +// Pokemons("Charmander", Pokemon_Types::Fire_Type, 100, 100, 35); +//} + +void Charmander::FlameBurst(Pokemons* target_pokemon) { - Pokemons("Charmander", Pokemon_Types::Fire_Type, 100, 100, 35); + cout << name << " uses Flameburst on " << target_pokemon->name << "!!!\n"; + target_pokemon->TakeDamage(35); } -void Charmander::FlameBurst(Pokemons& target_pokemon) +void Charmander::Attack(Pokemons* target_pokemon) { - cout << name << " uses Flameburst on " << target_pokemon.name << "!!!\n"; - target_pokemon.TakeDamage(35); + FlameBurst(target_pokemon); } \ No newline at end of file diff --git a/Pokemon/Pokemon/Charmander.hpp b/Pokemon/Pokemon/Charmander.hpp index a8ba70c..88fb462 100644 --- a/Pokemon/Pokemon/Charmander.hpp +++ b/Pokemon/Pokemon/Charmander.hpp @@ -5,9 +5,9 @@ class Charmander :public Pokemons { public: - Charmander(); + Charmander() : Pokemons("Charmander", Pokemon_Types::Fire_Type, 100, 100, 35) {}; private: - void FlameBurst(Pokemons& target_pokemon); + void FlameBurst(Pokemons* target_pokemon); - void Attack(Pokemons& target_pokemon) override; + void Attack(Pokemons* target_pokemon) override; }; \ No newline at end of file diff --git a/Pokemon/Pokemon/Game.cpp b/Pokemon/Pokemon/Game.cpp index 6e5da90..7dbaa4d 100644 --- a/Pokemon/Pokemon/Game.cpp +++ b/Pokemon/Pokemon/Game.cpp @@ -4,6 +4,9 @@ #include "Utility.hpp" #include "WildPokemonEncounterHandler.hpp" #include "BattleManager.hpp" +#include "Pidgey.hpp" +#include "Zubat.hpp" +#include "Caterpie.hpp" #include @@ -14,12 +17,12 @@ using namespace N_Utility; Game::Game() { forest_grass = { - "Forest", - {{"Pidgey",Pokemon_Types::Normal_Type,40, 40, 2}, - {"Zubat",Pokemon_Types::Poison_Type,30, 30, 10}, - {"Caterpie",Pokemon_Types::Bug_Type,35, 35, 5}}, - 70 }; + "Forest", + {new Pidgey(),new Zubat(),new Caterpie()}, + 70 + }; } + void Game::GameLoop(Player &player) { BattleManager* battle_manager = new BattleManager(); @@ -41,17 +44,18 @@ void Game::GameLoop(Player &player) { case 1: { + // What pokemon will appear randomly while walking around. WildPokemonEncounterHandler encounters; - Pokemons encountered_pokemon = encounters.GetRandomWildPokemonFromGrass(forest_grass); + Pokemons* encountered_pokemon = encounters.GetRandomWildPokemonFromGrass(forest_grass); battle_manager->StartBattle(player,encountered_pokemon); - player.captured_pokemon.ShowHealth(player.captured_pokemon); break; } case 2: { - player.captured_pokemon.Heal(); - cout << player.captured_pokemon.name << "'s health is fully restored.\n"; - player.captured_pokemon.ShowHealth(player.captured_pokemon); + //player.captured_pokemon.Heal(); + wild_pokemon->Heal(); + //cout << player.captured_pokemon.name << "'s health is fully restored.\n"; + cout << wild_pokemon->name << "'s health is fully restored.\n"; break; } case 3: @@ -78,4 +82,9 @@ void Game::GameLoop(Player &player) } cout << "Goodbye, " << player.name << "! Thanks for playing!\n"; delete(battle_manager); +} + +Game::~Game() +{ + } \ No newline at end of file diff --git a/Pokemon/Pokemon/Game.hpp b/Pokemon/Pokemon/Game.hpp index e01f21b..367b163 100644 --- a/Pokemon/Pokemon/Game.hpp +++ b/Pokemon/Pokemon/Game.hpp @@ -6,7 +6,9 @@ class Game { private: Grass forest_grass; + Pokemons* wild_pokemon; public: Game(); + ~Game(); void GameLoop(Player &player); }; \ No newline at end of file diff --git a/Pokemon/Pokemon/Grass.hpp b/Pokemon/Pokemon/Grass.hpp index 9a98da9..4056d13 100644 --- a/Pokemon/Pokemon/Grass.hpp +++ b/Pokemon/Pokemon/Grass.hpp @@ -9,12 +9,6 @@ using namespace std; struct Grass { string environment; - vector wild_pokemons_list; + vector wild_pokemons_list; int pokemon_encounter_rate; -}; - -//Grass forestGrass = { -// "Cave", -// {{"Zubat",Pokemon_Types::Poison_Type,30},{"Geodude",Pokemon_Types::Rock_Type,50},{"Caterpie",Pokemon_Types::Bug_Type,10}}, -// 80 -//}; \ No newline at end of file +}; \ No newline at end of file diff --git a/Pokemon/Pokemon/Pidgey.cpp b/Pokemon/Pokemon/Pidgey.cpp index 19a261a..c49240e 100644 --- a/Pokemon/Pokemon/Pidgey.cpp +++ b/Pokemon/Pokemon/Pidgey.cpp @@ -2,13 +2,18 @@ #include "PokemonType.hpp" #include -Pidgey::Pidgey() +//Pidgey::Pidgey() +//{ +// Pokemons("Pidgey", Pokemon_Types::Normal_Type, 100, 100, 35); +//} + +void Pidgey::WingAttack(Pokemons* target_pokemon) { - Pokemons("Pidgey", Pokemon_Types::Normal_Type, 100, 100, 35); + cout << name << " uses Wingattack on " << target_pokemon->name << "!!!\n"; + target_pokemon->TakeDamage(20); } -void Pidgey::WingAttack(Pokemons& target_pokemon) +void Pidgey::Attack(Pokemons* target_pokemon) { - cout << name << " uses Wingattack on " << target_pokemon.name << "!!!\n"; - target_pokemon.TakeDamage(20); + WingAttack(target_pokemon); } \ No newline at end of file diff --git a/Pokemon/Pokemon/Pidgey.hpp b/Pokemon/Pokemon/Pidgey.hpp index 892ec3c..2adcc71 100644 --- a/Pokemon/Pokemon/Pidgey.hpp +++ b/Pokemon/Pokemon/Pidgey.hpp @@ -5,9 +5,9 @@ class Pidgey :public Pokemons { public: - Pidgey(); + Pidgey() : Pokemons("Pidgey", Pokemon_Types::Normal_Type, 100, 100, 35) {}; private: - void WingAttack(Pokemons& target_pokemon); + void WingAttack(Pokemons* target_pokemon); - void Attack(Pokemons& target_pokemon) override; + void Attack(Pokemons* target_pokemon) override; }; \ No newline at end of file diff --git a/Pokemon/Pokemon/Pikachu.cpp b/Pokemon/Pokemon/Pikachu.cpp index e0f0fba..dd14d1c 100644 --- a/Pokemon/Pokemon/Pikachu.cpp +++ b/Pokemon/Pokemon/Pikachu.cpp @@ -4,13 +4,18 @@ using namespace std; -Pikachu::Pikachu() +//Pikachu::Pikachu() +//{ +// //Pokemons("Pikachu", Pokemon_Types::Electric_Type, 100, 100, 15); +//} + +void Pikachu::ThunderShock(Pokemons* target_pokemon) { - Pokemons("Pikachu", Pokemon_Types::Electric_Type, 100, 100, 15); + cout << name << " uses Thundershock on " << target_pokemon->name << "!!!\n"; + target_pokemon->TakeDamage(20); } -void Pikachu::ThunderShock(Pokemons& target_pokemon) +void Pikachu::Attack(Pokemons* target_pokemon) { - cout << name << " uses Thundershock on " << target_pokemon.name << "!!!\n"; - target_pokemon.TakeDamage(20); + ThunderShock(target_pokemon); } \ No newline at end of file diff --git a/Pokemon/Pokemon/Pikachu.hpp b/Pokemon/Pokemon/Pikachu.hpp index a63ad25..3ebf9a8 100644 --- a/Pokemon/Pokemon/Pikachu.hpp +++ b/Pokemon/Pokemon/Pikachu.hpp @@ -5,7 +5,9 @@ class Pikachu : public Pokemons { public: - Pikachu(); + Pikachu() : Pokemons("Pikachu", Pokemon_Types::Electric_Type, 100, 100, 15) {}; private: - void ThunderShock(Pokemons& target_pokemon); + void ThunderShock(Pokemons* target_pokemon); + + void Attack(Pokemons* target_pokemon) override; }; diff --git a/Pokemon/Pokemon/Player.cpp b/Pokemon/Pokemon/Player.cpp index 5f35b82..4cd28bb 100644 --- a/Pokemon/Pokemon/Player.cpp +++ b/Pokemon/Pokemon/Player.cpp @@ -1,5 +1,9 @@ #include "Player.hpp" #include "Pokemons.hpp" +#include "Pikachu.hpp" +#include "Charmander.hpp" +#include "Bulbasaur.hpp" +#include "Squirtle.hpp" #include using namespace std; @@ -8,31 +12,40 @@ using namespace N_Utility; Player::Player() { - Player::captured_pokemon = Pokemons(); + } -Player::Player(string playerName, Pokemons playerCapturedPokemon) +//Player::Player(string playerName, Pokemons playerCapturedPokemon) +//{ +// Player::name = playerName; +// Player::captured_pokemon = playerCapturedPokemon; +//} + +Player::Player(string playerName) { Player::name = playerName; - Player::captured_pokemon = playerCapturedPokemon; } void Player::ChosenPokemon(int choice) { switch ((Pokemon_Choice)choice) { case Pokemon_Choice::Charmander: - Player::captured_pokemon = Pokemons("Charmander", Pokemon_Types::Fire_Type, 100, 100, 20); + //Player::captured_pokemon = Pokemons("Charmander", Pokemon_Types::Fire_Type, 100, 100, 20); + Player::captured_pokemon = new Charmander(); break; case Pokemon_Choice::Bulbasaur: - Player::captured_pokemon = Pokemons("Bulbasaur", Pokemon_Types::Grass_Type, 100, 100, 10); + //Player::captured_pokemon = Pokemons("Bulbasaur", Pokemon_Types::Grass_Type, 100, 100, 10); + Player::captured_pokemon = new Bulbasaur(); break; case Pokemon_Choice::Squirtle: - Player::captured_pokemon = Pokemons("Squirtle", Pokemon_Types::Water_Type, 100, 100, 15); + //Player::captured_pokemon = Pokemons("Squirtle", Pokemon_Types::Water_Type, 100, 100, 15); + Player::captured_pokemon = new Squirtle(); break; default: - Player::captured_pokemon = Pokemons("Pikachu", Pokemon_Types::Electric_Type, 100, 100, 20); + //Player::captured_pokemon = Pokemons("Pikachu", Pokemon_Types::Electric_Type, 100, 100, 20); + Player::captured_pokemon = new Pikachu(); break; } - cout << name << " chose " << captured_pokemon.name << "\n"; + cout << name << " chose " << captured_pokemon->name << "\n"; Utility::WaitForEnter(); } \ No newline at end of file diff --git a/Pokemon/Pokemon/Player.hpp b/Pokemon/Pokemon/Player.hpp index 53c977a..2fb122b 100644 --- a/Pokemon/Pokemon/Player.hpp +++ b/Pokemon/Pokemon/Player.hpp @@ -13,9 +13,10 @@ class Player { public: string name; - Pokemons captured_pokemon; + Pokemons* captured_pokemon; Player(); - Player(string playerName, Pokemons playerCapturedPokemon); + //Player(string playerName, Pokemons playerCapturedPokemon); + Player(string playerName); void ChosenPokemon(int choice); }; \ No newline at end of file diff --git a/Pokemon/Pokemon/Pokemons.cpp b/Pokemon/Pokemon/Pokemons.cpp index 46eeadc..92abf0b 100644 --- a/Pokemon/Pokemon/Pokemons.cpp +++ b/Pokemon/Pokemon/Pokemons.cpp @@ -60,11 +60,6 @@ void Pokemons::Heal() health = max_health; } -void Pokemons::ShowHealth(Pokemons pokemon) -{ - cout << "\n" << pokemon.name << "'s health is at " << pokemon.health << endl; -} - int Pokemons::GetHealth() { return health; diff --git a/Pokemon/Pokemon/Pokemons.hpp b/Pokemon/Pokemon/Pokemons.hpp index 1808acf..0d5a607 100644 --- a/Pokemon/Pokemon/Pokemons.hpp +++ b/Pokemon/Pokemon/Pokemons.hpp @@ -18,11 +18,10 @@ class Pokemons Pokemons(string poke_name, Pokemon_Types poke_type, int poke_health, int poke_max_health, int poke_attack_power); Pokemons(const Pokemons& other); ~Pokemons(); - virtual void Attack(Pokemons &target_pokemon) = 0; + virtual void Attack(Pokemons* target_pokemon) = 0; void TakeDamage(int damage); bool IsFainted() const; void Heal(); - void ShowHealth(Pokemons pokemon); int GetHealth(); void SetHealth(int updated_health); -}; \ No newline at end of file +}; diff --git a/Pokemon/Pokemon/ProfessorOak.cpp b/Pokemon/Pokemon/ProfessorOak.cpp index dc577c6..da16a90 100644 --- a/Pokemon/Pokemon/ProfessorOak.cpp +++ b/Pokemon/Pokemon/ProfessorOak.cpp @@ -44,7 +44,7 @@ void ProfessorOak::FirstPokemon(Player& player) cin >> choice; player.ChosenPokemon(choice); - cout << "Professor Oak: " << player.captured_pokemon.name << " and you, " << player.name << ", are going to be the best of friends!\n"; + cout << "Professor Oak: " << player.captured_pokemon->name << " and you, " << player.name << ", are going to be the best of friends!\n"; Utility::WaitForEnter(); } diff --git a/Pokemon/Pokemon/Squirtle.cpp b/Pokemon/Pokemon/Squirtle.cpp index 00ced77..56597cf 100644 --- a/Pokemon/Pokemon/Squirtle.cpp +++ b/Pokemon/Pokemon/Squirtle.cpp @@ -2,13 +2,18 @@ #include "PokemonType.hpp" #include -Squirtle::Squirtle() +//Squirtle::Squirtle() +//{ +// Pokemons("Squirtle", Pokemon_Types::Water_Type, 100, 100, 35); +//} + +void Squirtle::WaterSplash(Pokemons* target_pokemon) { - Pokemons("Squirtle", Pokemon_Types::Water_Type, 100, 100, 35); + cout << name << " uses Watersplash on " << target_pokemon->name << "!!!\n"; + target_pokemon->TakeDamage(35); } -void Squirtle::WaterSplash(Pokemons& target_pokemon) +void Squirtle::Attack(Pokemons* target_pokemon) { - cout << name << " uses Watersplash on " << target_pokemon.name << "!!!\n"; - target_pokemon.TakeDamage(35); + WaterSplash(target_pokemon); } \ No newline at end of file diff --git a/Pokemon/Pokemon/Squirtle.hpp b/Pokemon/Pokemon/Squirtle.hpp index a051f14..d12e040 100644 --- a/Pokemon/Pokemon/Squirtle.hpp +++ b/Pokemon/Pokemon/Squirtle.hpp @@ -5,7 +5,9 @@ class Squirtle :public Pokemons { public: - Squirtle(); + Squirtle() : Pokemons("Squirtle", Pokemon_Types::Water_Type, 100, 100, 35) {}; private: - void WaterSplash(Pokemons& target_pokemon); + void WaterSplash(Pokemons* target_pokemon); + + void Attack(Pokemons* target_pokemon) override; }; \ No newline at end of file diff --git a/Pokemon/Pokemon/WildPokemonEncounterHandler.cpp b/Pokemon/Pokemon/WildPokemonEncounterHandler.cpp index d508697..8b388eb 100644 --- a/Pokemon/Pokemon/WildPokemonEncounterHandler.cpp +++ b/Pokemon/Pokemon/WildPokemonEncounterHandler.cpp @@ -2,12 +2,14 @@ #include #include +using namespace std; + WildPokemonEncounterHandler::WildPokemonEncounterHandler() { srand(time(0)); } -Pokemons WildPokemonEncounterHandler::GetRandomWildPokemonFromGrass(const Grass& grass) +Pokemons* WildPokemonEncounterHandler::GetRandomWildPokemonFromGrass(const Grass& grass) { int random_index = rand() % grass.wild_pokemons_list.size(); return grass.wild_pokemons_list[random_index]; diff --git a/Pokemon/Pokemon/WildPokemonEncounterHandler.hpp b/Pokemon/Pokemon/WildPokemonEncounterHandler.hpp index 4bee1e9..6302acf 100644 --- a/Pokemon/Pokemon/WildPokemonEncounterHandler.hpp +++ b/Pokemon/Pokemon/WildPokemonEncounterHandler.hpp @@ -5,5 +5,5 @@ class WildPokemonEncounterHandler { public: WildPokemonEncounterHandler(); - Pokemons GetRandomWildPokemonFromGrass(const Grass& grass); + Pokemons* GetRandomWildPokemonFromGrass(const Grass& grass); }; \ No newline at end of file diff --git a/Pokemon/Pokemon/Zubat.cpp b/Pokemon/Pokemon/Zubat.cpp index 3a42c5d..4756b68 100644 --- a/Pokemon/Pokemon/Zubat.cpp +++ b/Pokemon/Pokemon/Zubat.cpp @@ -2,13 +2,18 @@ #include "Pokemons.hpp" #include -Zubat::Zubat() +//Zubat::Zubat() +//{ +// Pokemons("Zubat", Pokemon_Types::Poison_Type, 100, 100, 20); +//} + +void Zubat::SuperSonic(Pokemons* target_pokemon) { - Pokemons("Zubat", Pokemon_Types::Poison_Type, 100, 100, 20); + cout << name << " uses Supersonic on " << target_pokemon->name << "!!!\n"; + target_pokemon->TakeDamage(20); } -void Zubat::SuperSonic(Pokemons& target_pokemon) +void Zubat::Attack(Pokemons* target_pokemon) { - cout << name << " uses Supersonic on " << target_pokemon.name << "!!!\n"; - target_pokemon.TakeDamage(20); + SuperSonic(target_pokemon); } \ No newline at end of file diff --git a/Pokemon/Pokemon/Zubat.hpp b/Pokemon/Pokemon/Zubat.hpp index 1f26b39..26d7947 100644 --- a/Pokemon/Pokemon/Zubat.hpp +++ b/Pokemon/Pokemon/Zubat.hpp @@ -3,7 +3,9 @@ class Zubat :public Pokemons { public: - Zubat(); + Zubat() : Pokemons("Zubat", Pokemon_Types::Poison_Type, 100, 100, 20) {}; private: - void SuperSonic(Pokemons& target_pokemon); + void SuperSonic(Pokemons* target_pokemon); + + void Attack(Pokemons* target_pokemon) override; }; \ No newline at end of file From 8dc60487266fa797363d2b3ffc147de8a6a5d346 Mon Sep 17 00:00:00 2001 From: rangamach <117797904+rangamach@users.noreply.github.com> Date: Wed, 6 Nov 2024 14:55:21 +0530 Subject: [PATCH 29/30] Added unique battle dialogue. --- Pokemon/Pokemon/Bulbasaur.cpp | 14 ++++++++------ Pokemon/Pokemon/Bulbasaur.hpp | 1 - Pokemon/Pokemon/Caterpie.cpp | 13 ++++++++----- Pokemon/Pokemon/Charmander.cpp | 13 ++++++++----- Pokemon/Pokemon/Game.cpp | 6 ++---- Pokemon/Pokemon/Pidgey.cpp | 14 +++++++++----- Pokemon/Pokemon/Pikachu.cpp | 15 +++++++++------ Pokemon/Pokemon/Pokemons.cpp | 7 ------- Pokemon/Pokemon/Squirtle.cpp | 13 ++++++++----- Pokemon/Pokemon/WildPokemonEncounterHandler.cpp | 2 ++ Pokemon/Pokemon/Zubat.cpp | 13 ++++++++----- 11 files changed, 62 insertions(+), 49 deletions(-) diff --git a/Pokemon/Pokemon/Bulbasaur.cpp b/Pokemon/Pokemon/Bulbasaur.cpp index 382fb16..97968b7 100644 --- a/Pokemon/Pokemon/Bulbasaur.cpp +++ b/Pokemon/Pokemon/Bulbasaur.cpp @@ -1,17 +1,19 @@ #include "Bulbasaur.hpp" #include "PokemonType.hpp" +#include "Utility.hpp" #include -//Bulbasaur::Bulbasaur() -//{ -// //Pokemons("Bulbasaur", Pokemon_Types::Grass_Type, 100, 100, 35); -// //Bulbasaur::Bulbasaur("Bulbasaur", Pokemon_Types::Grass_Type, 100, 100, 35) : Pokemons("Bulbasaur", Pokemon_Types::Grass_Type, 100, 100, 35); -//} +using namespace N_Utility; void Bulbasaur::VineWhip(Pokemons* target_pokemon) { cout << name << " uses Vinewhip on " << target_pokemon->name << "!!!\n"; - target_pokemon->TakeDamage(35); + target_pokemon->TakeDamage(attack_power); + N_Utility::Utility::WaitForEnter(); + if (target_pokemon->IsFainted()) + cout << target_pokemon->name << " fainted!!!\n"; + else + cout << target_pokemon->name << " has " << target_pokemon->health << "HP left."; } void Bulbasaur::Attack(Pokemons* target_pokemon) diff --git a/Pokemon/Pokemon/Bulbasaur.hpp b/Pokemon/Pokemon/Bulbasaur.hpp index 45c0fd0..a7a84ca 100644 --- a/Pokemon/Pokemon/Bulbasaur.hpp +++ b/Pokemon/Pokemon/Bulbasaur.hpp @@ -6,7 +6,6 @@ class Bulbasaur :public Pokemons { public: Bulbasaur() : Pokemons("Bulbasaur", Pokemon_Types::Grass_Type, 100, 100, 35) {} ; - //Bulbasaur(string poke_name, Pokemon_Types poke_type, int poke_health, int poke_max_health, int poke_attack_power); private: void VineWhip(Pokemons* target_pokemon); diff --git a/Pokemon/Pokemon/Caterpie.cpp b/Pokemon/Pokemon/Caterpie.cpp index d197026..77260fc 100644 --- a/Pokemon/Pokemon/Caterpie.cpp +++ b/Pokemon/Pokemon/Caterpie.cpp @@ -1,16 +1,19 @@ #include "Caterpie.hpp" #include "PokemonType.hpp" +#include "Utility.hpp" #include -//Caterpie::Caterpie() -//{ -// Pokemons("Caterpie", Pokemon_Types::Bug_Type, 100, 100, 10); -//} +using namespace N_Utility; void Caterpie::BugBite(Pokemons* target_pokemon) { cout << name << " uses Bugbite on " << target_pokemon->name << "!!!\n"; - target_pokemon->TakeDamage(20); + target_pokemon->TakeDamage(attack_power); + N_Utility::Utility::WaitForEnter(); + if (target_pokemon->IsFainted()) + cout << target_pokemon->name << " fainted!!!\n"; + else + cout << target_pokemon->name << " has " << target_pokemon->health << "HP left."; } void Caterpie::Attack(Pokemons* target_pokemon) diff --git a/Pokemon/Pokemon/Charmander.cpp b/Pokemon/Pokemon/Charmander.cpp index 05dddb3..54edc97 100644 --- a/Pokemon/Pokemon/Charmander.cpp +++ b/Pokemon/Pokemon/Charmander.cpp @@ -1,16 +1,19 @@ #include "Charmander.hpp" #include "PokemonType.hpp" +#include "Utility.hpp" #include -//Charmander::Charmander() -//{ -// Pokemons("Charmander", Pokemon_Types::Fire_Type, 100, 100, 35); -//} +using namespace N_Utility; void Charmander::FlameBurst(Pokemons* target_pokemon) { cout << name << " uses Flameburst on " << target_pokemon->name << "!!!\n"; - target_pokemon->TakeDamage(35); + target_pokemon->TakeDamage(attack_power); + N_Utility::Utility::WaitForEnter(); + if (target_pokemon->IsFainted()) + cout << target_pokemon->name << " fainted!!!\n"; + else + cout << target_pokemon->name << " has " << target_pokemon->health << "HP left."; } void Charmander::Attack(Pokemons* target_pokemon) diff --git a/Pokemon/Pokemon/Game.cpp b/Pokemon/Pokemon/Game.cpp index 7dbaa4d..6fcd2e8 100644 --- a/Pokemon/Pokemon/Game.cpp +++ b/Pokemon/Pokemon/Game.cpp @@ -52,10 +52,8 @@ void Game::GameLoop(Player &player) } case 2: { - //player.captured_pokemon.Heal(); - wild_pokemon->Heal(); - //cout << player.captured_pokemon.name << "'s health is fully restored.\n"; - cout << wild_pokemon->name << "'s health is fully restored.\n"; + player.captured_pokemon->Heal(); + cout << player.captured_pokemon->name << "'s health is fully restored.\n"; break; } case 3: diff --git a/Pokemon/Pokemon/Pidgey.cpp b/Pokemon/Pokemon/Pidgey.cpp index c49240e..360450a 100644 --- a/Pokemon/Pokemon/Pidgey.cpp +++ b/Pokemon/Pokemon/Pidgey.cpp @@ -1,16 +1,20 @@ #include "Pidgey.hpp" #include "PokemonType.hpp" +#include "Utility.hpp" #include -//Pidgey::Pidgey() -//{ -// Pokemons("Pidgey", Pokemon_Types::Normal_Type, 100, 100, 35); -//} +using namespace N_Utility; void Pidgey::WingAttack(Pokemons* target_pokemon) { cout << name << " uses Wingattack on " << target_pokemon->name << "!!!\n"; - target_pokemon->TakeDamage(20); + target_pokemon->TakeDamage(attack_power); + N_Utility::Utility::WaitForEnter(); + if (target_pokemon->IsFainted()) + cout << target_pokemon->name << " fainted!!!\n"; + else + cout << target_pokemon->name << " has " << target_pokemon->health << "HP left."; + } void Pidgey::Attack(Pokemons* target_pokemon) diff --git a/Pokemon/Pokemon/Pikachu.cpp b/Pokemon/Pokemon/Pikachu.cpp index dd14d1c..0a7f282 100644 --- a/Pokemon/Pokemon/Pikachu.cpp +++ b/Pokemon/Pokemon/Pikachu.cpp @@ -1,18 +1,21 @@ #include "Pikachu.hpp" #include "PokemonType.hpp" +#include "Utility.hpp" #include -using namespace std; +using namespace N_Utility; -//Pikachu::Pikachu() -//{ -// //Pokemons("Pikachu", Pokemon_Types::Electric_Type, 100, 100, 15); -//} +using namespace std; void Pikachu::ThunderShock(Pokemons* target_pokemon) { cout << name << " uses Thundershock on " << target_pokemon->name << "!!!\n"; - target_pokemon->TakeDamage(20); + target_pokemon->TakeDamage(attack_power); + N_Utility::Utility::WaitForEnter(); + if (target_pokemon->IsFainted()) + cout << target_pokemon->name << " fainted!!!\n"; + else + cout << target_pokemon->name << " has " << target_pokemon->health << "HP left."; } void Pikachu::Attack(Pokemons* target_pokemon) diff --git a/Pokemon/Pokemon/Pokemons.cpp b/Pokemon/Pokemon/Pokemons.cpp index 92abf0b..9f85916 100644 --- a/Pokemon/Pokemon/Pokemons.cpp +++ b/Pokemon/Pokemon/Pokemons.cpp @@ -36,13 +36,6 @@ Pokemons::~Pokemons() } -//void Pokemons::Attack(Pokemons &target_pokemon) -//{ -// int damage = attack_power; -// cout << name << " inflicts an attack to " << target_pokemon.name << " that does " << damage << " damage!\n"; -// target_pokemon.TakeDamage(damage); -//} - void Pokemons::TakeDamage(int damage) { health -= damage; diff --git a/Pokemon/Pokemon/Squirtle.cpp b/Pokemon/Pokemon/Squirtle.cpp index 56597cf..37254c9 100644 --- a/Pokemon/Pokemon/Squirtle.cpp +++ b/Pokemon/Pokemon/Squirtle.cpp @@ -1,16 +1,19 @@ #include "Squirtle.hpp" #include "PokemonType.hpp" +#include "Utility.hpp" #include -//Squirtle::Squirtle() -//{ -// Pokemons("Squirtle", Pokemon_Types::Water_Type, 100, 100, 35); -//} +using namespace N_Utility; void Squirtle::WaterSplash(Pokemons* target_pokemon) { cout << name << " uses Watersplash on " << target_pokemon->name << "!!!\n"; - target_pokemon->TakeDamage(35); + target_pokemon->TakeDamage(attack_power); + N_Utility::Utility::WaitForEnter(); + if (target_pokemon->IsFainted()) + cout << target_pokemon->name << " fainted!!!\n"; + else + cout << target_pokemon->name << " has " << target_pokemon->health << "HP left."; } void Squirtle::Attack(Pokemons* target_pokemon) diff --git a/Pokemon/Pokemon/WildPokemonEncounterHandler.cpp b/Pokemon/Pokemon/WildPokemonEncounterHandler.cpp index 8b388eb..364bb68 100644 --- a/Pokemon/Pokemon/WildPokemonEncounterHandler.cpp +++ b/Pokemon/Pokemon/WildPokemonEncounterHandler.cpp @@ -12,5 +12,7 @@ WildPokemonEncounterHandler::WildPokemonEncounterHandler() Pokemons* WildPokemonEncounterHandler::GetRandomWildPokemonFromGrass(const Grass& grass) { int random_index = rand() % grass.wild_pokemons_list.size(); + if (grass.wild_pokemons_list[random_index]->health == 0) + grass.wild_pokemons_list[random_index]->Heal(); return grass.wild_pokemons_list[random_index]; } diff --git a/Pokemon/Pokemon/Zubat.cpp b/Pokemon/Pokemon/Zubat.cpp index 4756b68..eeb7c49 100644 --- a/Pokemon/Pokemon/Zubat.cpp +++ b/Pokemon/Pokemon/Zubat.cpp @@ -1,16 +1,19 @@ #include "Zubat.hpp" #include "Pokemons.hpp" +#include "Utility.hpp" #include -//Zubat::Zubat() -//{ -// Pokemons("Zubat", Pokemon_Types::Poison_Type, 100, 100, 20); -//} +using namespace N_Utility; void Zubat::SuperSonic(Pokemons* target_pokemon) { cout << name << " uses Supersonic on " << target_pokemon->name << "!!!\n"; - target_pokemon->TakeDamage(20); + target_pokemon->TakeDamage(attack_power); + N_Utility::Utility::WaitForEnter(); + if (target_pokemon->IsFainted()) + cout << target_pokemon->name << " fainted!!!\n"; + else + cout << target_pokemon->name << " has " << target_pokemon->health << "HP left."; } void Zubat::Attack(Pokemons* target_pokemon) From e4afc0173d386116d32eabffffee04e4acfa8421 Mon Sep 17 00:00:00 2001 From: rangamach <117797904+rangamach@users.noreply.github.com> Date: Thu, 7 Nov 2024 10:47:54 +0530 Subject: [PATCH 30/30] Added Special Moves to Pokemon. --- Pokemon/Pokemon/BattleManager.cpp | 10 ++-- Pokemon/Pokemon/BattleManager.hpp | 2 +- Pokemon/Pokemon/Bulbasaur.cpp | 36 ++++++++----- Pokemon/Pokemon/Bulbasaur.hpp | 8 +-- Pokemon/Pokemon/Caterpie.cpp | 32 ++++++----- Pokemon/Pokemon/Caterpie.hpp | 8 +-- Pokemon/Pokemon/Charmander.cpp | 31 ++++++----- Pokemon/Pokemon/Charmander.hpp | 8 +-- Pokemon/Pokemon/Pidgey.cpp | 37 ++++++++----- Pokemon/Pokemon/Pidgey.hpp | 8 +-- Pokemon/Pokemon/Pikachu.cpp | 39 +++++++++----- Pokemon/Pokemon/Pikachu.hpp | 8 +-- Pokemon/Pokemon/Pokemon.vcxproj | 1 + Pokemon/Pokemon/Pokemon.vcxproj.filters | 3 ++ Pokemon/Pokemon/PokemonMove.hpp | 17 ++++++ Pokemon/Pokemon/Pokemons.cpp | 71 +++++++++++++++++++++++-- Pokemon/Pokemon/Pokemons.hpp | 17 ++++-- Pokemon/Pokemon/Squirtle.cpp | 33 +++++++----- Pokemon/Pokemon/Squirtle.hpp | 8 +-- Pokemon/Pokemon/Zubat.cpp | 32 ++++++----- Pokemon/Pokemon/Zubat.hpp | 8 +-- 21 files changed, 300 insertions(+), 117 deletions(-) create mode 100644 Pokemon/Pokemon/PokemonMove.hpp diff --git a/Pokemon/Pokemon/BattleManager.cpp b/Pokemon/Pokemon/BattleManager.cpp index b62ffdc..4d1fabf 100644 --- a/Pokemon/Pokemon/BattleManager.cpp +++ b/Pokemon/Pokemon/BattleManager.cpp @@ -14,17 +14,19 @@ void BattleManager::StartBattle(Player& player, Pokemons* wild_pokemon) battle_state.player_turn = true; battle_state.battle_unfinished = true; cout << "A wild " << wild_pokemon->name << " appeared!\n"; - Battle(*player.captured_pokemon, *wild_pokemon); + Battle(*player.captured_pokemon, wild_pokemon); } -void BattleManager::Battle(Pokemons& player_pokemon, Pokemons& wild_pokemon) +void BattleManager::Battle(Pokemons& player_pokemon, Pokemons* wild_pokemon) { while (battle_state.battle_unfinished) { if (battle_state.player_turn) - battle_state.player_pokemon->Attack(battle_state.wild_pokemon); + //battle_state.player_pokemon->Attack(battle_state.wild_pokemon); + battle_state.player_pokemon->SelectAndExecuteMove(wild_pokemon); else - battle_state.wild_pokemon->Attack(battle_state.player_pokemon); + //battle_state.wild_pokemon->Attack(battle_state.player_pokemon); + battle_state.wild_pokemon->SelectAndExecuteMove(battle_state.player_pokemon); UpdateBattleState(); battle_state.player_turn = !battle_state.player_turn; Utility::WaitForEnter(); diff --git a/Pokemon/Pokemon/BattleManager.hpp b/Pokemon/Pokemon/BattleManager.hpp index 803c42a..6867e30 100644 --- a/Pokemon/Pokemon/BattleManager.hpp +++ b/Pokemon/Pokemon/BattleManager.hpp @@ -9,7 +9,7 @@ class BattleManager void StartBattle(Player& player, Pokemons *wild_pokemon); private: BattleState battle_state; - void Battle(Pokemons &player_pokemon, Pokemons &wild_pokemon); + void Battle(Pokemons &player_pokemon, Pokemons* wild_pokemon); void BattleOutcome(); void UpdateBattleState(); }; \ No newline at end of file diff --git a/Pokemon/Pokemon/Bulbasaur.cpp b/Pokemon/Pokemon/Bulbasaur.cpp index 97968b7..9523b13 100644 --- a/Pokemon/Pokemon/Bulbasaur.cpp +++ b/Pokemon/Pokemon/Bulbasaur.cpp @@ -5,18 +5,30 @@ using namespace N_Utility; -void Bulbasaur::VineWhip(Pokemons* target_pokemon) -{ - cout << name << " uses Vinewhip on " << target_pokemon->name << "!!!\n"; - target_pokemon->TakeDamage(attack_power); - N_Utility::Utility::WaitForEnter(); - if (target_pokemon->IsFainted()) - cout << target_pokemon->name << " fainted!!!\n"; - else - cout << target_pokemon->name << " has " << target_pokemon->health << "HP left."; -} +//void Bulbasaur::VineWhip(Pokemons* target_pokemon) +//{ +// cout << name << " uses Vinewhip on " << target_pokemon->name << "!!!\n"; +// target_pokemon->TakeDamage(attack_power); +// N_Utility::Utility::WaitForEnter(); +// if (target_pokemon->IsFainted()) +// cout << target_pokemon->name << " fainted!!!\n"; +// else +// cout << target_pokemon->name << " has " << target_pokemon->health << "HP left."; +//} -void Bulbasaur::Attack(Pokemons* target_pokemon) +void Bulbasaur::Attack(PokemonMove selected_move, Pokemons* target_pokemon) { - VineWhip(target_pokemon); + Pokemons::Attack(selected_move, target_pokemon); + if (selected_move.move_name == "Vine Whip") + { + int second_hit_chance = rand() % 2; + if (second_hit_chance == 1) + { + Pokemons::Attack(selected_move, target_pokemon); + cout << name << " hits again with a second " << selected_move.move_name << "!!!\n"; + } + else + cout << target_pokemon->name << " dodged the second hit!!!\n"; + } + //VineWhip(target_pokemon); } \ No newline at end of file diff --git a/Pokemon/Pokemon/Bulbasaur.hpp b/Pokemon/Pokemon/Bulbasaur.hpp index a7a84ca..94a9e4c 100644 --- a/Pokemon/Pokemon/Bulbasaur.hpp +++ b/Pokemon/Pokemon/Bulbasaur.hpp @@ -1,13 +1,15 @@ #pragma once #include "Pokemons.hpp" +#include "PokemonMove.hpp" +#include "PokemonType.hpp" class Bulbasaur :public Pokemons { public: - Bulbasaur() : Pokemons("Bulbasaur", Pokemon_Types::Grass_Type, 100, 100, 35) {} ; + Bulbasaur() : Pokemons("Bulbasaur", Pokemon_Types::Grass_Type, 100, 100, {{"Vine Whip", 25},{"Tackle", 10}}) {}; private: - void VineWhip(Pokemons* target_pokemon); + //void VineWhip(Pokemons* target_pokemon); - void Attack(Pokemons* target_pokemon) override; + void Attack(PokemonMove selected_move, Pokemons* target_pokemon) override; }; \ No newline at end of file diff --git a/Pokemon/Pokemon/Caterpie.cpp b/Pokemon/Pokemon/Caterpie.cpp index 77260fc..a58504d 100644 --- a/Pokemon/Pokemon/Caterpie.cpp +++ b/Pokemon/Pokemon/Caterpie.cpp @@ -1,22 +1,30 @@ #include "Caterpie.hpp" #include "PokemonType.hpp" #include "Utility.hpp" +#include "PokemonMove.hpp" #include using namespace N_Utility; -void Caterpie::BugBite(Pokemons* target_pokemon) -{ - cout << name << " uses Bugbite on " << target_pokemon->name << "!!!\n"; - target_pokemon->TakeDamage(attack_power); - N_Utility::Utility::WaitForEnter(); - if (target_pokemon->IsFainted()) - cout << target_pokemon->name << " fainted!!!\n"; - else - cout << target_pokemon->name << " has " << target_pokemon->health << "HP left."; -} +//void Caterpie::BugBite(Pokemons* target_pokemon) +//{ +// cout << name << " uses Bugbite on " << target_pokemon->name << "!!!\n"; +// target_pokemon->TakeDamage(attack_power); +// N_Utility::Utility::WaitForEnter(); +// if (target_pokemon->IsFainted()) +// cout << target_pokemon->name << " fainted!!!\n"; +// else +// cout << target_pokemon->name << " has " << target_pokemon->health << "HP left."; +//} -void Caterpie::Attack(Pokemons* target_pokemon) +void Caterpie::Attack(PokemonMove selected_move, Pokemons* target_pokemon) { - BugBite(target_pokemon); + Pokemons::Attack(selected_move, target_pokemon); + if (selected_move.move_name == "Sticky Web") + { + target_pokemon->ReduceAttackPower(5); + cout << target_pokemon->name << "'s next attack will be reduced by 5 damage!\n"; + N_Utility::Utility::WaitForEnter(); + } + //BugBite(target_pokemon); } \ No newline at end of file diff --git a/Pokemon/Pokemon/Caterpie.hpp b/Pokemon/Pokemon/Caterpie.hpp index f396c6f..f5e27c7 100644 --- a/Pokemon/Pokemon/Caterpie.hpp +++ b/Pokemon/Pokemon/Caterpie.hpp @@ -1,13 +1,15 @@ #pragma once #include "Pokemons.hpp" +#include "PokemonMove.hpp" +#include "PokemonType.hpp" class Caterpie :public Pokemons { public: - Caterpie() : Pokemons("Caterpie", Pokemon_Types::Bug_Type, 100, 100, 10) {}; + Caterpie() : Pokemons("Caterpie", Pokemon_Types::Bug_Type, 100, 100, {{"Sticky Web",10},{"Bug Bite",25}}) {}; private: - void BugBite(Pokemons* target_pokemon); + //void BugBite(Pokemons* target_pokemon); - void Attack(Pokemons* target_pokemon) override; + void Attack(PokemonMove selected_move, Pokemons* target_pokemon) override; }; \ No newline at end of file diff --git a/Pokemon/Pokemon/Charmander.cpp b/Pokemon/Pokemon/Charmander.cpp index 54edc97..b30035f 100644 --- a/Pokemon/Pokemon/Charmander.cpp +++ b/Pokemon/Pokemon/Charmander.cpp @@ -5,18 +5,25 @@ using namespace N_Utility; -void Charmander::FlameBurst(Pokemons* target_pokemon) -{ - cout << name << " uses Flameburst on " << target_pokemon->name << "!!!\n"; - target_pokemon->TakeDamage(attack_power); - N_Utility::Utility::WaitForEnter(); - if (target_pokemon->IsFainted()) - cout << target_pokemon->name << " fainted!!!\n"; - else - cout << target_pokemon->name << " has " << target_pokemon->health << "HP left."; -} +//void Charmander::FlameBurst(Pokemons* target_pokemon) +//{ +// cout << name << " uses Flameburst on " << target_pokemon->name << "!!!\n"; +// target_pokemon->TakeDamage(attack_power); +// N_Utility::Utility::WaitForEnter(); +// if (target_pokemon->IsFainted()) +// cout << target_pokemon->name << " fainted!!!\n"; +// else +// cout << target_pokemon->name << " has " << target_pokemon->health << "HP left."; +//} -void Charmander::Attack(Pokemons* target_pokemon) +void Charmander::Attack(PokemonMove selected_move, Pokemons* target_pokemon) { - FlameBurst(target_pokemon); + Pokemons::Attack(selected_move, target_pokemon); + if (selected_move.move_name == "Blazing Charge") + { + this->TakeDamage(10); + cout << name << " takes 10 recoil damage from the Blazing Charge!!!\n"; + N_Utility::Utility::WaitForEnter(); + } + //FlameBurst(target_pokemon); } \ No newline at end of file diff --git a/Pokemon/Pokemon/Charmander.hpp b/Pokemon/Pokemon/Charmander.hpp index 88fb462..14cc0b9 100644 --- a/Pokemon/Pokemon/Charmander.hpp +++ b/Pokemon/Pokemon/Charmander.hpp @@ -1,13 +1,15 @@ #pragma once #include "Pokemons.hpp" +#include "PokemonMove.hpp" +#include "PokemonType.hpp" class Charmander :public Pokemons { public: - Charmander() : Pokemons("Charmander", Pokemon_Types::Fire_Type, 100, 100, 35) {}; + Charmander() : Pokemons("Charmander", Pokemon_Types::Fire_Type, 100, 100, {{"Flameburst",35},{"Blazing Charge",70}}) {}; private: - void FlameBurst(Pokemons* target_pokemon); + //void FlameBurst(Pokemons* target_pokemon); - void Attack(Pokemons* target_pokemon) override; + void Attack(PokemonMove selected_move, Pokemons* target_pokemon) override; }; \ No newline at end of file diff --git a/Pokemon/Pokemon/Pidgey.cpp b/Pokemon/Pokemon/Pidgey.cpp index 360450a..86c6c10 100644 --- a/Pokemon/Pokemon/Pidgey.cpp +++ b/Pokemon/Pokemon/Pidgey.cpp @@ -1,23 +1,34 @@ #include "Pidgey.hpp" #include "PokemonType.hpp" #include "Utility.hpp" +#include "PokemonMove.hpp" +#include "BattleManager.hpp" #include using namespace N_Utility; -void Pidgey::WingAttack(Pokemons* target_pokemon) -{ - cout << name << " uses Wingattack on " << target_pokemon->name << "!!!\n"; - target_pokemon->TakeDamage(attack_power); - N_Utility::Utility::WaitForEnter(); - if (target_pokemon->IsFainted()) - cout << target_pokemon->name << " fainted!!!\n"; - else - cout << target_pokemon->name << " has " << target_pokemon->health << "HP left."; - -} +//void Pidgey::WingAttack(Pokemons* target_pokemon) +//{ +// cout << name << " uses Wingattack on " << target_pokemon->name << "!!!\n"; +// target_pokemon->TakeDamage(attack_power); +// N_Utility::Utility::WaitForEnter(); +// if (target_pokemon->IsFainted()) +// cout << target_pokemon->name << " fainted!!!\n"; +// else +// cout << target_pokemon->name << " has " << target_pokemon->health << "HP left."; +// +//} -void Pidgey::Attack(Pokemons* target_pokemon) +void Pidgey::Attack(PokemonMove seleccted_move, Pokemons* target_pokemon) { - WingAttack(target_pokemon); + Pokemons::Attack(seleccted_move, target_pokemon); + if (seleccted_move.move_name == "Gust") + { + if (rand() % 100 < 20) + { + cout << this->name << " blew " << target_pokemon->name << " away!!!\n"; + target_pokemon->health = 0; + } + } + //WingAttack(target_pokemon); } \ No newline at end of file diff --git a/Pokemon/Pokemon/Pidgey.hpp b/Pokemon/Pokemon/Pidgey.hpp index 2adcc71..c988a2b 100644 --- a/Pokemon/Pokemon/Pidgey.hpp +++ b/Pokemon/Pokemon/Pidgey.hpp @@ -1,13 +1,15 @@ #pragma once #include "Pokemons.hpp" +#include "PokemonMove.hpp" +#include "PokemonType.hpp" class Pidgey :public Pokemons { public: - Pidgey() : Pokemons("Pidgey", Pokemon_Types::Normal_Type, 100, 100, 35) {}; + Pidgey() : Pokemons("Pidgey", Pokemon_Types::Normal_Type, 100, 100, {{"Wing Attack",35},{"Gust",15}}) {}; private: - void WingAttack(Pokemons* target_pokemon); + //void WingAttack(Pokemons* target_pokemon); - void Attack(Pokemons* target_pokemon) override; + void Attack(PokemonMove selected_move, Pokemons* target_pokemon) override; }; \ No newline at end of file diff --git a/Pokemon/Pokemon/Pikachu.cpp b/Pokemon/Pokemon/Pikachu.cpp index 0a7f282..4a160c3 100644 --- a/Pokemon/Pokemon/Pikachu.cpp +++ b/Pokemon/Pokemon/Pikachu.cpp @@ -1,24 +1,39 @@ #include "Pikachu.hpp" #include "PokemonType.hpp" #include "Utility.hpp" +#include "PokemonMove.hpp" #include using namespace N_Utility; using namespace std; -void Pikachu::ThunderShock(Pokemons* target_pokemon) -{ - cout << name << " uses Thundershock on " << target_pokemon->name << "!!!\n"; - target_pokemon->TakeDamage(attack_power); - N_Utility::Utility::WaitForEnter(); - if (target_pokemon->IsFainted()) - cout << target_pokemon->name << " fainted!!!\n"; - else - cout << target_pokemon->name << " has " << target_pokemon->health << "HP left."; -} +//void Pikachu::ThunderShock(Pokemons* target_pokemon) +//{ +// cout << name << " uses Thundershock on " << target_pokemon->name << "!!!\n"; +// target_pokemon->TakeDamage(attack_power); +// N_Utility::Utility::WaitForEnter(); +// if (target_pokemon->IsFainted()) +// cout << target_pokemon->name << " fainted!!!\n"; +// else +// cout << target_pokemon->name << " has " << target_pokemon->health << "HP left."; +//} -void Pikachu::Attack(Pokemons* target_pokemon) +void Pikachu::Attack(PokemonMove selected_move, Pokemons* target_pokemon) { - ThunderShock(target_pokemon); + if (selected_move.move_name == "Thunderbolt") + { + if (rand() % 100 < 80) + { + Pokemons::Attack(selected_move, target_pokemon); + cout << this->name << " hit " << target_pokemon->name << " successfully!!!\n"; + } + else + { + cout << this->name << " missed " << target_pokemon->name << "!!!\n"; + } + } + else + Pokemons::Attack(selected_move, target_pokemon); + //ThunderShock(target_pokemon); } \ No newline at end of file diff --git a/Pokemon/Pokemon/Pikachu.hpp b/Pokemon/Pokemon/Pikachu.hpp index 3ebf9a8..67f5888 100644 --- a/Pokemon/Pokemon/Pikachu.hpp +++ b/Pokemon/Pokemon/Pikachu.hpp @@ -1,13 +1,15 @@ #pragma once #include "Pokemons.hpp" +#include "PokemonMove.hpp" +#include "PokemonType.hpp" class Pikachu : public Pokemons { public: - Pikachu() : Pokemons("Pikachu", Pokemon_Types::Electric_Type, 100, 100, 15) {}; + Pikachu() : Pokemons("Pikachu", Pokemon_Types::Electric_Type, 100, 100, { {"Thundershock",15},{"Thunderbolt",80}}) {}; private: - void ThunderShock(Pokemons* target_pokemon); + //void ThunderShock(Pokemons* target_pokemon); - void Attack(Pokemons* target_pokemon) override; + void Attack(PokemonMove selected_move, Pokemons* target_pokemon) override; }; diff --git a/Pokemon/Pokemon/Pokemon.vcxproj b/Pokemon/Pokemon/Pokemon.vcxproj index cc5d425..2404748 100644 --- a/Pokemon/Pokemon/Pokemon.vcxproj +++ b/Pokemon/Pokemon/Pokemon.vcxproj @@ -156,6 +156,7 @@ + diff --git a/Pokemon/Pokemon/Pokemon.vcxproj.filters b/Pokemon/Pokemon/Pokemon.vcxproj.filters index 77c812a..78c2d9b 100644 --- a/Pokemon/Pokemon/Pokemon.vcxproj.filters +++ b/Pokemon/Pokemon/Pokemon.vcxproj.filters @@ -119,5 +119,8 @@ Header Files + + Header Files + \ No newline at end of file diff --git a/Pokemon/Pokemon/PokemonMove.hpp b/Pokemon/Pokemon/PokemonMove.hpp new file mode 100644 index 0000000..70bcae9 --- /dev/null +++ b/Pokemon/Pokemon/PokemonMove.hpp @@ -0,0 +1,17 @@ +#pragma once +#include +#include "Pokemons.hpp" + +using namespace std; + +struct PokemonMove +{ + string move_name; + int move_power; + + PokemonMove(const string& pokemon_move_name, int pokemon_move_power) + { + move_name = pokemon_move_name; + move_power = pokemon_move_power; + } +}; \ No newline at end of file diff --git a/Pokemon/Pokemon/Pokemons.cpp b/Pokemon/Pokemon/Pokemons.cpp index 9f85916..d126dff 100644 --- a/Pokemon/Pokemon/Pokemons.cpp +++ b/Pokemon/Pokemon/Pokemons.cpp @@ -1,9 +1,13 @@ #include #include "Pokemons.hpp" #include "PokemonType.hpp" +#include "PokemonMove.hpp" +#include "Utility.hpp" using namespace std; +using namespace N_Utility; + Pokemons::Pokemons() { Pokemons::name = "Unknown"; @@ -11,15 +15,25 @@ Pokemons::Pokemons() Pokemons::health = 50; Pokemons::max_health = 100; Pokemons::attack_power = 10; + Pokemons::pokemon_moves = {}; } -Pokemons::Pokemons(string poke_name, Pokemon_Types poke_type, int poke_health, int poke_max_health, int poke_attack_power) +//Pokemons::Pokemons(string poke_name, Pokemon_Types poke_type, int poke_health, int poke_max_health, int poke_attack_power) +//{ +// Pokemons::name = poke_name; +// Pokemons::type = poke_type; +// Pokemons::health = poke_health; +// Pokemons::max_health = poke_max_health; +// Pokemons::attack_power = poke_attack_power; +//} + +Pokemons::Pokemons(string poke_name, Pokemon_Types poke_type, int poke_health, int poke_max_health, vector pokemon_moves_list) { Pokemons::name = poke_name; Pokemons::type = poke_type; Pokemons::health = poke_health; Pokemons::max_health = poke_max_health; - Pokemons::attack_power = poke_attack_power; + Pokemons::pokemon_moves = pokemon_moves_list; } Pokemons::Pokemons(const Pokemons& other) @@ -28,7 +42,8 @@ Pokemons::Pokemons(const Pokemons& other) Pokemons::type = other.type; Pokemons::health = other.health; Pokemons::max_health = other.max_health; - Pokemons::attack_power = other.attack_power; + //Pokemons::attack_power = other.attack_power; + Pokemons::pokemon_moves = other.pokemon_moves; } Pokemons::~Pokemons() @@ -36,6 +51,11 @@ Pokemons::~Pokemons() } +void Pokemons::Attack(PokemonMove pokemon_move, Pokemons* target_pokemon) +{ + target_pokemon->TakeDamage(pokemon_move.move_power); +} + void Pokemons::TakeDamage(int damage) { health -= damage; @@ -63,3 +83,48 @@ void Pokemons::SetHealth(int updated_health) health = updated_health; } +void Pokemons::PrintAllAvailableMoves() +{ + cout << "Availablle Moves:\n"; + for (size_t i = 0; i < pokemon_moves.size(); ++i) + cout << i + 1 << ": " << pokemon_moves[i].move_name << " -> " << "Power: " << pokemon_moves[i].move_power << endl; +} + +int Pokemons::SelectMove() +{ + int choice; + cout << "Choose a move: "; + cin >> choice; + while (choice < 1 || choice > static_cast(pokemon_moves.size())) + { + cout << "Invalid Choice. Try Again"; + cin >> choice; + } + return choice; +} + +void Pokemons::ExecuteMove(PokemonMove selected_move, Pokemons* target_pokemon) +{ + cout << name << " used " << selected_move.move_name << "!!!\n"; + Attack(selected_move, target_pokemon); + N_Utility::Utility::WaitForEnter(); + cout << ". . . \n"; + N_Utility::Utility::WaitForEnter(); + if (target_pokemon->IsFainted()) + cout << target_pokemon->name << " fainted!!!\n"; + else + cout << target_pokemon->name << " has " << target_pokemon->health << "HP left.\n"; +} + +void Pokemons::SelectAndExecuteMove(Pokemons* target_pokemon) +{ + PrintAllAvailableMoves(); + int move = SelectMove(); + ExecuteMove(pokemon_moves[move-1], target_pokemon); +} + +void Pokemons::ReduceAttackPower(int power) +{ + attack_power -= power; +} + diff --git a/Pokemon/Pokemon/Pokemons.hpp b/Pokemon/Pokemon/Pokemons.hpp index 0d5a607..11e50e4 100644 --- a/Pokemon/Pokemon/Pokemons.hpp +++ b/Pokemon/Pokemon/Pokemons.hpp @@ -1,10 +1,13 @@ #pragma once #include -#include "PokemonType.hpp" +#include using namespace std; +enum class Pokemon_Types; +struct PokemonMove; + class Pokemons { public: @@ -13,15 +16,23 @@ class Pokemons int health; int max_health; int attack_power; + vector pokemon_moves; Pokemons(); - Pokemons(string poke_name, Pokemon_Types poke_type, int poke_health, int poke_max_health, int poke_attack_power); + //Pokemons(string poke_name, Pokemon_Types poke_type, int poke_health, int poke_max_health, int poke_attack_power); + Pokemons(string poke_name, Pokemon_Types poke_type, int poke_health, int poke_max_health, vector poke_moves_list); Pokemons(const Pokemons& other); ~Pokemons(); - virtual void Attack(Pokemons* target_pokemon) = 0; + virtual void Attack(PokemonMove pokemon_move, Pokemons* target_pokemon) = 0; void TakeDamage(int damage); bool IsFainted() const; void Heal(); int GetHealth(); void SetHealth(int updated_health); + void SelectAndExecuteMove(Pokemons* target_pokemon); + void ReduceAttackPower(int power); +protected: + int SelectMove(); + void PrintAllAvailableMoves(); + void ExecuteMove(PokemonMove selected_move, Pokemons* target_pokemon); }; diff --git a/Pokemon/Pokemon/Squirtle.cpp b/Pokemon/Pokemon/Squirtle.cpp index 37254c9..278f95f 100644 --- a/Pokemon/Pokemon/Squirtle.cpp +++ b/Pokemon/Pokemon/Squirtle.cpp @@ -1,22 +1,31 @@ #include "Squirtle.hpp" #include "PokemonType.hpp" +#include "PokemonMove.hpp" #include "Utility.hpp" #include using namespace N_Utility; -void Squirtle::WaterSplash(Pokemons* target_pokemon) -{ - cout << name << " uses Watersplash on " << target_pokemon->name << "!!!\n"; - target_pokemon->TakeDamage(attack_power); - N_Utility::Utility::WaitForEnter(); - if (target_pokemon->IsFainted()) - cout << target_pokemon->name << " fainted!!!\n"; - else - cout << target_pokemon->name << " has " << target_pokemon->health << "HP left."; -} +//void Squirtle::WaterSplash(Pokemons* target_pokemon) +//{ +// cout << name << " uses Watersplash on " << target_pokemon->name << "!!!\n"; +// target_pokemon->TakeDamage(attack_power); +// N_Utility::Utility::WaitForEnter(); +// if (target_pokemon->IsFainted()) +// cout << target_pokemon->name << " fainted!!!\n"; +// else +// cout << target_pokemon->name << " has " << target_pokemon->health << "HP left."; +//} -void Squirtle::Attack(Pokemons* target_pokemon) +void Squirtle::Attack(PokemonMove selected_move, Pokemons* target_pokemon) { - WaterSplash(target_pokemon); + Pokemons::Attack(selected_move, target_pokemon); + if (selected_move.move_name == "Rapid Spin") + { + int hits = (rand() % 4) + 2; + for (int i = 0; i < hits; ++i) + Pokemons::Attack(selected_move, target_pokemon); + cout << this->name << " hit " << target_pokemon->name << " " << hits << " times!!!\n"; + } + //WaterSplash(target_pokemon); } \ No newline at end of file diff --git a/Pokemon/Pokemon/Squirtle.hpp b/Pokemon/Pokemon/Squirtle.hpp index d12e040..4744615 100644 --- a/Pokemon/Pokemon/Squirtle.hpp +++ b/Pokemon/Pokemon/Squirtle.hpp @@ -1,13 +1,15 @@ #pragma once #include "Pokemons.hpp" +#include "PokemonMove.hpp" +#include "PokemonType.hpp" class Squirtle :public Pokemons { public: - Squirtle() : Pokemons("Squirtle", Pokemon_Types::Water_Type, 100, 100, 35) {}; + Squirtle() : Pokemons("Squirtle", Pokemon_Types::Water_Type, 100, 100, { {"Watersplash",35},{"Rapid Spin",5}}) {}; private: - void WaterSplash(Pokemons* target_pokemon); + //void WaterSplash(Pokemons* target_pokemon); - void Attack(Pokemons* target_pokemon) override; + void Attack(PokemonMove selected_move, Pokemons* target_pokemon) override; }; \ No newline at end of file diff --git a/Pokemon/Pokemon/Zubat.cpp b/Pokemon/Pokemon/Zubat.cpp index eeb7c49..3d4365a 100644 --- a/Pokemon/Pokemon/Zubat.cpp +++ b/Pokemon/Pokemon/Zubat.cpp @@ -1,22 +1,30 @@ #include "Zubat.hpp" #include "Pokemons.hpp" +#include "PokemonMove.hpp" #include "Utility.hpp" #include using namespace N_Utility; -void Zubat::SuperSonic(Pokemons* target_pokemon) -{ - cout << name << " uses Supersonic on " << target_pokemon->name << "!!!\n"; - target_pokemon->TakeDamage(attack_power); - N_Utility::Utility::WaitForEnter(); - if (target_pokemon->IsFainted()) - cout << target_pokemon->name << " fainted!!!\n"; - else - cout << target_pokemon->name << " has " << target_pokemon->health << "HP left."; -} +//void Zubat::SuperSonic(Pokemons* target_pokemon) +//{ +// cout << name << " uses Supersonic on " << target_pokemon->name << "!!!\n"; +// target_pokemon->TakeDamage(attack_power); +// N_Utility::Utility::WaitForEnter(); +// if (target_pokemon->IsFainted()) +// cout << target_pokemon->name << " fainted!!!\n"; +// else +// cout << target_pokemon->name << " has " << target_pokemon->health << "HP left."; +//} -void Zubat::Attack(Pokemons* target_pokemon) +void Zubat::Attack(PokemonMove selected_move, Pokemons* target_pokemon) { - SuperSonic(target_pokemon); + Pokemons::Attack(selected_move, target_pokemon); + if (selected_move.move_name == "Leech Life") + { + this->health += selected_move.move_power * 0.5; + } + if (this->health > this->max_health) + this->health = this->max_health; + //SuperSonic(target_pokemon); } \ No newline at end of file diff --git a/Pokemon/Pokemon/Zubat.hpp b/Pokemon/Pokemon/Zubat.hpp index 26d7947..eb876df 100644 --- a/Pokemon/Pokemon/Zubat.hpp +++ b/Pokemon/Pokemon/Zubat.hpp @@ -1,11 +1,13 @@ #include "Pokemons.hpp" +#include "PokemonMove.hpp" +#include "PokemonType.hpp" class Zubat :public Pokemons { public: - Zubat() : Pokemons("Zubat", Pokemon_Types::Poison_Type, 100, 100, 20) {}; + Zubat() : Pokemons("Zubat", Pokemon_Types::Poison_Type, 100, 100, { {"Supersonic",20},{"Leech Life",10}}) {}; private: - void SuperSonic(Pokemons* target_pokemon); + //void SuperSonic(Pokemons* target_pokemon); - void Attack(Pokemons* target_pokemon) override; + void Attack(PokemonMove selected_move, Pokemons* target_pokemon) override; }; \ No newline at end of file