Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/amir-samiee/iustz
Browse files Browse the repository at this point in the history
  • Loading branch information
zinabkaviani committed Apr 12, 2024
2 parents 709c44e + 9cb7eb6 commit 2c6c759
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 31 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
*.exe
!main.exe
/.vscode
tester*.cpp
shoptest.cpp
Expand Down
27 changes: 19 additions & 8 deletions character.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#pragma once
#include "headers.h"

Stat::Stat(int basePoint, int lvl) : basePoint(basePoint)
{
maxPoint = (lvl - 1) * 30 + basePoint;
currentPoint = maxPoint;
}

void Stat::setCurrentPoint(int newValue)
{
if (newValue > maxPoint)
Expand Down Expand Up @@ -210,11 +216,15 @@ void MVC::EnemyController::die()
Mission::eventsLog.push_back(model->name + magenta + " (enemy) " + red + "died" + reset);
}

void MVC::SpecialEnemyController::takeDamage(int damage)
void MVC::SpecialEnemyController::takeDamage(int takenDamage)
{
double ratio = (1.0 / ((rand() % 3) + 1));
int newPoint = model->hp.getCurrentPoint() - (damage * ratio);
Mission::eventsLog.push_back(model->name + magenta + " (enemy)" + reset + " took " + to_string((int)(100 * ratio)) + "% of the damage!");
int newPoint = model->hp.getCurrentPoint() - (takenDamage * ratio);
if(ratio != 1)
Mission::eventsLog.push_back(model->name + magenta + " (enemy)" + reset + " took " + to_string((int)(100 * ratio)) + "% of the damage!");
if (model->hp.getCurrentPoint() > model->hp.getMaxPoint() * 0.3 && newPoint <= model->hp.getMaxPoint() * 0.3)
Mission::eventsLog.push_back(yellow + model->name + magenta + " (enemy) " + red + "raged" + reset);

model->hp.setCurrentPoint(newPoint);
if (newPoint <= 0)
this->die();
Expand Down Expand Up @@ -253,7 +263,7 @@ Character *Enemy::currentEnemy(bool isViewd)

bool Enemy::isAlive() { return model->isAlive(); }
int Enemy::level() { return (model->firearmLevel + model->meleeLevel + model->hp.level() + model->stamina.level()) / 4; }
void Enemy::takeDamage(int damage) { controller->takeDamage(damage); }
void Enemy::takeDamage(int takenDamage) { controller->takeDamage(takenDamage); }

HumanEnemy::HumanEnemy(string name, int age, string gender, LimitedStorage backpack,
Stat hp, Stat stamina, int firearmLevel, int meleeLevel, double powerBoost, vector<Character *> currentWave, int coins)
Expand All @@ -264,15 +274,14 @@ ZombieEnemy::ZombieEnemy(string name, int age, string gender, LimitedStorage bac
Stat hp, Stat stamina, int firearmLevel, int meleeLevel, double powerBoost, vector<Character *> currentWave, int coins)
: Enemy(name, age, gender, backpack, hp,
stamina, firearmLevel, meleeLevel, powerBoost, currentWave, coins) {}
void ZombieEnemy::takeDamage(int damage) { controller->takeDamage(damage); }
void ZombieEnemy::takeDamage(int takenDamage) { controller->takeDamage(takenDamage); }

SpecialZombie::SpecialZombie(string name, int age, string gender, LimitedStorage backpack,
Stat hp, Stat stamina, int firearmLevel, int meleeLevel, double powerBoost, vector<Character *> currentWave, int coins)
: ZombieEnemy(name, age, gender, backpack, hp, stamina, firearmLevel, meleeLevel, powerBoost, currentWave, coins)
{
delete controller;
controller = new MVC::SpecialEnemyController(model, view, this);
model->backpack.addItem({{powerPotion4.getName(), 5}});
}

void SpecialZombie::takeDamage(int damage) { controller->takeDamage(damage); }
Expand Down Expand Up @@ -310,8 +319,10 @@ bool Player::move()

double SpecialZombie::getPowerBoost() const
{
if (model->hp.getCurrentPoint() <= (0.2 * model->hp.getMaxPoint()))
return model->powerBoost * 1.5;

if (model->hp.getCurrentPoint() <= (0.3 * model->hp.getMaxPoint()))
return model->powerBoost * 1.25;

return model->powerBoost;
}

Expand Down
18 changes: 10 additions & 8 deletions character.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Stat
// constructors:
Stat() = default;
Stat(int basePoint) : basePoint(basePoint) {}
Stat(int basePoint , int lvl);

// getters:
int getMaxPoint() const { return maxPoint; }
Expand Down Expand Up @@ -66,7 +67,7 @@ class Character
virtual int level() = 0;
virtual bool move() = 0;
virtual void die() = 0;
virtual void takeDamage(int newPoint) = 0;
virtual void takeDamage(int takenDamage) = 0;
virtual void display(bool isFighting = 0) = 0;
};

Expand Down Expand Up @@ -140,7 +141,7 @@ class Player : public Character
int level() override;
bool move() override;
void die() override;
void takeDamage(int newPoint) override;
void takeDamage(int takenDamage) override;
void display(bool isFighing = 0) override;
void addRewardCoins(int addedCoins);
void loadPlayer(json data);
Expand Down Expand Up @@ -193,7 +194,7 @@ namespace MVC

public:
EnemyController(EnemyModel *model, EnemyView *view, Enemy *self);
virtual void takeDamage(int damage);
virtual void takeDamage(int takenDamage);
void die();
bool move();
};
Expand All @@ -206,7 +207,7 @@ namespace MVC
: EnemyController(model, view, self) {}

// methodes:
void takeDamage(int damage) override;
void takeDamage(int takenDamage) override;
};
}

Expand All @@ -231,7 +232,7 @@ class Enemy : public Character
Stat *getStamina() override { return &model->stamina; };
int getFirearmLevel() const override { return model->firearmLevel; };
int getMeleeLevel() const override { return model->meleeLevel; };
double getPowerBoost() const override { return model->powerBoost; };
virtual double getPowerBoost() const override { return model->powerBoost; };
int getCoins() const override { return model->coins; };
vector<Character *> getWave() const override { return model->currentWave; };
Character *currentEnemy(bool isViewd = 0) override;
Expand All @@ -252,7 +253,7 @@ class Enemy : public Character
// others
bool isAlive() override;
int level() override;
virtual void takeDamage(int damage) override;
virtual void takeDamage(int takenDamage) override;
bool move() override;
void die() override;
void display(bool isFighting = 0) override;
Expand All @@ -270,7 +271,8 @@ class ZombieEnemy : public Enemy
public:
ZombieEnemy(string name, int age, string gender, LimitedStorage backpack,
Stat hp, Stat stamina, int firearmLevel, int meleeLevel, double powerBoost, vector<Character *> currentWave, int coins);
virtual void takeDamage(int damage);
virtual void takeDamage(int takenDamage);
virtual double getPowerBoost() const override { return model->powerBoost; };
};

class SpecialZombie : public ZombieEnemy
Expand All @@ -279,7 +281,7 @@ class SpecialZombie : public ZombieEnemy
SpecialZombie(string name, int age, string gender, LimitedStorage backpack,
Stat hp, Stat stamina, int firearmLevel, int meleeLevel, double powerBoost, vector<Character *> currentWave, int coins);
double getPowerBoost() const override;
void takeDamage(int damage) override;
void takeDamage(int takenDamage) override;
};

vector<Character *> characterLeakHandle;
2 changes: 1 addition & 1 deletion fsm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ StateName States::nextState()
{
return StateName::LowHp;
}
else if (highStamina() && havePowerPotion() && canUse(self->getBackpack()->getPowerPotions()) && !wastingPowerPotion)
else if (havePowerPotion() && canUse(self->getBackpack()->getPowerPotions()) && !wastingPowerPotion)
{
return StateName::BoostPower;
}
Expand Down
1 change: 0 additions & 1 deletion fsm.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class States
bool haveStaminaPotion() { return !self->getBackpack()->getStaminaPotions().empty(); }
bool haveHpPotion() { return !self->getBackpack()->getHpPotions().empty(); }
bool havePowerPotion() { return !self->getBackpack()->getPowerPotions().empty(); }
bool highStamina() { return self->getStamina()->getCurrentPoint() > 0.5 * self->getStamina()->getMaxPoint(); }
bool wastingPotion(vector<string> potions, Stat myStat); // check if there is a potion of a type that wont go to waste
bool wastingPotion(Item *potion, Stat myStat); // check if a certain potion wont go to waste
string appropriateStamina(Stat myStat);
Expand Down
1 change: 0 additions & 1 deletion item.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once
#include "headers.h"

vector<string> Mission::eventsLog = {};

Item::Item(string name, int price, Character *owner, int stamina)
{
Expand Down
10 changes: 5 additions & 5 deletions item.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ StaminaPotion staminaPotion4("ReviveRush", 35, nullptr, 0, 40);
StaminaPotion staminaPotion5("StamBlitz", 50, nullptr, 0, 50);

// power potion
PowerPotion powerPotion1("Savage Serum", 25, nullptr, 0, 1.1);
PowerPotion powerPotion2("Titan Tonic", 50, nullptr, 0, 1.2);
PowerPotion powerPotion3("Cataclysmic", 75, nullptr, 0, 1.3);
PowerPotion powerPotion4("Blitzkrieg", 100, nullptr, 0, 1.4);
PowerPotion powerPotion5("Valor Elixir", 150, nullptr, 0, 1.5);
PowerPotion powerPotion1("Savage Serum", 25, nullptr, 5, 1.1);
PowerPotion powerPotion2("Titan Tonic", 50, nullptr, 10, 1.2);
PowerPotion powerPotion3("Cataclysmic", 75, nullptr, 20, 1.3);
PowerPotion powerPotion4("Blitzkrieg", 100, nullptr, 35, 1.4);
PowerPotion powerPotion5("Valor Elixir", 150, nullptr, 60, 1.5);
Binary file removed main.exe
Binary file not shown.
20 changes: 16 additions & 4 deletions mission.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once
#include "headers.h"

vector<string> Mission::eventsLog = {};

Factory::Factory(int lvl, int specialEn,
const vector<string> &permanents,
const vector<string> &throwables,
Expand Down Expand Up @@ -50,7 +52,7 @@ vector<int> Factory::getWave()
void Factory::addPermanent(vector<Character *> unshuffeledEn, vector<string> addingItem)
{
// Generating a random number of permanents:
int randomPermanentNum = rand() % (casualEnemy / 2) + (casualEnemy / 4) + 1;
int randomPermanentNum = rand() % (casualEnemy / 2) + (casualEnemy / 4);

for (int i = 0; i < randomPermanentNum; i++)
{
Expand Down Expand Up @@ -158,8 +160,13 @@ vector<vector<Character *>> HumanFactory::createEnemy(vector<int> waves)
// Generating enemies backpacks with randomly generated number of permanents inside:
for (int i = 0; i < casualEnemy; i++)
{
int statLevel;
if(level == 1){statLevel = 1;}
else
statLevel = ((level - 1) / 3) + 1 + (rand() % 2);

// Creating the enemy based on type:
Character *enemy = new HumanEnemy("", 30, "male", LimitedStorage(), Stat(), Stat(),
Character *enemy = new HumanEnemy("", 30, "male", LimitedStorage(), Stat(100, statLevel), Stat(100, statLevel),
level + (rand() % 2), level + (rand() % 2), 1, {player1}, (level * 10));
// Saving enemy in a primary vector:
unshuffeledEn.push_back(enemy);
Expand Down Expand Up @@ -194,8 +201,13 @@ vector<vector<Character *>> ZombieFactory::createEnemy(vector<int> waves)

for (int i = 0; i < casualEnemy; i++)
{
int statLevel;
if(level == 1){statLevel = 1;}
else
statLevel = ((level - 1) / 3) + 1 + (rand() % 2);

// Creating the enemy based on type:
Character *enemy = new ZombieEnemy("", 1000, "male", LimitedStorage(), Stat(), Stat(),
Character *enemy = new ZombieEnemy("", 1000, "male", LimitedStorage(), Stat(100, statLevel), Stat(100 , statLevel),
level + (rand() % 2), level + (rand() % 2), 1, {player1}, (level * 10));
// Saving enemy in a primary vector:
casualEn.push_back(enemy);
Expand All @@ -213,7 +225,7 @@ vector<vector<Character *>> ZombieFactory::createEnemy(vector<int> waves)
int bestWeapon = (missionPermanents.size() - 1);
backpack.addItem(missionPermanents[bestWeapon]);

Character *enemy = new SpecialZombie("", 1000, "male", backpack, Stat(200), Stat(200),
Character *enemy = new SpecialZombie("", 1000, "male", backpack, Stat(200, ((level - 1) / 3) + 1), Stat(200, ((level - 1) / 3) + 1),
(level + rand() % 3 + 1), level + (rand() % 2 + 1), 1, {player1}, (level * 20));
characterLeakHandle.push_back(enemy);
specialEn.push_back(enemy);
Expand Down
5 changes: 3 additions & 2 deletions storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ void Storage::addItem(map<string, int> addingItems, bool isViewed)

string Storage::getStorageData(string beforeNumber, string afterNumber, bool priceView)
{
names.clear();
if (items.empty())
return "Storage is Empty!\n";
stringstream result;
Expand Down Expand Up @@ -76,12 +77,12 @@ string Storage::getStorageData(string beforeNumber, string afterNumber, bool pri
if (priceView)
result << setw(10) << "Price";
result << endl;
names.clear();
for (auto &item : items)
{
string itemName = item.first;
Item *itemPtr = itemsMap[itemName];
names.push_back(itemName);
if(itemName != "")
names.push_back(itemName);
result << left << setw(leftMargin) << beforeNumber + to_string(i) + afterNumber
<< setw(maxNameLength + 5) << itemName
<< setw(maxTypeLength + 2) << itemPtr->getType() << right
Expand Down

0 comments on commit 2c6c759

Please sign in to comment.