Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎉 completed random generator class and Adding units #9

Merged
merged 25 commits into from
Apr 6, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
92ae826
:rocket: Added game class
AhmedSobhy01 Apr 3, 2024
0929dec
:rocket: Added RandomGenerator class
AhmedSobhy01 Apr 3, 2024
c301511
:memo: Commented line causing build error
AhmedSobhy01 Apr 3, 2024
bcfedd0
:memo: Changed Visual Studio filters
AhmedSobhy01 Apr 3, 2024
3127428
:zap: Changed Game class data members
AhmedSobhy01 Apr 4, 2024
8780815
:bug: fixed a typo
HelanaNady Apr 4, 2024
e3a170e
:art: improved consistency of lab code
HelanaNady Apr 4, 2024
5f593d1
:memo: Updated Range struct
AhmedSobhy01 Apr 4, 2024
2b0a3a9
Merge branch 'feature/Game-RandomGenerator-classes' of https://github…
AhmedSobhy01 Apr 4, 2024
34fac75
:fire: Completed most of the Random generator's logic + Initialized a…
habibayman Apr 4, 2024
1a1845e
:hammer: Fixed files causing build errors
AhmedSobhy01 Apr 4, 2024
40a651a
:memo: Removed unnecessary cout lines
AhmedSobhy01 Apr 4, 2024
0767717
:construction: completed the RaandGen and tested it
habibayman Apr 5, 2024
5cb601d
:tada: completed the RandGen and Army adding process
habibayman Apr 5, 2024
507bcfd
Merge branch 'main' into feature/Game-RandomGenerator-classes
AhmedSobhy01 Apr 5, 2024
52817f0
:hammer: Fixed code typos & casting warning when building
AhmedSobhy01 Apr 5, 2024
0f31f8b
:bug: fixed some stuff in array class
HelanaNady Apr 5, 2024
ffd80d8
:white_check_mark: Added the health parameter initial check
habibayman Apr 6, 2024
563f5ad
:bug: Fixed another circular dependancy issue between Game & Unit cla…
habibayman Apr 6, 2024
fa49977
:recycle: Refactored Unit Classes
AhmedSobhy01 Apr 6, 2024
73110e0
:memo: Updated CMakeLists
AhmedSobhy01 Apr 6, 2024
59ff797
Merge branch 'feature/Game-RandomGenerator-classes' of https://github…
HelanaNady Apr 6, 2024
d9595d4
:memo: changed generateArmy function
HelanaNady Apr 6, 2024
99b317b
:bug: updated header of RandomGenerator
HelanaNady Apr 6, 2024
5db1a26
:bug: adjusted the units' initial health condition
habibayman Apr 6, 2024
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
7 changes: 7 additions & 0 deletions Alien-Invasion.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,16 @@
<ClCompile Include="Game.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="RandomGenerator\RandomGenerator.cpp" />
<ClCompile Include="UnitClasses\AlienDrone.cpp" />
<ClCompile Include="UnitClasses\AlienMonster.cpp" />
<ClCompile Include="UnitClasses\AlienSoldier.cpp" />
<ClCompile Include="UnitClasses\EarthGunnery.cpp" />
<ClCompile Include="UnitClasses\EarthSoldier.cpp" />
<ClCompile Include="UnitClasses\EarthTank.cpp" />
<ClCompile Include="UnitClasses\Unit.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="Containers\Array.h" />
<ClInclude Include="Containers\ArrayStack.h" />
<ClInclude Include="Containers\Deque.h" />
<ClInclude Include="Containers\LinkedQueue.h" />
Expand Down
21 changes: 21 additions & 0 deletions Alien-Invasion.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
<ClInclude Include="Containers\ArrayStack.h">
<Filter>Containers Classes</Filter>
</ClInclude>
<ClInclude Include="Containers\Array.h">
<Filter>Containers Classes</Filter>
</ClInclude>
<ClInclude Include="UnitClasses\AlienDrone.h">
<Filter>Unit Classes</Filter>
</ClInclude>
Expand Down Expand Up @@ -99,5 +102,23 @@
<ClCompile Include="Game.cpp">
<Filter>Game Class</Filter>
</ClCompile>
<ClCompile Include="UnitClasses\EarthSoldier.cpp">
<Filter>Unit Classes</Filter>
</ClCompile>
<ClCompile Include="UnitClasses\AlienMonster.cpp">
<Filter>Unit Classes</Filter>
</ClCompile>
<ClCompile Include="UnitClasses\AlienDrone.cpp">
<Filter>Unit Classes</Filter>
</ClCompile>
<ClCompile Include="UnitClasses\AlienSoldier.cpp">
<Filter>Unit Classes</Filter>
</ClCompile>
<ClCompile Include="UnitClasses\EarthGunnery.cpp">
<Filter>Unit Classes</Filter>
</ClCompile>
<ClCompile Include="UnitClasses\EarthTank.cpp">
<Filter>Unit Classes</Filter>
</ClCompile>
</ItemGroup>
</Project>
20 changes: 13 additions & 7 deletions ArmyClasses/AlienArmy.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
#include <iostream>

#include "AlienArmy.h"
#include "../UnitClasses/Unit.h"

void AlienArmy::addUnit()
void AlienArmy::addUnit(Unit* unit)
{
if (unit->getUnitType() == UnitType::AS)
soldiers.enqueue(dynamic_cast<AlienSoldier*>(unit));
//else if (unit->getUnitType() == UnitType::AM)
// add it to array
else
drones.enqueue(dynamic_cast<AlienDrone*>(unit));
}

void AlienArmy::removeUnit()
{
}
{}

void AlienArmy::print() const
{
}
{}

void AlienArmy::attack()
{
}
{}
6 changes: 3 additions & 3 deletions ArmyClasses/AlienArmy.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
class AlienArmy: public Army
{
private:
LinkedQueue<AlienSoldier*> soldiers;
// Array <AlienMonster> monsters;
LinkedQueue<AlienSoldier*> soldiers;
// Array <AlienMonster*> monsters;
Deque<AlienDrone*> drones;

public:
void addUnit();
void addUnit(Unit*);
void removeUnit();
void print() const;
void attack();
Expand Down
4 changes: 3 additions & 1 deletion ArmyClasses/Army.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#ifndef ARMY_H
#define ARMY_H

#include "../UnitClasses/Unit.h"

class Army
{
public:
virtual void addUnit() = 0; // Will take a pointer to Unit as a parameter
virtual void addUnit(Unit*) = 0; // Will take a pointer to Unit as a parameter
virtual void removeUnit() = 0;
virtual void print() const = 0;
virtual void attack() = 0;
Expand Down
20 changes: 13 additions & 7 deletions ArmyClasses/EarthArmy.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
#include <iostream>

#include "EarthArmy.h"
#include "../UnitClasses/Unit.h"

void EarthArmy::addUnit()
void EarthArmy::addUnit(Unit* unit)
{
if (unit->getUnitType() == UnitType::ES)
soldiers.enqueue(dynamic_cast<EarthSoldier*>(unit));
else if (unit->getUnitType() == UnitType::ET)
tanks.push(dynamic_cast<EarthTank*>(unit));
else if (unit->getUnitType() == UnitType::EG)
gunneries.enqueue(dynamic_cast<EarthGunnery*>(unit), unit->getHealth() + unit->getPower());
}

void EarthArmy::removeUnit()
{
}
{}

void EarthArmy::print() const
{
}
{}

void EarthArmy::attack()
{
}
{}
2 changes: 1 addition & 1 deletion ArmyClasses/EarthArmy.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class EarthArmy: public Army
PriorityQueue<EarthGunnery*> gunneries;

public:
void addUnit();
void addUnit(Unit*);
void removeUnit();
void print() const;
void attack();
Expand Down
13 changes: 12 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,15 @@ add_executable(Alien_Invasion
Containers/PriorityNode.h
Containers/PriorityQueue.h
Containers/QueueADT.h
Containers/StackADT.h)
Containers/StackADT.h
RandomGenerator/RandomGenerator.cpp
UnitClasses/AlienDrone.cpp
UnitClasses/AlienMonster.cpp
UnitClasses/AlienSoldier.cpp
UnitClasses/EarthGunnery.cpp
UnitClasses/EarthSoldier.cpp
UnitClasses/EarthTank.cpp
UnitClasses/Unit.cpp
Game.cpp
ArmyClasses/AlienArmy.cpp
ArmyClasses/EarthArmy.cpp)
83 changes: 83 additions & 0 deletions Containers/Array.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#ifndef ARRAY_H
#define ARRAY_H

#include <iostream>

template<typename T>
class Array
{
enum { MAX_SIZE = 1000 };
private:
T items[MAX_SIZE];
int count;

public:
Array();
bool isEmpty() const;
bool insert(const T newEntry);
bool remove(int index);
bool entryAt(T entry, int index) const;
void printList() const;
int getCount() const;
};


template <typename T>
inline Array<T>::Array() : count(0)
{}

template <typename T>
inline bool Array<T>::isEmpty() const
{
return (count == 0);
}

template <typename T>
inline bool Array<T>::insert(const T newEntry)
{
if (count == MAX_SIZE - 1) return false;

items[count++] = newEntry;
return true;
}

template <typename T>
inline bool Array<T>::remove(int index)
{
if (index >= count) return false;

items[index] = items[count - 1];
items[count - 1] = nullptr;
count--;

return true;
}

template <typename T>
inline bool Array<T>::entryAt(T entry, int index) const
{
if (isEmpty()) return false;

entry = items[index];
return true;
}

template <typename T>
inline void Array<T>::printList() const
{
for (int i = 0; i < count; i++)
{
std::cout << items[i];
if (i != count - 1)
std::cout << ", ";
}
std::cout << std::endl;
}

template <typename T>
inline int Array<T>::getCount() const
{
return count;
}

#endif
2 changes: 1 addition & 1 deletion Containers/ArrayStack.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ArrayStack: public StackADT<T>

template<typename T>
inline ArrayStack<T>::ArrayStack(): top(-1)
{ }
{}

template<typename T>
inline bool ArrayStack<T>::isEmpty() const
Expand Down
2 changes: 1 addition & 1 deletion Containers/LinkedQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class LinkedQueue: public QueueADT<T>

template <typename T>
inline LinkedQueue<T>::LinkedQueue():itemCount(0), backPtr(nullptr), frontPtr(nullptr)
{ }
{}

template <typename T>
inline bool LinkedQueue<T>::isEmpty() const
Expand Down
4 changes: 2 additions & 2 deletions Containers/Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ class Node
template < typename T>
inline Node<T>::Node()
: prev(nullptr), next(nullptr)
{ }
{}

template < typename T>
inline Node<T>::Node(const T& item)
: item(item), prev(nullptr), next(nullptr)
{ }
{}

template < typename T>
inline Node<T>::Node(const T& item, Node<T>* prevNodePtr, Node<T>* nextNodePtr)
Expand Down
2 changes: 1 addition & 1 deletion Containers/PriorityQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class PriorityQueue

template <typename T>
inline PriorityQueue<T>::PriorityQueue(): head(nullptr), itemCount(0)
{ }
{}

// Insert the new node in its correct position according to its priority
template <typename T>
Expand Down
2 changes: 1 addition & 1 deletion Containers/QueueADT.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ class QueueADT

virtual bool peek(T& FrontEntry) const = 0;

virtual ~QueueADT() { }
virtual ~QueueADT() {}
};
#endif
2 changes: 1 addition & 1 deletion Containers/StackADT.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class StackADT

virtual bool peek(T& TopEntry) const = 0;

virtual ~StackADT() { }
virtual ~StackADT() {}
};
#endif

10 changes: 10 additions & 0 deletions DEFS.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,14 @@ struct Range {
int max;
};

enum ArmyType {
EARTH, ALIEN
};

enum UnitType
{
ES, EG, ET,
AS, AD, AM
};

#endif
50 changes: 48 additions & 2 deletions Game.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,55 @@
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>

#include "Game.h"
#include "DEFS.h"
#include "UnitClasses/Unit.h"

Game::Game(): gameMode(GameMode::INTERACTIVE), currentTimestep(0)
std::string Game::loadFile(std::string fileName)
{
std::fstream fin(fileName);
std::string wholeFile;

if (fin.is_open())
{
std::string newLine;
while (std::getline(fin, newLine))
wholeFile += newLine + " ";
}
return wholeFile;
}

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

void Game::run(GameMode gameMode, std::string inputFileName)
{
this->gameMode = gameMode;

std::string inputParameters = loadFile(inputFileName);
randomGenerator = new RandomGenerator(this, inputParameters);
}

void Game::incrementTimestep()
{}

void Game::changeGameMode(GameMode)
{}

void Game::addUnit(Unit* unit)
{
if (unit->getArmyType() == ArmyType::EARTH)
earthArmy.addUnit(unit);
else if (unit->getArmyType() == ArmyType::ALIEN)
alienArmy.addUnit(unit);
}

int Game::getCurrentTimestep() const
{
return currentTimestep;
}

Game::~Game()
{}
Loading
Loading