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 1/7] 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 2/7] 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 3/7] 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 4/7] 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 5/7] 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 6/7] 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 7/7] 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;