From 51cb821f8c2f3d704e923661b5165e623832b4b3 Mon Sep 17 00:00:00 2001 From: Ahmed Sobhy Date: Thu, 4 Apr 2024 21:51:43 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=80=20Added=20Game=20&=20RandomGenerat?= =?UTF-8?q?or=20Classes=20(#8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * :rocket: Added game class * :rocket: Added RandomGenerator class * :memo: Commented line causing build error * :memo: Changed Visual Studio filters * :zap: Changed Game class data members * :bug: fixed a typo * :art: improved consistency of lab code * :memo: Updated Range struct --------- Co-authored-by: HelanaNady --- Alien-Invasion.vcxproj | 7 +++ Alien-Invasion.vcxproj.filters | 73 +++++++++++++++++++---------- ArmyClasses/AlienArmy.cpp | 17 +++++++ ArmyClasses/AlienArmy.h | 9 +++- ArmyClasses/EarthArmy.cpp | 17 +++++++ ArmyClasses/EarthArmy.h | 7 +++ Containers/PriorityNode.h | 20 ++++---- DEFS.h | 9 ++++ Game.cpp | 9 ++++ Game.h | 34 ++++++++++++++ RandomGenerator/RandomGenerator.cpp | 24 ++++++++++ RandomGenerator/RandomGenerator.h | 32 +++++++++++++ 12 files changed, 223 insertions(+), 35 deletions(-) create mode 100644 ArmyClasses/AlienArmy.cpp create mode 100644 ArmyClasses/EarthArmy.cpp create mode 100644 DEFS.h create mode 100644 Game.cpp create mode 100644 Game.h create mode 100644 RandomGenerator/RandomGenerator.cpp create mode 100644 RandomGenerator/RandomGenerator.h diff --git a/Alien-Invasion.vcxproj b/Alien-Invasion.vcxproj index c0f837d..1efffe6 100644 --- a/Alien-Invasion.vcxproj +++ b/Alien-Invasion.vcxproj @@ -19,7 +19,11 @@ + + + + @@ -31,6 +35,9 @@ + + + diff --git a/Alien-Invasion.vcxproj.filters b/Alien-Invasion.vcxproj.filters index 518a036..d0f3c07 100644 --- a/Alien-Invasion.vcxproj.filters +++ b/Alien-Invasion.vcxproj.filters @@ -1,78 +1,103 @@ - + + {8a245181-84c7-4cb6-9cc0-a558bcaf50e4} + + + {e00b24d1-c45b-4cf0-a79c-f081f0669982} + + {30a4ef19-f6b1-4dde-9639-08137b5a96c3} - - {d6265d0d-9e06-4a0b-9c88-39e5e3415fa3} + + {b46dd307-1a63-43e4-9442-65d606a3ceb0} - - {8a245181-84c7-4cb6-9cc0-a558bcaf50e4} + + {d6265d0d-9e06-4a0b-9c88-39e5e3415fa3} - Containers + Containers Classes - Containers + Containers Classes - Containers + Containers Classes - Containers + Containers Classes - Containers + Containers Classes - Containers + Containers Classes - Containers + Containers Classes - Containers + Containers Classes - UnitsClasses + Unit Classes - UnitsClasses + Unit Classes - UnitsClasses + Unit Classes - UnitsClasses + Unit Classes - UnitsClasses + Unit Classes - UnitsClasses + Unit Classes - UnitsClasses + Unit Classes + + RandomGenerator Class + + + Game Class + + - ArmyClasses + Army Classes - ArmyClasses + Army Classes - ArmyClasses + Army Classes - UnitsClasses + Unit Classes + + + RandomGenerator Class + + + Army Classes + + + Army Classes + + + Game Class \ No newline at end of file diff --git a/ArmyClasses/AlienArmy.cpp b/ArmyClasses/AlienArmy.cpp new file mode 100644 index 0000000..1000a86 --- /dev/null +++ b/ArmyClasses/AlienArmy.cpp @@ -0,0 +1,17 @@ +#include "AlienArmy.h" + +void AlienArmy::addUnit() +{ +} + +void AlienArmy::removeUnit() +{ +} + +void AlienArmy::print() const +{ +} + +void AlienArmy::attack() +{ +} diff --git a/ArmyClasses/AlienArmy.h b/ArmyClasses/AlienArmy.h index 0385dac..3c055b5 100644 --- a/ArmyClasses/AlienArmy.h +++ b/ArmyClasses/AlienArmy.h @@ -12,9 +12,16 @@ class AlienArmy: public Army { - LinkedQueue soliders; +private: + LinkedQueue soldiers; // Array monsters; Deque drones; + +public: + void addUnit(); + void removeUnit(); + void print() const; + void attack(); }; #endif \ No newline at end of file diff --git a/ArmyClasses/EarthArmy.cpp b/ArmyClasses/EarthArmy.cpp new file mode 100644 index 0000000..5bbd806 --- /dev/null +++ b/ArmyClasses/EarthArmy.cpp @@ -0,0 +1,17 @@ +#include "EarthArmy.h" + +void EarthArmy::addUnit() +{ +} + +void EarthArmy::removeUnit() +{ +} + +void EarthArmy::print() const +{ +} + +void EarthArmy::attack() +{ +} diff --git a/ArmyClasses/EarthArmy.h b/ArmyClasses/EarthArmy.h index 18be8d2..ab14c05 100644 --- a/ArmyClasses/EarthArmy.h +++ b/ArmyClasses/EarthArmy.h @@ -13,9 +13,16 @@ class EarthArmy: public Army { +private: LinkedQueue soldiers; ArrayStack tanks; PriorityQueue gunneries; + +public: + void addUnit(); + void removeUnit(); + void print() const; + void attack(); }; #endif diff --git a/Containers/PriorityNode.h b/Containers/PriorityNode.h index b11f4e4..47faa61 100644 --- a/Containers/PriorityNode.h +++ b/Containers/PriorityNode.h @@ -9,28 +9,28 @@ class PriorityNode PriorityNode* next; // Pointer to next node public: - PriorityNode(const T& _item, int _priority); + PriorityNode(const T& item, int priority); - void setItem(const T& _item, int _priority); + void setItem(const T& item, int priority); void setNext(PriorityNode* nextNodePtr); - T getItem(int& _priority) const; + T getItem(int& priority) const; PriorityNode* getNext() const; int getPriority() const; }; template -inline PriorityNode::PriorityNode(const T& _item, int _priority) +inline PriorityNode::PriorityNode(const T& item, int priority) { - setItem(_item, _priority); + setItem(item, priority); next = nullptr; } template -inline void PriorityNode::setItem(const T& _item, int _priority) +inline void PriorityNode::setItem(const T& item, int priority) { - item = _item; - priority = _priority; + this->item = item; + this->priority = priority; } template @@ -40,9 +40,9 @@ void PriorityNode::setNext(PriorityNode* nextNodePtr) } template -inline T PriorityNode::getItem(int& _priority) const +inline T PriorityNode::getItem(int& priority) const { - _priority = priority; + priority = this->priority; return item; } diff --git a/DEFS.h b/DEFS.h new file mode 100644 index 0000000..35230e1 --- /dev/null +++ b/DEFS.h @@ -0,0 +1,9 @@ +#ifndef DEFS_H +#define DEFS_H + +struct Range { + int min; + int max; +}; + +#endif \ No newline at end of file diff --git a/Game.cpp b/Game.cpp new file mode 100644 index 0000000..7e2b772 --- /dev/null +++ b/Game.cpp @@ -0,0 +1,9 @@ +#include "Game.h" + +Game::Game(): gameMode(GameMode::INTERACTIVE), currentTimestep(0) +{ +} + +Game::~Game() +{ +} diff --git a/Game.h b/Game.h new file mode 100644 index 0000000..b030756 --- /dev/null +++ b/Game.h @@ -0,0 +1,34 @@ +#ifndef GAME_H +#define GAME_H + +#include "ArmyClasses/EarthArmy.h" +#include "ArmyClasses/AlienArmy.h" +#include "RandomGenerator/RandomGenerator.h" + +enum GameMode +{ + INTERACTIVE, + SILENT, +}; + +class Game +{ +private: + GameMode gameMode; + int currentTimestep; + + EarthArmy earthArmy; + AlienArmy alienArmy; + // RandomGenerator randomGenerator; // We need to pass the parameters to the constructor + +public: + Game(); + + void run(GameMode); + void incrementTimestep(); + void changeGameMode(GameMode); + + ~Game(); +}; + +#endif \ No newline at end of file diff --git a/RandomGenerator/RandomGenerator.cpp b/RandomGenerator/RandomGenerator.cpp new file mode 100644 index 0000000..3b77c28 --- /dev/null +++ b/RandomGenerator/RandomGenerator.cpp @@ -0,0 +1,24 @@ +#include "RandomGenerator.h" + +RandomGenerator::RandomGenerator(int N, int ESPercentage, int ETPercentage, int EGPercentage, int ASPercentage, int AMPercentage, int ADPercentage, int prob, Range earthPowerRange, Range earthHealthRange, Range earthAttackCapacityRange, Range alienPowerRange, Range alienHealthRange, Range alienAttackCapacityRange) +{ + this->N = N; + + this->ESPercentage = ESPercentage; + this->ETPercentage = ETPercentage; + this->EGPercentage = EGPercentage; + + this->ASPercentage = ASPercentage; + this->AMPercentage = AMPercentage; + this->ADPercentage = ADPercentage; + + this->prob = prob; + + this->earthPowerRange = earthPowerRange; + this->earthHealthRange = earthHealthRange; + this->earthAttackCapacityRange = earthAttackCapacityRange; + + this->alienPowerRange = alienPowerRange; + this->alienHealthRange = alienHealthRange; + this->alienAttackCapacityRange = alienAttackCapacityRange; +} diff --git a/RandomGenerator/RandomGenerator.h b/RandomGenerator/RandomGenerator.h new file mode 100644 index 0000000..d463008 --- /dev/null +++ b/RandomGenerator/RandomGenerator.h @@ -0,0 +1,32 @@ +#ifndef RANDOM_GENERATOR_H +#define RANDOM_GENERATOR_H + +#include "../DEFS.h" +#include "../UnitClasses/Unit.h" + +class RandomGenerator +{ +private: + int N; + int ESPercentage; + int ETPercentage; + int EGPercentage; + int ASPercentage; + int AMPercentage; + int ADPercentage; + int prob; + Range earthPowerRange; + Range earthHealthRange; + Range earthAttackCapacityRange; + Range alienPowerRange; + Range alienHealthRange; + Range alienAttackCapacityRange; + +public: + RandomGenerator(int, int, int, int, int, int, int, int, Range, Range, Range, Range, Range, Range); + + Unit* generateUnit(); + int getRandomNumber(int min, int max); +}; + +#endif \ No newline at end of file