-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddBeltAction.cpp
More file actions
83 lines (59 loc) · 2.18 KB
/
Copy pathAddBeltAction.cpp
File metadata and controls
83 lines (59 loc) · 2.18 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 "AddBeltAction.h"
AddBeltAction::AddBeltAction(ApplicationManager *pApp) : Action(pApp)
{
// Initializes the pManager pointer of Action with the passed pointer
}
void AddBeltAction::ReadActionParameters()
{
// Get a Pointer to the Input / Output Interfaces
Grid* pGrid = pManager->GetGrid();
Output* pOut = pGrid->GetOutput();
Input* pIn = pGrid->GetInput();
// Read the startPos parameter
pOut->PrintMessage("New Belt: Click on its Start Cell ...");
startPos = pIn->GetCellClicked();
// Read the endPos parameter
pOut->PrintMessage("New Belt: Click on its End Cell ...");
endPos = pIn->GetCellClicked();
///TODO: Make the needed validations on the read parameters
if (!startPos.IsValidCell()&& !endPos.IsValidCell() || startPos.GetCellNum() == 1)
{
pOut->PrintMessage("Invalid cell position! Operation cancelled.");
return;
}
// Clear messages
pOut->ClearStatusBar();
}
void AddBeltAction::Execute()
{
// The first line of any Action Execution is to read its parameter first
// and hence initializes its data members
ReadActionParameters();
// Create a belt object with the parameters read from the user
Belt * pBelt = new Belt(startPos, endPos);
Grid * pGrid = pManager->GetGrid(); // We get a pointer to the Grid from the ApplicationManager
// Check for overlaps and conflicts
if (pGrid->getGameobject(startPos)) {
pGrid->PrintErrorMessage("Error: Cells already has object! Operation cancelled.");
return;
}
if (pGrid->isflag(endPos)) {
pGrid->PrintErrorMessage("Error: End Cell has Flag! Operation cancelled.");
return;
}
if (pGrid->Beltsconflicts(startPos, endPos)) {
pGrid->PrintErrorMessage("Error: Belt will conflicts with existing belts! Operation cancelled.");
return;
}
bool added = pGrid->AddObjectToCell(pBelt);
// if the GameObject cannot be added
if (!added)
{
// Print an appropriate message
pGrid->PrintErrorMessage("Error: Cell already has an object ! Click to continue ...");
}
// Here, the belt is created and added to the GameObject of its Cell, so we finished executing the AddBeltAction
}
AddBeltAction::~AddBeltAction()
{
}