-
Notifications
You must be signed in to change notification settings - Fork 1
/
PasteCardAction.cpp
44 lines (39 loc) · 1020 Bytes
/
PasteCardAction.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
#include "PasteCardAction.h"
#include "Input.h"
#include "Output.h"
#include "Grid.h"
#include "Card.h"
PasteCardAction::PasteCardAction(ApplicationManager* pApp) :Action(pApp)
{
}
void PasteCardAction::ReadActionParameters()
{
Grid* pGrid = pManager->GetGrid();
Input* pIn = pGrid->GetInput();
Output* pOut = pGrid->GetOutput();
pOut->PrintMessage("Click on the destination cell");
cardPosition = pIn->GetCellClicked();
}
void PasteCardAction::Execute()
{
Grid* pGrid = pManager->GetGrid();
ReadActionParameters();
Card* pCard;
pCard = pGrid->GetClipboard();
if (!pCard)
{
pGrid->PrintErrorMessage("There is no copied card!");
return;
}
Card* pnew_card;
pnew_card = pCard->GetCopy(cardPosition);
bool val = pGrid->AddObjectToCell(pnew_card);
if (!val) pGrid->PrintErrorMessage("Error: There's already an object in this cell ! Click to continue ...");
else {
pnew_card->Draw(pGrid->GetOutput());
pGrid->GetOutput()->PrintMessage("Card Pasted!");
}
}
PasteCardAction::~PasteCardAction()
{
}