Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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
};
11 changes: 11 additions & 0 deletions Pokemon/Bulbasaur.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "Bulbasaur.h"
#include<iostream>
#include "PokemonType.h"
using namespace std;

Bulbasaur::Bulbasaur() : Pokemon("Bulbasaur", PokemonType::GRASS, 100, 35) {}

void Bulbasaur::vineWhip(Pokemon& target) {
cout << name << " uses Vine Whip on " << target.name << "!\n";
target.TakeDamage(20);
}
11 changes: 11 additions & 0 deletions Pokemon/Bulbasaur.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once
#include"Pokemon.h"
class Bulbasaur:public Pokemon
{
public:
Bulbasaur();
private:
void vineWhip(Pokemon& target);

};

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

Caterpie::Caterpie() : Pokemon("Caterpie", PokemonType::BUG, 100, 35) {}

void Caterpie::bugBite(Pokemon& target) {
cout << name << " uses Flame Thrower on " << target.name << "!\n";
target.TakeDamage(20);
}
10 changes: 10 additions & 0 deletions Pokemon/Caterpie.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include"Pokemon.h"
#pragma once

class Caterpie : public Pokemon
{
public:
Caterpie();
private:
void bugBite(Pokemon& target);
};
11 changes: 11 additions & 0 deletions Pokemon/Charmander.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "Charmander.h"
#include "PokemonType.h"
#include <iostream>
using namespace std;

Charmander::Charmander() : Pokemon("Charmander", PokemonType::FIRE, 100, 35) {}

void Charmander::flameThrower(Pokemon& target) {
cout << name << " uses Flame Thrower on " << target.name << "!\n";
target.TakeDamage(20);
}
10 changes: 10 additions & 0 deletions Pokemon/Charmander.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include"Pokemon.h"
#pragma once

class Charmander : public Pokemon
{
public:
Charmander();
private:
void flameThrower(Pokemon& target);
};
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

};

Empty file added Pokemon/Pidgey.cpp
Empty file.
10 changes: 10 additions & 0 deletions Pokemon/Pidgey.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include"Pokemon.h"
#pragma once

class Pidgey : public Pokemon
{
public:
Pidgey();
private:
void wingAttack(Pokemon& target);
};
11 changes: 11 additions & 0 deletions Pokemon/Pikachu.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "Pikachu.h"
#include <iostream>
#include"PokemonType.h"
using namespace std;

Pikachu::Pikachu() : Pokemon("Pikachu", PokemonType::ELECTRIC, 100, 20) {}

void Pikachu::thunderShock(Pokemon& target) {
cout << name << "uses Tunder shock on " << target.name << "\n";
target.TakeDamage(20);
}
11 changes: 11 additions & 0 deletions Pokemon/Pikachu.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include"Pokemon.h"
#pragma once

class Pikachu : public Pokemon
{
public:
Pikachu();
private:
void thunderShock(Pokemon& target);
};

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

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

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

// 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
}
Loading