-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddRotatingGearAction.cpp
More file actions
73 lines (57 loc) · 1.71 KB
/
Copy pathAddRotatingGearAction.cpp
File metadata and controls
73 lines (57 loc) · 1.71 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
#include "AddRotatingGearAction.h"
#include "Input.h"
#include "Output.h"
#include "Grid.h"
#include "RotatingGear.h"
AddRotatingGearAction::AddRotatingGearAction(ApplicationManager * pApp):Action(pApp)
{
}
void AddRotatingGearAction::ReadActionParameters()
{
Grid* pGrid = pManager->GetGrid();
Input* pIn = pGrid->GetInput();
Output* pOut = pGrid->GetOutput();
pOut->PrintMessage("Click on a cell to place the RotatingGear.");
gearPos = pIn->GetCellClicked();
if (!(gearPos.IsValidGameObjectCell()) || !(pGrid->IsCellEmpty(gearPos)))
{
pOut->PrintMessage("Invalid cell selected! The Action is canceled. Click to continue");
int x, y;
pIn->GetPointClicked(x, y);
gearPos = CellPosition(-1, -1);
return;
}
pOut->PrintMessage("Enter rotation direction (0 for counterclockwise, 1 for clockwise) ");
int rotationDirection = pIn->GetInteger(pOut);
if (rotationDirection != 0 && rotationDirection != 1)
{
pOut->PrintMessage("Invalid rotation direction entered! Action is canceled.");
return;
}
this->gearPos = gearPos;
this->clockwise = rotationDirection;
pOut->ClearStatusBar();
}
void AddRotatingGearAction::Execute()
{
ReadActionParameters();
Grid* pGrid = pManager->GetGrid();
Output* pOut = pGrid->GetOutput();
RotatingGear* pGear = new RotatingGear(gearPos, clockwise);
bool addedgear = pGrid->AddObjectToCell(pGear);
if (!addedgear)
{
pOut->PrintMessage("Couldn't add the rotating gear. The cell is occupied.");
delete pGear;
}
else
{
if (pGear->GetisClockWise())
pOut->PrintMessage("Rotating gear (Clockwise) added successfully!");
else
pOut->PrintMessage("Rotating gear (Counterclockwise) added successfully!");
}
}
AddRotatingGearAction::~AddRotatingGearAction()
{
}