-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddFlagAction.cpp
More file actions
83 lines (55 loc) · 2.21 KB
/
Copy pathAddFlagAction.cpp
File metadata and controls
83 lines (55 loc) · 2.21 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
#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(" Click on the cell where you want to place the flag... ");
flagPos = pIn->GetCellClicked();
// 4- Make the needed validations on the read parameters
if (!flagPos.IsValidCell()||flagPos.GetCellNum()==1)
{
pOut->PrintMessage("Invalid cell position! Operation cancelled.");
flagPos = CellPosition(-1, -1); // Reset the position to invalid
return;
}
// 5- Clear status bar
pOut->ClearStatusBar();
}
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();
// 3- check if there is a flag in the grid and if true print error massage
if (pGrid->HasFlag()) {
pGrid->PrintErrorMessage("Error: A flag already exists on the grid! Cannot add another one.");
return;
}
// 4-Add the flag object to the GameObject of its Cell:
bool added = pGrid->AddObjectToCell(pFlag);
// 5-Check if the flag was added and print an errror message if flag couldn't be added
if (!added)
{
// Print an appropriate message
pGrid->PrintErrorMessage("Error: Cell already has an object ! Click to continue ...");
return;
}
}
AddFlagAction::~AddFlagAction()
{
}