-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddWaterPit.cpp
More file actions
36 lines (27 loc) · 1.09 KB
/
Copy pathAddWaterPit.cpp
File metadata and controls
36 lines (27 loc) · 1.09 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
#include "AddWaterPit.h"
#include "WaterPit.h" // Ensure WaterPit definition is included
AddWaterPit::AddWaterPit(ApplicationManager* pApp) : Action(pApp) {}
void AddWaterPit::ReadActionParameters() {
Grid* pGrid = pManager->GetGrid();
Output* pOut = pGrid->GetOutput();
Input* pIn = pGrid->GetInput();
pOut->PrintMessage("New Water Pit: Click on its Cell ...");
WaterPitpos = pIn->GetCellClicked();
if (!WaterPitpos.IsValidCell()) {
pOut->PrintMessage("Invalid cell! Click anywhere to continue.");
pIn->GetCellClicked();
return;
}
pOut->ClearStatusBar();
}
void AddWaterPit::Execute() {
ReadActionParameters();
WaterPit* pWaterPit = new WaterPit(WaterPitpos); // Instantiate WaterPit
Grid* pGrid = pManager->GetGrid();
bool added = pGrid->AddObjectToCell(pWaterPit); // Pass to AddObjectToCell
if (!added) {
delete pWaterPit; // Avoid memory leak
pGrid->PrintErrorMessage("Error: Cell already has an object! Click to continue ...");
}
}
AddWaterPit::~AddWaterPit() {}