Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions Pokemon/BattleManager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include "BattleManager.h"
#include <iostream>
#include "Pokemon.h"
#include "PokemonType.h"
#include "player.h"
#include "utility.h"
#include "BattleState.h"
using namespace std;

void BattleManager::startBattle(Player& player, Pokemon& wildPokemon) {
battleState.playerPokemon = &player.chosenPokemon;
battleState.wildPokemon = &wildPokemon;
battleState.playerTurn = true; // Player starts first
battleState.battleOngoing = true;

std::cout << "A wild " << wildPokemon.name << " appeared!\\n";
battle();
}

void BattleManager::battle() {
while (battleState.battleOngoing) {
if (battleState.playerTurn) {
// Player's turn to attack
battleState.playerPokemon->attack(*battleState.wildPokemon);
}
else {
// Wild Pok�mon's turn to attack
battleState.wildPokemon->attack(*battleState.playerPokemon);
}

// Update the battle state after the turn
updateBattleState();

// Switch turns
battleState.playerTurn = !battleState.playerTurn;

Utility::waitForEnter();
}

handleBattleOutcome();
}

void BattleManager::updateBattleState() {
if (battleState.playerPokemon->isFainted()) {
battleState.battleOngoing = false;
}
else if (battleState.wildPokemon->isFainted()) {
battleState.battleOngoing = false;
}
}

void BattleManager::handleBattleOutcome() {
if (battleState.playerPokemon->isFainted()) {
std::cout << battleState.playerPokemon->name << " has fainted! You lose the battle.\\n";
}
else {
std::cout << "You defeated the wild " << battleState.wildPokemon->name << "!\\n";
}
}
14 changes: 14 additions & 0 deletions Pokemon/BattleManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "Pokemon.h"
#include "player.h"
#include"BattleState.h"

class BattleManager {
public:
void startBattle(Player& player, Pokemon& wildPokemon);
private:
BattleState battleState; // New BattleState object to track the battle

void battle();
void handleBattleOutcome();
void updateBattleState(); // Method to update the battle state after each turn
};
1 change: 1 addition & 0 deletions Pokemon/BattleState.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "BattleState.h"
8 changes: 8 additions & 0 deletions Pokemon/BattleState.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include "Pokemon.h"

struct BattleState {
Pokemon* playerPokemon; // Pointer to the player's Pok�mon
Pokemon* wildPokemon; // Pointer to the wild Pok�mon
bool playerTurn; // True if it's the player's turn, false if it's the wild Pok�mon's turn
bool battleOngoing; // True if the battle is ongoing, false if the battle has ended
};
89 changes: 89 additions & 0 deletions Pokemon/Game.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#include "Game.h"
#include "Player.h"
#include "PokemonType.h"
#include "utility.h"
#include "WildEncounterManager.h"
#include <iostream>
#include"BattleManager.h"
using namespace std;

Game::Game() {
// Create a sample grass environment with actual Pokemon objects
forestGrass = { "Forest",
{Pokemon("Pidgey", PokemonType::NORMAL, 40),
Pokemon("Caterpie", PokemonType::BUG, 35),
Pokemon("Zubat", PokemonType::POISON, 30)},
70 };
}

void Game::gameLoop(Player& player) {

BattleManager BattleManager;
int choice;
bool keepPlaying = true;

while (keepPlaying) {
// Clear console before showing options
Utility::clearConsole();

// Display options to the player
cout << "\nWhat would you like to do next, " << player.name << "?\n";
cout << "1. Battle Wild Pok�mon\n";
cout << "2. Visit PokeCenter\n";
cout << "3. Challenge Gyms\n";
cout << "4. Enter Pok�mon League\n";
cout << "5. Quit\n";
cout << "Enter your choice: ";
cin >> choice;

Utility::clearInputBuffer(); // Clear the input buffer

// Process the player's choice and display the corresponding message
switch (choice) {
case 1: {
// Create a scope within case 1
WildEncounterManager encounterManager;
Pokemon wildPokemon = encounterManager.getRandomPokemonFromGrass(forestGrass);
BattleManager.startBattle(player,wildPokemon);;
break;
}
case 2: {
cout << "You head to the PokeCenter.\\n";
player.chosenPokemon.heal();
cout << player.chosenPokemon.name << " has been healed to full health!\n";
break;
}
case 3: {
cout << "You march up to the Gym, but it's closed for renovations. Seems "
"like even Gym Leaders need a break!\n";
break;
}
case 4: {
cout << "You boldly step towards the Pok�mon League... but the "
"gatekeeper laughs and says, 'Maybe next time, champ!'\n";
break;
}
case 5: {
cout << "You try to quit, but Professor Oak's voice echoes: 'There's no "
"quitting in Pok�mon training!'\n";
cout << "Are you sure you want to quit? (y/n): ";
char quitChoice;
cin >> quitChoice;
if (quitChoice == 'y' || quitChoice == 'Y') {
keepPlaying = false;
}
break;
}
default: {
cout << "That's not a valid choice. Try again!\n";
break;
}
}

// Wait for Enter key before the screen is cleared and the menu is shown
// again
Utility::waitForEnter();
}

cout << "Goodbye, " << player.name << "! Thanks for playing!\n";
}
11 changes: 11 additions & 0 deletions Pokemon/Game.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "Grass.h"

class Player;

class Game {
private:
Grass forestGrass;
public:
Game();
void gameLoop(Player& player);
};
14 changes: 14 additions & 0 deletions Pokemon/Grass.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "Grass.h"
#include"PokemonType.h"

Grass forestGrass = {
"Forest",
{{"Pidgey", PokemonType::NORMAL, 40}, {"Caterpie", PokemonType::BUG, 35}},
70
};

Grass caveGrass = {
"Cave",
{{"Zubat", PokemonType::POISON, 30}, {"Geodude", PokemonType::ROCK, 50}},
80
};
12 changes: 12 additions & 0 deletions Pokemon/Grass.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include<string>
#include<vector>
#include"Pokemon.h"
using namespace std;

struct Grass{
string environmentType; // Example: "Forest", "Cave", "Riverbank"
vector<Pokemon> wildPokemonList; // List of wild Pok�mon that live in this grass
int encounterRate; // Likelihood of encountering a wild Pok�mon, out of 100

};

39 changes: 39 additions & 0 deletions Pokemon/Pokemon.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "Pokemon.h"
#include <iostream>
#include"PokemonType.h"

Pokemon::Pokemon():name("unknown"),type(PokemonType::NORMAL),health(50){}
// Parameterized constructor
Pokemon::Pokemon(string p_name, PokemonType p_type, int p_health): name(p_name),
type(p_type),
health(p_health) {
}

// Copy constructor
Pokemon::Pokemon(const Pokemon& other):name(other.name),type(other.type),health(other.health) {}

// Destructor
Pokemon::~Pokemon() {
// Destructor message removed
}

void Pokemon::attack(Pokemon& target) {
int damage = attackPower; // Example damage value, could be based on type or other factors
target.TakeDamage(damage); // Example damage value
cout << name << " attacks " << target.name << " for " << damage << " damage!\\n";
}
void Pokemon::TakeDamage(int Damage) {
health -= Damage;// Reduce health by the damage taken

if (health < 0) {
health = 0; // Ensure health doesn't go below 0
}
}
bool Pokemon::isFainted() const {
return health <= 0; // Check if health is 0 or less
}

int Pokemon::heal() {
int healAmount = maxHealth; // Example heal amount
return health; // Return the new health value
}
33 changes: 33 additions & 0 deletions Pokemon/Pokemon.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <string>
using namespace std;

enum class PokemonType;

class Pokemon {
public:
string name;
PokemonType type;
int health;
int maxHealth;
int attackPower;

// Default constructor
Pokemon();

// Parameterized constructor
Pokemon(string p_name, PokemonType p_type, int p_health);

// Copy constructor
Pokemon(const Pokemon& other);

// Destructor
~Pokemon();

void attack(Pokemon & target);

void TakeDamage(int damage);

bool isFainted() const;

int heal();
};
19 changes: 19 additions & 0 deletions Pokemon/Pokemon.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.14.36310.24 d17.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Pokemon", "Pokemon.vcxproj", "{872261CB-D6AC-488B-91C5-1B44032596F2}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Header.h", "..\Header.h\Header.h.vcxproj", "{47FEE16B-AAEB-4576-91E7-3C9C5225D963}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Expand All @@ -18,5 +23,19 @@ Global
{872261CB-D6AC-488B-91C5-1B44032596F2}.Release|Win32.Build.0 = Release|Win32
{872261CB-D6AC-488B-91C5-1B44032596F2}.Release|x64.ActiveCfg = Release|x64
{872261CB-D6AC-488B-91C5-1B44032596F2}.Release|x64.Build.0 = Release|x64
{47FEE16B-AAEB-4576-91E7-3C9C5225D963}.Debug|Win32.ActiveCfg = Debug|Win32
{47FEE16B-AAEB-4576-91E7-3C9C5225D963}.Debug|Win32.Build.0 = Debug|Win32
{47FEE16B-AAEB-4576-91E7-3C9C5225D963}.Debug|x64.ActiveCfg = Debug|x64
{47FEE16B-AAEB-4576-91E7-3C9C5225D963}.Debug|x64.Build.0 = Debug|x64
{47FEE16B-AAEB-4576-91E7-3C9C5225D963}.Release|Win32.ActiveCfg = Release|Win32
{47FEE16B-AAEB-4576-91E7-3C9C5225D963}.Release|Win32.Build.0 = Release|Win32
{47FEE16B-AAEB-4576-91E7-3C9C5225D963}.Release|x64.ActiveCfg = Release|x64
{47FEE16B-AAEB-4576-91E7-3C9C5225D963}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {AA496C07-30CF-4C3C-ABFF-0573647E3200}
EndGlobalSection
EndGlobal
10 changes: 10 additions & 0 deletions Pokemon/Pokemon.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,24 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="player.cpp" />
<ClCompile Include="PokemonChoice.cpp" />
<ClCompile Include="PokemonType.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="utility.cpp" />
</ItemGroup>
<ItemGroup>
<Content Include=".idea\.idea.Pokemon\.idea\indexLayout.xml" />
<Content Include=".idea\.idea.Pokemon\.idea\vcs.xml" />
<Content Include=".idea\.idea.Pokemon\.idea\workspace.xml" />
<Content Include="Pokemon.vcxproj.filters" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="player.h" />
<ClInclude Include="PokemonChoice.h" />
<ClInclude Include="PokemonType.h" />
<ClInclude Include="utility.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
Expand Down
26 changes: 26 additions & 0 deletions Pokemon/Pokemon.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,31 @@
<ClCompile Include="main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="PokemonType.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="PokemonChoice.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="utility.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="player.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="PokemonType.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PokemonChoice.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="utility.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="player.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
4 changes: 4 additions & 0 deletions Pokemon/Pokemon.vcxproj.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>
Empty file added Pokemon/PokemonChoice.cpp
Empty file.
Loading