-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddFlagAction.cpp
More file actions
84 lines (61 loc) · 2.18 KB
/
Copy pathAddFlagAction.cpp
File metadata and controls
84 lines (61 loc) · 2.18 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
#include "AddFlagAction.h"
AddFlagAction::AddFlagAction(ApplicationManager *pApp) : Action(pApp)
{
// Initializes the pManager pointer of Action with the passed pointer
}
void AddFlagAction::ReadActionParameters()
{
///TODO: Implement this function as mentioned in the guideline steps (numbered below) below
// == Here are some guideline steps (numbered below) to implement this function ==
// 1- Get a Pointer to the Input / Output Interfaces
Grid* pGrid = pManager->GetGrid();
Output* pOut = pGrid->GetOutput();
Input* pIn = pGrid->GetInput();
// 2- Read the flagPos
pOut->PrintMessage("New Flag: Click on its Cell ...");
flagPos = pIn->GetCellClicked();
// 4- Make the needed validations on the read parameters
while (!flagPos.IsValidCell() || flagPos.GetCellNum() == 1)
{
pGrid->PrintErrorMessage("Error: Invalid Cell! Click to continue ...");
pOut->PrintMessage("New Flag: Click on its Cell ...");
flagPos = pIn->GetCellClicked();
}
// 5- Clear status bar
pOut->ClearStatusBar();
}
void AddFlagAction::resetisflag()
{
AddFlagAction::isFlagAdded = false;
}
void AddFlagAction::Execute()
{
// The first line of any Action Execution is to read its parameter first
// and hence initializes its data members
ReadActionParameters();
///TODO: Implement this function as mentioned in the guideline steps (numbered below) below
// == Here are some guideline steps (numbered below) to implement this function ==
// 1-Create a flag object
Flag* pFlag = new Flag(flagPos);
// 2-get a pointer to the Grid from the ApplicationManager
Grid* pGrid = pManager->GetGrid();
if (AddFlagAction::isFlagAdded)
{
pGrid->PrintErrorMessage("Error: You can't add more than one flag ! Click to continue ...");
return;
}
// 3-Add the flag object to the GameObject of its Cell:
bool added = pGrid->AddObjectToCell(pFlag);
// 4-Check if the flag was added and print an errror message if flag couldn't be added
if (!added)
{
pGrid->PrintErrorMessage("Error: Cell already has an object ! Click to continue ...");
}
else {
AddFlagAction::isFlagAdded = true;
}
}
AddFlagAction::~AddFlagAction()
{
}
bool AddFlagAction::isFlagAdded = false; //initializing the static data member to false