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

✨ Created Army Classes #7

Merged
merged 18 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 6 additions & 2 deletions Alien-Invasion.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp" />
<ClCompile Include="UnitClasses\Unit.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="Containers\ArrayStack.h" />
Expand All @@ -32,11 +33,14 @@
<ClInclude Include="Containers\StackADT.h" />
<ClInclude Include="UnitClasses\AlienDrone.h" />
<ClInclude Include="UnitClasses\AlienMonster.h" />
<ClInclude Include="UnitClasses\AlienSolider.h" />
<ClInclude Include="UnitClasses\AlienSoldier.h" />
<ClInclude Include="UnitClasses\EarthGunnery.h" />
<ClInclude Include="UnitClasses\EarthSolider.h" />
<ClInclude Include="UnitClasses\EarthSoldier.h" />
<ClInclude Include="UnitClasses\EarthTank.h" />
<ClInclude Include="UnitClasses\Unit.h" />
<ClInclude Include="ArmyClasses\Army.h" />
<ClInclude Include="ArmyClasses\EarthArmy.h" />
<ClInclude Include="ArmyClasses\AlienArmy.h" />
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>17.0</VCProjectVersion>
Expand Down
23 changes: 19 additions & 4 deletions Alien-Invasion.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Containers">
Expand All @@ -7,6 +7,9 @@
<Filter Include="UnitsClasses">
<UniqueIdentifier>{d6265d0d-9e06-4a0b-9c88-39e5e3415fa3}</UniqueIdentifier>
</Filter>
<Filter Include="ArmyClasses">
<UniqueIdentifier>{8a245181-84c7-4cb6-9cc0-a558bcaf50e4}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Containers\PriorityQueue.h">
Expand Down Expand Up @@ -39,13 +42,13 @@
<ClInclude Include="UnitClasses\AlienMonster.h">
<Filter>UnitsClasses</Filter>
</ClInclude>
<ClInclude Include="UnitClasses\AlienSolider.h">
<ClInclude Include="UnitClasses\AlienSoldier.h">
<Filter>UnitsClasses</Filter>
</ClInclude>
<ClInclude Include="UnitClasses\EarthGunnery.h">
<Filter>UnitsClasses</Filter>
</ClInclude>
<ClInclude Include="UnitClasses\EarthSolider.h">
<ClInclude Include="UnitClasses\EarthSoldier.h">
<Filter>UnitsClasses</Filter>
</ClInclude>
<ClInclude Include="UnitClasses\EarthTank.h">
Expand All @@ -56,7 +59,19 @@
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp">
<ClInclude Include="ArmyClasses\AlienArmy.h">
<Filter>ArmyClasses</Filter>
</ClInclude>
<ClInclude Include="ArmyClasses\Army.h">
<Filter>ArmyClasses</Filter>
</ClInclude>
<ClInclude Include="ArmyClasses\EarthArmy.h">
<Filter>ArmyClasses</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp" />
<ClCompile Include="UnitClasses\Unit.cpp">
<Filter>UnitsClasses</Filter>
</ClCompile>
</ItemGroup>
Expand Down
20 changes: 20 additions & 0 deletions ArmyClasses/AlienArmy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef ALIEN_ARMY_H
#define ALIEN_ARMY_H

#include "Army.h"
#include "..\Containers\LinkedQueue.h"
#include "..\Containers\ArrayStack.h"
#include "..\Containers\Deque.h"
#include "..\UnitClasses\Unit.h"
#include "..\UnitClasses\AlienSoldier.h"
#include "..\UnitClasses\AlienMonster.h"
#include "..\UnitClasses\AlienDrone.h"

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

#endif
14 changes: 14 additions & 0 deletions ArmyClasses/Army.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef ARMY_H
#define ARMY_H

class Army
{
public:
virtual void addUnit() = 0; // Will take a pointer to Unit as a parameter
virtual void removeUnit() = 0;
virtual void print() const = 0;
virtual void attack() = 0;
};

#endif

21 changes: 21 additions & 0 deletions ArmyClasses/EarthArmy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef EARTH_ARMY_H
#define EARTH_ARMY_H

#include "Army.h"
#include "..\UnitClasses\Unit.h"
#include "..\Containers\ArrayStack.h"
#include "..\Containers\LinkedQueue.h"
#include "..\Containers\PriorityQueue.h"
#include "..\UnitClasses\Unit.h"
#include "..\UnitClasses\EarthSoldier.h"
#include "..\UnitClasses\EarthTank.h"
#include "..\UnitClasses\EarthGunnery.h"

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

#endif
15 changes: 7 additions & 8 deletions Containers/ArrayStack.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#ifndef ARRAYSTACK_H
#define ARRAYSTACK_H
#ifndef ARRAY_STACK_H
#define ARRAY_STACK_H

#include <iostream>
#include "StackADT.h"

// The default size is 100
// The default size is 1000
template<typename T>
class ArrayStack : public StackADT<T>
class ArrayStack: public StackADT<T>
{
enum { MAX_SIZE = 1000 };
private:
Expand All @@ -22,11 +22,10 @@ class ArrayStack : public StackADT<T>
void printList() const;
int getCount() const;
};
#endif

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

template<typename T>
inline bool ArrayStack<T>::isEmpty() const
Expand Down Expand Up @@ -79,4 +78,4 @@ inline int ArrayStack<T>::getCount() const
return top + 1;
}


#endif
8 changes: 4 additions & 4 deletions Containers/Deque.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#ifndef DEQUE_
#define DEQUE_
#ifndef DEQUE_H
#define DEQUE_H

#include "LinkedQueue.h"

template <typename T>
class Deque : public LinkedQueue<T>
class Deque: public LinkedQueue<T>
{
public:
bool dequeueBack(T& backEntry);
bool peekBack(T& backEntry);
};

template<typename T>
bool Deque<T>::dequeueBack(T& backEntry)
inline bool Deque<T>::dequeueBack(T& backEntry)
{
if (LinkedQueue<T> ::isEmpty())
return false;
Expand Down
20 changes: 10 additions & 10 deletions Containers/LinkedQueue.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#ifndef LINKED_QUEUE_
#define LINKED_QUEUE_
#ifndef LINKED_QUEUE_H
#define LINKED_QUEUE_H

#include <iostream>
#include "Node.h"
#include "QueueADT.h"

template <typename T>
class LinkedQueue :public QueueADT<T>
class LinkedQueue: public QueueADT<T>
{
protected:
Node<T>* backPtr;
Expand All @@ -24,17 +24,17 @@ class LinkedQueue :public QueueADT<T>
};

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

template <typename T>
bool LinkedQueue<T>::isEmpty() const
inline bool LinkedQueue<T>::isEmpty() const
{
return (frontPtr == nullptr);
}

template <typename T>
bool LinkedQueue<T>::enqueue(const T& newEntry)
inline bool LinkedQueue<T>::enqueue(const T& newEntry)
{
Node<T>* newNodePtr = new Node<T>(newEntry);
// Insert the new node
Expand All @@ -52,7 +52,7 @@ bool LinkedQueue<T>::enqueue(const T& newEntry)
}

template <typename T>
bool LinkedQueue<T>::dequeue(T& frontEntry)
inline bool LinkedQueue<T>::dequeue(T& frontEntry)
{
if (isEmpty())
return false;
Expand All @@ -74,7 +74,7 @@ bool LinkedQueue<T>::dequeue(T& frontEntry)
}

template <typename T>
bool LinkedQueue<T>::peek(T& frontEntry) const
inline bool LinkedQueue<T>::peek(T& frontEntry) const
{
if (isEmpty())
return false;
Expand Down Expand Up @@ -106,7 +106,7 @@ inline int LinkedQueue<T>::getCount() const
}

template <typename T>
LinkedQueue<T>::~LinkedQueue()
inline LinkedQueue<T>::~LinkedQueue()
{
T temp;
while (dequeue(temp));
Expand Down
27 changes: 14 additions & 13 deletions Containers/Node.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef _NODE
#define _NODE
#ifndef NODE_H
#define NODE_H

template <typename T>
class Node
Expand All @@ -19,33 +19,32 @@ class Node
T getItem() const;
Node<T>* getPrev() const;
Node<T>* getNext() const;
}; // end Node
#endif
};

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

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

template < typename T>
Node<T>::Node(const T& item, Node<T>* prevNodePtr, Node<T>* nextNodePtr)
inline Node<T>::Node(const T& item, Node<T>* prevNodePtr, Node<T>* nextNodePtr)
: item(item), prev(prevNodePtr), next(nextNodePtr)
{

}
template < typename T>
void Node<T>::setItem(const T& item)
inline void Node<T>::setItem(const T& item)
{
this->item = item;
}

template < typename T>
void Node<T>::setNext(Node<T>* nextNodePtr)
inline void Node<T>::setNext(Node<T>* nextNodePtr)
{
next = nextNodePtr;
}
Expand All @@ -58,19 +57,21 @@ inline void Node<T>::setPrev(Node<T>* prevNodePtr)


template < typename T>
T Node<T>::getItem() const
inline T Node<T>::getItem() const
{
return item;
}

template<typename T>
Node<T>* Node<T>::getPrev() const
inline Node<T>* Node<T>::getPrev() const
{
return prev;
}

template < typename T>
Node<T>* Node<T>::getNext() const
inline Node<T>* Node<T>::getNext() const
{
return next;
}
}

#endif
Loading
Loading