-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddAntennaAction.cpp
More file actions
76 lines (50 loc) · 1.82 KB
/
Copy pathAddAntennaAction.cpp
File metadata and controls
76 lines (50 loc) · 1.82 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
#include "AddAntennaAction.h"
AddAntennaAction::AddAntennaAction(ApplicationManager* pApp) : Action(pApp)
{
// Initializes the pManager pointer of Action with the passed pointer
}
void AddAntennaAction::ReadActionParameters()
{
// 1- Get a Pointer to the Input / Output Interfaces
Grid* pGrid = pManager->GetGrid();
Output* pOut = pGrid->GetOutput();
Input* pIn = pGrid->GetInput();
// 2- Read the Antenna Position
pOut->PrintMessage(" Click on the cell where you want to place the Antenna... ");
AntennaPos = pIn->GetCellClicked();
// 4- Make the needed validations on the read parameters
if (!AntennaPos.IsValidCell() || AntennaPos.GetCellNum() == 1)
{
pOut->PrintMessage("Invalid cell position! Operation cancelled.");
AntennaPos = CellPosition(-1, -1); // Reset the position to invalid
return;
}
// 5- Clear status bar
pOut->ClearStatusBar();
}
void AddAntennaAction::Execute()
{
//1- initializes its data members :
ReadActionParameters();
// 2- Create a Antenna object :
Antenna* pAntenna = new Antenna(AntennaPos);
// 2-get a pointer to the Grid from the ApplicationManager
Grid* pGrid = pManager->GetGrid();
// 3- check if there is a Antenna in the grid and if true print error massage
if (pGrid->HasAntenna()) {
pGrid->PrintErrorMessage("Error: A Antenna already exists on the grid! Cannot add another one.");
return;
}
// 3-Add the Antenna object to the GameObject of its Cell:
bool added = pGrid->AddObjectToCell(pAntenna);
// 4-Check if the Antenna was added and print an errror message if Antenna couldn't be added
if (!added)
{
// Print an appropriate message
pGrid->PrintErrorMessage("Error: Cell already has an object ! Click to continue ...");
return;
}
}
AddAntennaAction::~AddAntennaAction()
{
}