Skip to content

Commit

Permalink
🚀 Added Game & RandomGenerator Classes (#8)
Browse files Browse the repository at this point in the history
* 🚀 Added game class

* 🚀 Added RandomGenerator class

* 📝 Commented line causing build error

* 📝 Changed Visual Studio filters

* ⚡ Changed Game class data members

* 🐛 fixed a typo

* 🎨 improved consistency of lab code

* 📝 Updated Range struct

---------

Co-authored-by: HelanaNady <helananady7@gmail.com>
  • Loading branch information
AhmedSobhy01 and HelanaNady authored Apr 4, 2024
1 parent c9c7b6e commit 51cb821
Show file tree
Hide file tree
Showing 12 changed files with 223 additions and 35 deletions.
7 changes: 7 additions & 0 deletions Alien-Invasion.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="ArmyClasses\AlienArmy.cpp" />
<ClCompile Include="ArmyClasses\EarthArmy.cpp" />
<ClCompile Include="Game.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="RandomGenerator\RandomGenerator.cpp" />
<ClCompile Include="UnitClasses\Unit.cpp" />
</ItemGroup>
<ItemGroup>
Expand All @@ -31,6 +35,9 @@
<ClInclude Include="Containers\PriorityQueue.h" />
<ClInclude Include="Containers\QueueADT.h" />
<ClInclude Include="Containers\StackADT.h" />
<ClInclude Include="DEFS.h" />
<ClInclude Include="Game.h" />
<ClInclude Include="RandomGenerator\RandomGenerator.h" />
<ClInclude Include="UnitClasses\AlienDrone.h" />
<ClInclude Include="UnitClasses\AlienMonster.h" />
<ClInclude Include="UnitClasses\AlienSoldier.h" />
Expand Down
73 changes: 49 additions & 24 deletions Alien-Invasion.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -1,78 +1,103 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Containers">
<Filter Include="Army Classes">
<UniqueIdentifier>{8a245181-84c7-4cb6-9cc0-a558bcaf50e4}</UniqueIdentifier>
</Filter>
<Filter Include="Game Class">
<UniqueIdentifier>{e00b24d1-c45b-4cf0-a79c-f081f0669982}</UniqueIdentifier>
</Filter>
<Filter Include="Containers Classes">
<UniqueIdentifier>{30a4ef19-f6b1-4dde-9639-08137b5a96c3}</UniqueIdentifier>
</Filter>
<Filter Include="UnitsClasses">
<UniqueIdentifier>{d6265d0d-9e06-4a0b-9c88-39e5e3415fa3}</UniqueIdentifier>
<Filter Include="RandomGenerator Class">
<UniqueIdentifier>{b46dd307-1a63-43e4-9442-65d606a3ceb0}</UniqueIdentifier>
</Filter>
<Filter Include="ArmyClasses">
<UniqueIdentifier>{8a245181-84c7-4cb6-9cc0-a558bcaf50e4}</UniqueIdentifier>
<Filter Include="Unit Classes">
<UniqueIdentifier>{d6265d0d-9e06-4a0b-9c88-39e5e3415fa3}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Containers\PriorityQueue.h">
<Filter>Containers</Filter>
<Filter>Containers Classes</Filter>
</ClInclude>
<ClInclude Include="Containers\PriorityNode.h">
<Filter>Containers</Filter>
<Filter>Containers Classes</Filter>
</ClInclude>
<ClInclude Include="Containers\Deque.h">
<Filter>Containers</Filter>
<Filter>Containers Classes</Filter>
</ClInclude>
<ClInclude Include="Containers\LinkedQueue.h">
<Filter>Containers</Filter>
<Filter>Containers Classes</Filter>
</ClInclude>
<ClInclude Include="Containers\Node.h">
<Filter>Containers</Filter>
<Filter>Containers Classes</Filter>
</ClInclude>
<ClInclude Include="Containers\QueueADT.h">
<Filter>Containers</Filter>
<Filter>Containers Classes</Filter>
</ClInclude>
<ClInclude Include="Containers\StackADT.h">
<Filter>Containers</Filter>
<Filter>Containers Classes</Filter>
</ClInclude>
<ClInclude Include="Containers\ArrayStack.h">
<Filter>Containers</Filter>
<Filter>Containers Classes</Filter>
</ClInclude>
<ClInclude Include="UnitClasses\AlienDrone.h">
<Filter>UnitsClasses</Filter>
<Filter>Unit Classes</Filter>
</ClInclude>
<ClInclude Include="UnitClasses\AlienMonster.h">
<Filter>UnitsClasses</Filter>
<Filter>Unit Classes</Filter>
</ClInclude>
<ClInclude Include="UnitClasses\AlienSoldier.h">
<Filter>UnitsClasses</Filter>
<Filter>Unit Classes</Filter>
</ClInclude>
<ClInclude Include="UnitClasses\EarthGunnery.h">
<Filter>UnitsClasses</Filter>
<Filter>Unit Classes</Filter>
</ClInclude>
<ClInclude Include="UnitClasses\EarthSoldier.h">
<Filter>UnitsClasses</Filter>
<Filter>Unit Classes</Filter>
</ClInclude>
<ClInclude Include="UnitClasses\EarthTank.h">
<Filter>UnitsClasses</Filter>
<Filter>Unit Classes</Filter>
</ClInclude>
<ClInclude Include="UnitClasses\Unit.h">
<Filter>UnitsClasses</Filter>
<Filter>Unit Classes</Filter>
</ClInclude>
<ClInclude Include="RandomGenerator\RandomGenerator.h">
<Filter>RandomGenerator Class</Filter>
</ClInclude>
<ClInclude Include="Game.h">
<Filter>Game Class</Filter>
</ClInclude>
<ClInclude Include="DEFS.h" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="ArmyClasses\AlienArmy.h">
<Filter>ArmyClasses</Filter>
<Filter>Army Classes</Filter>
</ClInclude>
<ClInclude Include="ArmyClasses\Army.h">
<Filter>ArmyClasses</Filter>
<Filter>Army Classes</Filter>
</ClInclude>
<ClInclude Include="ArmyClasses\EarthArmy.h">
<Filter>ArmyClasses</Filter>
<Filter>Army Classes</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp" />
<ClCompile Include="UnitClasses\Unit.cpp">
<Filter>UnitsClasses</Filter>
<Filter>Unit Classes</Filter>
</ClCompile>
<ClCompile Include="RandomGenerator\RandomGenerator.cpp">
<Filter>RandomGenerator Class</Filter>
</ClCompile>
<ClCompile Include="ArmyClasses\AlienArmy.cpp">
<Filter>Army Classes</Filter>
</ClCompile>
<ClCompile Include="ArmyClasses\EarthArmy.cpp">
<Filter>Army Classes</Filter>
</ClCompile>
<ClCompile Include="Game.cpp">
<Filter>Game Class</Filter>
</ClCompile>
</ItemGroup>
</Project>
17 changes: 17 additions & 0 deletions ArmyClasses/AlienArmy.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "AlienArmy.h"

void AlienArmy::addUnit()
{
}

void AlienArmy::removeUnit()
{
}

void AlienArmy::print() const
{
}

void AlienArmy::attack()
{
}
9 changes: 8 additions & 1 deletion ArmyClasses/AlienArmy.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,16 @@

class AlienArmy: public Army
{
LinkedQueue<AlienSoldier*> soliders;
private:
LinkedQueue<AlienSoldier*> soldiers;
// Array <AlienMonster> monsters;
Deque<AlienDrone*> drones;

public:
void addUnit();
void removeUnit();
void print() const;
void attack();
};

#endif
17 changes: 17 additions & 0 deletions ArmyClasses/EarthArmy.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "EarthArmy.h"

void EarthArmy::addUnit()
{
}

void EarthArmy::removeUnit()
{
}

void EarthArmy::print() const
{
}

void EarthArmy::attack()
{
}
7 changes: 7 additions & 0 deletions ArmyClasses/EarthArmy.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,16 @@

class EarthArmy: public Army
{
private:
LinkedQueue<EarthSoldier*> soldiers;
ArrayStack<EarthTank*> tanks;
PriorityQueue<EarthGunnery*> gunneries;

public:
void addUnit();
void removeUnit();
void print() const;
void attack();
};

#endif
20 changes: 10 additions & 10 deletions Containers/PriorityNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,28 @@ class PriorityNode
PriorityNode<T>* 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<T>* nextNodePtr);

T getItem(int& _priority) const;
T getItem(int& priority) const;
PriorityNode<T>* getNext() const;
int getPriority() const;
};

template <typename T>
inline PriorityNode<T>::PriorityNode(const T& _item, int _priority)
inline PriorityNode<T>::PriorityNode(const T& item, int priority)
{
setItem(_item, _priority);
setItem(item, priority);
next = nullptr;
}

template <typename T>
inline void PriorityNode<T>::setItem(const T& _item, int _priority)
inline void PriorityNode<T>::setItem(const T& item, int priority)
{
item = _item;
priority = _priority;
this->item = item;
this->priority = priority;
}

template <typename T>
Expand All @@ -40,9 +40,9 @@ void PriorityNode<T>::setNext(PriorityNode<T>* nextNodePtr)
}

template <typename T>
inline T PriorityNode<T>::getItem(int& _priority) const
inline T PriorityNode<T>::getItem(int& priority) const
{
_priority = priority;
priority = this->priority;

return item;
}
Expand Down
9 changes: 9 additions & 0 deletions DEFS.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef DEFS_H
#define DEFS_H

struct Range {
int min;
int max;
};

#endif
9 changes: 9 additions & 0 deletions Game.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "Game.h"

Game::Game(): gameMode(GameMode::INTERACTIVE), currentTimestep(0)
{
}

Game::~Game()
{
}
34 changes: 34 additions & 0 deletions Game.h
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions RandomGenerator/RandomGenerator.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
32 changes: 32 additions & 0 deletions RandomGenerator/RandomGenerator.h
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 51cb821

Please sign in to comment.