-
Notifications
You must be signed in to change notification settings - Fork 0
/
CopyCard.cpp
45 lines (38 loc) · 1.14 KB
/
CopyCard.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
#include "CopyCard.h"
#include "Input.h"
#include "Output.h"
#include "Card.h"
CopyCardAction::CopyCardAction(ApplicationManager *pApp) : Action(pApp)
{
// Initializes the pManager pointer of Action with the passed pointer
Pcard = NULL;
check = true;
}
CopyCardAction::~CopyCardAction()
{
}
void CopyCardAction::ReadActionParameters()
{
Grid* pGrid = pManager->GetGrid(); // We get a pointer to the Grid from the ApplicationManager
pGrid->GetOutput()->PrintMessage("Click on 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 CopyCardAction::Execute()
{
ReadActionParameters();
if (check) {
Grid* pGrid = pManager->GetGrid(); // We get a pointer to the Grid from the ApplicationManager
if (Pcard)
pGrid->SetClipboard(Pcard);
else
return; //cancel operation if it doesnt contain a card
pGrid->GetOutput()->ClearStatusBar();
}
}