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/22] 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/22] 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/22] 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/22] 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/22] 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/22] 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/22] 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/22] 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/22] 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/22] 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/22] 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/22] 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/22] 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/22] 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/22] 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/22] 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/22] 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/22] 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/22] 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/22] 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/22] 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/22] 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