-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCopyCardAction.cpp
55 lines (36 loc) · 1.51 KB
/
CopyCardAction.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
#include "CopyCardAction.h"
#include"Grid.h"
#include"CellPosition.h"
CopyCardAction::CopyCardAction(ApplicationManager* pApp) :Action(pApp) {
}
void CopyCardAction::ReadActionParameters() {
Grid* pGrid = pManager->GetGrid();
Output* pOut = pGrid->GetOutput();
Input* pIn = pGrid->GetInput();
pOut->PrintMessage("Click On A Card...");
CellPosition CopiedPos = pIn->GetCellClicked(); //the postion of the card copied
CopiedCard = pGrid->GetCell(CopiedPos.VCell(), CopiedPos.HCell())->HasCard(); //checks if the cell clicked contains a card
if (CopiedCard == NULL) // if there is a card in the cell clicked
{
pGrid->PrintErrorMessage("No Cards Here! Click to continue...");
return;
}
pOut->ClearStatusBar();
} // Reads parameters required for action to execute
// (code depends on action type so virtual)
void CopyCardAction::Execute() {
ReadActionParameters();
Grid* pGrid = pManager->GetGrid();
if (pGrid->GetClipboard() != NULL) //checks if there is no cards in clipboard
{
// checks if the card in clipboard is cutted or not, then we delete it if cutted
if (pGrid->GetClipboard() != pGrid->GetCell(pGrid->GetClipboard()->GetPosition().VCell(), pGrid->GetClipboard()->GetPosition().HCell())->GetGameObject())
delete pGrid->GetClipboard();
}
pGrid->SetClipboard(CopiedCard);
pManager->UpdateInterface();
if (CopiedCard!= NULL)
pGrid->PrintErrorMessage("Coppied!...");
} // Executes action (code depends on action type so virtual)
CopyCardAction:: ~CopyCardAction() {
}