-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddCoinSet.cpp
More file actions
65 lines (49 loc) · 1.48 KB
/
AddCoinSet.cpp
File metadata and controls
65 lines (49 loc) · 1.48 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
#include "AddCoinSet.h"
#include "Input.h"
#include "Output.h"
AddCoinSetAction::AddCoinSetAction(ApplicationManager *pApp) : Action(pApp)
{
// Initializes the pManager pointer of Action with the passed pointer
}
AddCoinSetAction::~AddCoinSetAction()
{
}
void AddCoinSetAction::ReadActionParameters() {
Grid* pGrid = pManager->GetGrid();
Output* pOut = pGrid->GetOutput();
Input* pIn = pGrid->GetInput();
//get the cell that the user selected and set it as temporary
pOut->PrintMessage("Click on cell to add coinset ...");
CellPosition temp = pIn->GetCellClicked();
if (temp.IsValidCell()) {
this->cell = temp;
}
//get the amount of the coinset from the user input
pOut->PrintMessage("Enter amount of coins in coin set");
this->amount = pIn->GetInteger(pOut);
//then clear the status bar
pOut->ClearStatusBar();
}
void AddCoinSetAction::Execute() {
//read the parameters of the action
ReadActionParameters();
//creating a new pointer to the coinset object
Grid* pGrid = pManager->GetGrid(); //we want the grid to add the object to it
Output* pOut = pGrid->GetOutput();
Input* pIn = pGrid->GetInput();
if (cell.HCell() == -1)
{
return;
pOut->PrintMessage("Action terminated");
}
else
{
CoinSet* cset = new CoinSet(amount,cell);
bool added = pGrid->AddObjectToCell(cset);
if (!added) {
//if we failed to add the object then output an error message
pGrid->PrintErrorMessage("Error: Cell already has an object ! Click to continue ...");
}
}
}
// Mohamed Shams