-
Notifications
You must be signed in to change notification settings - Fork 1
/
AddCoinsetAction.cpp
67 lines (51 loc) · 1.88 KB
/
AddCoinsetAction.cpp
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
#include "Input.h"
#include "Output.h"
#include "AddCoinsetAction.h"
#include"coinset.h"
AddCoinsetAction::AddCoinsetAction(ApplicationManager *pApp) : Action(pApp)
{
// Initializes the pManager pointer of Action with the passed pointer
}
AddCoinsetAction::~AddCoinsetAction()
{
}
void AddCoinsetAction::ReadActionParameters()
{
// Get a Pointer to the Input / Output Interfaces
Grid* pGrid = pManager->GetGrid();
Output* pOut = pGrid->GetOutput();
Input* pIn = pGrid->GetInput();
int x=0;int y=0;
// Read the wallet value parameter
do{
pGrid->GetOutput()->PrintMessage("Enter a positive value of the coinset,click to continue");
pGrid->GetInput()->GetPointClicked(x,y);
wallet=pGrid->GetInput()->GetInteger(pGrid->GetOutput());
}while(wallet<0);
do{
pGrid->GetOutput()->PrintMessage("Click on a cell to add the coinset");
pos=pGrid->GetInput()->GetCellClicked();
}while(pos.IsValidCell()==false);
///TODO: Make the needed validations on the read parameters
// Clear messages
pOut->ClearStatusBar();
}
// Execute the action
void AddCoinsetAction::Execute()
{
// The first line of any Action Execution is to read its parameter first
// and hence initializes its data members
ReadActionParameters();
// Create a Ladder object with the parameters read from the user
CoinSet * pcoin = new CoinSet(pos,wallet);
Grid * pGrid = pManager->GetGrid(); // We get a pointer to the Grid from the ApplicationManager
// Add the card object to the GameObject of its Cell:
bool added = pGrid->AddObjectToCell(pcoin);
// 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 coinset is created and added to the GameObject of its Cell, so we finished executing the AddCoinSetAction
}