-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCell.cpp
More file actions
105 lines (77 loc) · 2.26 KB
/
Copy pathCell.cpp
File metadata and controls
105 lines (77 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include "Cell.h"
#include "Grid.h"
#include "GameObject.h"
#include "Belt.h"
#include "WaterPit.h"
#include "Player.h"
#include "DangerZone.h"
#include "Output.h"
#include "Antenna.h"
#include "Flag.h"
Cell::Cell(const CellPosition & pos) : position(pos)
{
// initializes the data members (position & pGameObject)
pGameObject = NULL;
}
Cell::Cell(int v, int h) : position(v, h)
{
// initializes the data members (position & pGameObject)
pGameObject = NULL;
}
// ======= Setters and Getters Functions =======
CellPosition Cell::GetCellPosition() const
{
return position;
}
bool Cell::SetGameObject(GameObject * pGObj)
{
if (pGameObject != NULL && pGObj != NULL) // already contains one
return false; // do NOT add it and return false
pGameObject = pGObj;
return true;
}
GameObject * Cell::GetGameObject() const
{
return pGameObject;
}
Belt * Cell::HasBelt() const
{
return dynamic_cast<Belt *>(pGameObject);
}
Antenna* Cell::HasAntenna() const
{
return dynamic_cast<Antenna*>(pGameObject);
}
Flag * Cell::HasFlag() const
{
///TODO: Implement the following function like HasBelt() function
return dynamic_cast<Flag*>(pGameObject);
}
WaterPit * Cell::HasWaterPit() const
{
///TODO: Implement the following function like HasBelt() function
return false; // THIS LINE SHOULD CHANGED WITH YOUR IMPLEMENTATION
}
DangerZone * Cell::HasDangerZone() const
{
///TODO: Implement the following function like HasBelt() function
return false; // THIS LINE SHOULD CHANGED WITH YOUR IMPLEMENTATION
}
// ======= Drawing Functions =======
void Cell::DrawCellOrWaterPitOrDangerZone(Output* pOut) const
{
// Checks if there is a dangerzone or a waterpit on the cell
if (HasDangerZone()||HasWaterPit()) // means if not NULL
pGameObject->Draw(pOut); // draw the dangerzone or waterpit then
else
pOut->DrawCell(position,UI.CellColor); // draw empty cell
}
// separate from the above function
//because other game objects should be drawn AFTER All Cells are drawn
//because other game objects don't change color of the cell
void Cell::DrawGameObject(Output* pOut) const
{
//TODO: edit this incomplete implemntation to check for other game objects (excluding waterpits and dangerzones)
if (HasFlag()|| HasBelt() || HasAntenna())
pGameObject->Draw(pOut); // draw game object
}