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
45 changes: 26 additions & 19 deletions Pokemon/Header/Pokemon/Pokemon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,51 +7,58 @@
#include"../Pokemon/Move.hpp"
#include"../Pokemon/PokemonType.hpp"
#include"../Pokemon/PokemonChoice.hpp"
#include"StatusEffects/IStatusEffect.hpp"
#include"StatusEffects/StatusEffectType.hpp"
#include"StatusEffects/ParalyzedEffect.hpp"

using namespace std;

struct Move;

namespace N_Pokemon
{
using namespace N_StatusEffects;
class Pokemon {
public:

// Default constructor
Pokemon();
//basic attributes
string name;
PokemonType type;
int health;
int maxHealth;
vector<Move> moves;
int attackBonus = 0;

// Parameterized constructor
//constructors
Pokemon();
Pokemon(std::string p_name, PokemonType p_type, int p_health, vector<Move> p_moves);

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

//destructor
~Pokemon();

//battle methods
virtual void attack(Move selectedMove, Pokemon* target) = 0;

void heal();

void takeDamage(int damage);

bool isFainted() const;

//getters and setters
//getter and setter methods
string getName();

void setName(string _name);

void selectAndUseMove(Pokemon* target);

void reduceAttackPower(int reducedDamage);

//status effect members
IStatusEffect* appliedEffect;

bool canAttack();
void applyEffect(StatusEffectType effectToApply);
void clearEffect();
bool canApplyEffect();

protected:
string name;
PokemonType type;
int health;
int maxHealth;
vector<Move> moves;
int attackBonus = 0;

//Pokemon move methods
void printAvailableMoves();
int selectMove();
void useMove(Move selectedMove, Pokemon* target);
Expand Down
26 changes: 26 additions & 0 deletions Pokemon/Header/Pokemon/StatusEffects/IStatusEffect.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once
#include"../Pokemon.hpp"

namespace N_Pokemon
{
namespace N_StatusEffects
{
class IStatusEffect {
public:
// Apply the effect (e.g., poison, burn)
virtual void applyEffect(Pokemon* target) = 0;

// Get the name of the effect
virtual std::string getEffectName() = 0;

// Apply the changes due to effect after the end of each turn
// Returns true if the Pok�mon can move, else false
virtual bool turnEndEffect(Pokemon* target) = 0;

// Remove the effect
virtual void clearEffect(Pokemon* target) = 0;

virtual ~IStatusEffect() = default;
};
}
}
19 changes: 19 additions & 0 deletions Pokemon/Header/Pokemon/StatusEffects/ParalyzedEffect.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once
#include "IStatusEffect.hpp"

namespace N_Pokemon
{
namespace N_StatusEffects
{
class ParalyzedEffect : public IStatusEffect
{
private:
int turnsLeft; // Track the remaining turns for the effect
public:
void applyEffect(Pokemon* target) override;
std::string getEffectName() override;
bool turnEndEffect(Pokemon* target) override;
void clearEffect(Pokemon* target) override;
};
}
}
15 changes: 15 additions & 0 deletions Pokemon/Header/Pokemon/StatusEffects/StatusEffectType.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

namespace N_Pokemon
{
namespace N_StatusEffects
{
enum class StatusEffectType
{
PARALYZED,
SLEEPING,
BURNED,
POISONED
};
}
}
4 changes: 4 additions & 0 deletions Pokemon/Pokemon.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@
<ClCompile Include="Src\Pokemon\Pokemons\Caterpie.cpp" />
<ClCompile Include="Src\Pokemon\Pokemons\Pikachu.cpp" />
<ClCompile Include="Src\Pokemon\Pokemons\Squirtle.cpp" />
<ClCompile Include="Src\Pokemon\StatusEffects\ParalyzedEffect.cpp" />
<ClCompile Include="Src\Utility\Utility.cpp" />
<ClCompile Include="Src\Battle\WildEncounterManager.cpp" />
</ItemGroup>
Expand All @@ -179,8 +180,10 @@
<ClInclude Include="Header\Battle\BattleManager.hpp" />
<ClInclude Include="Header\Battle\BattleState.hpp" />
<ClInclude Include="Header\Main\Game.hpp" />
<ClInclude Include="Header\Pokemon\StatusEffects\ParalyzedEffect.hpp" />
<ClInclude Include="Header\Pokemon\Grass.hpp" />
<ClInclude Include="Header\Character\Player\Player.hpp" />
<ClInclude Include="Header\Pokemon\StatusEffects\IStatusEffect.hpp" />
<ClInclude Include="Header\Pokemon\Move.hpp" />
<ClInclude Include="Header\Pokemon\Pokemon.hpp" />
<ClInclude Include="Header\Pokemon\PokemonChoice.hpp" />
Expand All @@ -192,6 +195,7 @@
<ClInclude Include="Header\Pokemon\Pokemons\Squirtle.hpp" />
<ClInclude Include="Header\Pokemon\PokemonType.hpp" />
<ClInclude Include="Header\Character\ProfessorOak.hpp" />
<ClInclude Include="Header\Pokemon\StatusEffects\StatusEffectType.hpp" />
<ClInclude Include="Header\Utility\Utility.hpp" />
<ClInclude Include="Header\Battle\WildEncounterManager.hpp" />
</ItemGroup>
Expand Down
12 changes: 12 additions & 0 deletions Pokemon/Pokemon.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
<ClCompile Include="Src\Pokemon\Pokemons\Squirtle.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Src\Pokemon\StatusEffects\ParalyzedEffect.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Header\Character\Player\Player.hpp">
Expand Down Expand Up @@ -113,5 +116,14 @@
<ClInclude Include="Header\Pokemon\Move.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Header\Pokemon\StatusEffects\IStatusEffect.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Header\Pokemon\StatusEffects\ParalyzedEffect.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Header\Pokemon\StatusEffects\StatusEffectType.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
19 changes: 6 additions & 13 deletions Pokemon/Src/Battle/BattleManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,19 @@ namespace N_Battle
}
//className* ptrname; declaration
//ptrname->name;
void BattleManager::battle() {
while (battleState.battleOngoing) {
if (battleState.playerTurn) {
// Player's turn to attack
void BattleManager::battle()
{
while (battleState.battleOngoing)
{
if (battleState.playerTurn && battleState.playerPokemon->canAttack())
battleState.playerPokemon->selectAndUseMove(battleState.wildPokemon);
}
else {
// Wild Pok�mon's turn to attack
else if (battleState.wildPokemon->canAttack())
battleState.wildPokemon->selectAndUseMove(battleState.playerPokemon);
}

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

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

Utility::waitForEnter();
}

handleBattleOutcome();
}

Expand Down
44 changes: 43 additions & 1 deletion Pokemon/Src/Pokemon/Pokemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ using namespace std;

using namespace N_Utility;


namespace N_Pokemon
{
using namespace N_StatusEffects;

Pokemon::Pokemon() {
name = "Unknown";
type = PokemonType::NORMAL;
Expand Down Expand Up @@ -79,8 +82,43 @@ namespace N_Pokemon
cout << target->name << " has " << target->health << " HP left.\n";
}

bool Pokemon::canAttack()
{
if (appliedEffect == nullptr)
return true;
else
return appliedEffect->turnEndEffect(this);
}

Pokemon::~Pokemon() { }
bool Pokemon::canApplyEffect()
{
return appliedEffect == nullptr;
}

void Pokemon::applyEffect(StatusEffectType effectToApply)
{
switch (effectToApply)
{
case StatusEffectType::PARALYZED:
appliedEffect = new ParalyzedEffect();
appliedEffect->applyEffect(this);
break;
default:
appliedEffect = nullptr;
}
}

void Pokemon::clearEffect() { appliedEffect = nullptr; }

void Pokemon::printAvailableMoves()
{
cout << name << "'s available moves:\n";

// List out all moves for the player to choose from
for (size_t i = 0; i < moves.size(); ++i) {
cout << i + 1 << ": " << moves[i].name << " (Power: " << moves[i].power << ")\n";
}
}

void Pokemon::attack(Move selectedMove, Pokemon* target) {
target->takeDamage((selectedMove.power + attackBonus));
Expand Down Expand Up @@ -117,5 +155,9 @@ namespace N_Pokemon
{
attackBonus -= reducedDamage;
}



Pokemon::~Pokemon() { }
}

7 changes: 7 additions & 0 deletions Pokemon/Src/Pokemon/Pokemons/Pikachu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ namespace N_Pokemon {
}
else
Pokemon::attack(selectedMove, target);
if (selectedMove.name == "THUNDER SHOCK")
{

if (target->canApplyEffect())

target->applyEffect(StatusEffectType::PARALYZED);

}
}
}
}
53 changes: 53 additions & 0 deletions Pokemon/Src/Pokemon/StatusEffects/ParalyzedEffect.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include "../../../Header/Pokemon/StatusEffects/ParalyzedEffect.hpp"
#include "../../../Header/Pokemon/StatusEffects/StatusEffectType.hpp"
#include <iostream>

namespace N_Pokemon
{
namespace N_StatusEffects
{
void ParalyzedEffect::applyEffect(Pokemon* target)
{
std::cout << target->getName() << " is paralyzed! It may not be able to move!\n";

// Effect lasts between 1 and 3 turns randomly
turnsLeft = rand() % 3 + 1;
}

std::string ParalyzedEffect::getEffectName()
{
return "Paralyzed";
}

// Determines whether the Pok�mon can act at the end of the turn
// Returns false if the paralysis prevents the Pok�mon from moving
bool ParalyzedEffect::turnEndEffect(Pokemon* target)
{
if (turnsLeft <= 0) {
clearEffect(target);
return true; // Can move as the effect is cleared
}
turnsLeft--;

// Generates a number between 0 and 3
int paralysis_chance = rand() % 4;

// 25% chance that the Pok�mon cannot move due to paralysis
if (paralysis_chance == 0)
{
std::cout << target->getName() << " is paralyzed! It can't move!\n";
return false; // Pok�mon cannot act this turn
}

// Otherwise, it can act normally
std::cout << target->getName() << " shakes off the paralysis momentarily and can move!\n";
return true; // Pok�mon can act this turn
}

void ParalyzedEffect::clearEffect(Pokemon* target)
{
std::cout << target->getName() << " is no longer paralyzed!\n";
target->clearEffect();
}
}
}