/
CutCardAction.cpp
51 lines (44 loc) · 1.4 KB
/
CutCardAction.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
#include "CutCardAction.h"
#include "ApplicationManager.h"
#include "Card.h"
#include "GameObject.h"
CutCardAction::CutCardAction(ApplicationManager* pApp) : Action(pApp)
{
// Initializes the pManager pointer of Action with the passed pointer
}
void CutCardAction::ReadActionParameters()
{
// Get a Pointer to the Input / Output Interfaces
Grid* pGrid = pManager->GetGrid();
Output* pOut = pGrid->GetOutput();
Input* pIn = pGrid->GetInput();
do {
pOut->PrintMessage("click on cell with card to cut .......");
cardPosition=pIn->GetCellClicked();
} while (cardPosition.IsValidCell() != true);
// 5- Clear status bar
pOut->ClearStatusBar();
}
void CutCardAction::Execute()
{
// 1- The first line of any Action Execution is to read its parameter first
ReadActionParameters();
Grid* pGrid = pManager->GetGrid();
Card* CardinCell= dynamic_cast<Card*>(pGrid->GetGameObject(cardPosition)); //get card object in the cell if there's one
if (CardinCell)
{
pGrid->SetClipboard(CardinCell); // putting it in clipboard
pGrid->RemoveObjectFromCell(cardPosition); // removing card from the cell
//update interface
pGrid->UpdateInterface();
pGrid->PrintErrorMessage("Successfully Card "+to_string(CardinCell->GetCardNumber())+" was cut ,click to continue!");
}
else
{
pGrid->PrintErrorMessage("error cannot cut ,No Card was found ,click to continue!");
return;
}
}
CutCardAction::~CutCardAction()
{
}