-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddWaterPitAction.cpp
More file actions
49 lines (39 loc) · 1.25 KB
/
Copy pathAddWaterPitAction.cpp
File metadata and controls
49 lines (39 loc) · 1.25 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
#include "AddWaterPitAction.h"
AddWaterPitAction::AddWaterPitAction(ApplicationManager* pApp) : Action(pApp)
{
}
void AddWaterPitAction::ReadActionParameters()
{
Grid* pGrid = pManager->GetGrid();
Input* pIn = pGrid->GetInput();
Output* pOut = pGrid->GetOutput();
pOut->PrintMessage("Click on a cell to place the Water Pit.");
WaterPitPos = pIn->GetCellClicked();
if (!(WaterPitPos.IsValidGameObjectCell()) || !(pGrid->IsCellEmpty(WaterPitPos)))
{
pOut->PrintMessage("Invalid cell selected, The Action is canceled. Click to continue");
int x, y;
pIn->GetPointClicked(x, y);
WaterPitPos = CellPosition(-1, -1);
return;
}
pOut->ClearStatusBar();
}
void AddWaterPitAction::Execute()
{
ReadActionParameters();
Grid* pGrid = pManager->GetGrid();
if (!(WaterPitPos.IsValidGameObjectCell()))
return;
WaterPit* pWaterPit = new WaterPit(WaterPitPos);
bool empty = pGrid->AddObjectToCell(pWaterPit);
if (!empty)
{
pGrid->PrintErrorMessage("Cannot add WaterPit, Cell is invalid or occupied, Click to continue.");
delete pWaterPit;
return;
}
}
AddWaterPitAction::~AddWaterPitAction()
{
}