-
Notifications
You must be signed in to change notification settings - Fork 1
/
CopyCardorCoin.cpp
64 lines (53 loc) · 1.73 KB
/
CopyCardorCoin.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
56
57
58
59
60
61
62
63
64
#include "CopyCardOrCoin.h"
#include "Input.h"
#include "Output.h"
#include "CoinSet.h"
#include"Card.h"
CopyCardorCoin::CopyCardorCoin(ApplicationManager* pApp) : Action(pApp)
{
// Initializes the pManager pointer of Action with the passed pointer
pManager = pApp;
}
CopyCardorCoin::~CopyCardorCoin()
{
}
void CopyCardorCoin::ReadActionParameters()
{
// Get a Pointer to the Input / Output Interfaces
Grid* pGrid = pManager->GetGrid();
Output* pOut = pGrid->GetOutput();
Input* pIn = pGrid->GetInput();
// Read the CardOrCoinCell parameter
pGrid->PrintErrorMessage("Copying a card or coinset: Double Click on the source cell you wish to copy ...");
CardOrCoinCell = pIn->GetCellClicked();
///Make the needed validations on the read parameters
if (CardOrCoinCell.IsValidCell() == 0)
{
pGrid->PrintErrorMessage("Error: Invalid Cell!!");
return;
}
// Clear messages
pOut->ClearStatusBar();
}
// Execute the action
void CopyCardorCoin::Execute()
{
//1-The first line of any Action Execution is to read its parameter first
// and hence initializes its data members
ReadActionParameters();
Grid*pGrid=pManager->GetGrid();
//2-make sure CardOrCoinCell does not have ladder or snake , if it does, return and print error message
//3-SetClipboard
GameObject* GameObj = pGrid->GetCardOrCoins(CardOrCoinCell);
if (GameObj!=NULL)
{
pGrid->SetClipboard(GameObj,0); // set the clipboard value by the selected one
}
else
{
pGrid->PrintErrorMessage("Error:This cell cannot be copied...click to return ");
return;
}
// Here, the Card/CoinSet is copied and added to the Clipboard, so we finished executing the CopyCardOrCoinsAction
pGrid->UpdateInterface();
}