-
Notifications
You must be signed in to change notification settings - Fork 0
/
CutCard.cpp
49 lines (44 loc) · 1.19 KB
/
CutCard.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
#include "CutCard.h"
#include "Input.h"
#include "Output.h"
#include "Card.h"
CutCardAction::CutCardAction(ApplicationManager *pApp) : Action(pApp)
{
// Initializes the pManager pointer of Action with the passed pointer
check = true;
Pcard = NULL;
}
CutCardAction::~CutCardAction()
{
}
void CutCardAction::ReadActionParameters()
{
Grid* pGrid = pManager->GetGrid(); // We get a pointer to the Grid from the ApplicationManager
pGrid->GetOutput()->PrintMessage("Click on the source cell");
CardPos = pGrid->GetInput()->GetCellClicked();
if (!CardPos.IsValidCell()) {
pGrid->GetOutput()->PrintMessage("Error: not a valid cell. Click to continue...");
check = false;
return;
}
Pcard = dynamic_cast<Card*>(pGrid->GetCellWithPos(CardPos)->GetGameObject());
}
// Execute the action
void CutCardAction::Execute()
{
ReadActionParameters();
if (check) {
Grid* pGrid = pManager->GetGrid();
if (Pcard)
{
pGrid->SetClipboard(Pcard); //if it contained a card then set clipboard
pGrid->RemoveObjectFromCell(CardPos);
}
else
{
//cell doesnt contain a card then cancel operation
return;
}
pGrid->GetOutput()->ClearStatusBar();
}
}