-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPasteCardAction.cpp
More file actions
132 lines (118 loc) · 3.12 KB
/
PasteCardAction.cpp
File metadata and controls
132 lines (118 loc) · 3.12 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include "PasteCardAction.h"
#include "Input.h"
#include "Output.h"
#include "Card.h"
#include "CardOne.h"
#include "CardTwo.h"
#include "CardThree.h"
#include "CardFour.h"
#include "CardFive.h"
#include "CardSix.h"
#include "CardSeven.h"
#include "CardEight.h"
#include "CardNine.h"
#include "CardTen.h"
#include "CardEleven.h"
#include "CardTwelve.h"
#include "CardThirteen.h"
PasteCardAction::PasteCardAction(ApplicationManager* pApp) : Action(pApp)
{
// Initializes the pManager pointer of Action with the passed pointer
}
PasteCardAction::~PasteCardAction()
{
}
bool PasteCardAction::ReadActionParameters()
{
// Get a Pointer to the Input / Output Interfaces
Grid* pGrid = pManager->GetGrid();
Output* pOut = pGrid->GetOutput();
Input* pIn = pGrid->GetInput();
pOut->PrintMessage("Paste Card: click on the destination cell");
destinationcardPosition = pIn->GetCellClicked();
if (!destinationcardPosition.IsValidCell())
{
return false;
}
// Clear messages
pOut->ClearStatusBar();
return true;
}
void PasteCardAction::Execute()
{
Grid* pGrid = pManager->GetGrid();
Output* pOut = pGrid->GetOutput();
if (!ReadActionParameters())
{
pGrid->PrintErrorMessage("Error: Invalid cell ! Click to continue ...");
return;
}
Card* destinationcard = NULL;
Card* sourcecard = pGrid->GetClipboard();
if (sourcecard)
{
switch (sourcecard->GetCardNumber())
{
case 1:
destinationcard = new CardOne(destinationcardPosition, sourcecard);
break;
case 2:
destinationcard = new CardTwo(destinationcardPosition, sourcecard);
break;
case 3:
destinationcard = new CardThree(destinationcardPosition);
break;
case 4:
destinationcard = new CardFour(destinationcardPosition);
break;
case 5:
destinationcard = new CardFive(destinationcardPosition);
break;
case 6:
destinationcard = new CardSix(destinationcardPosition);
break;
case 7:
destinationcard = new CardSeven(destinationcardPosition);
break;
case 8:
destinationcard = new CardEight(destinationcardPosition);
break;
case 9:
destinationcard = new CardNine(destinationcardPosition, sourcecard);
break;
case 10:
destinationcard = new CardTen(destinationcardPosition);
break;
case 11:
destinationcard = new CardEleven(destinationcardPosition);
break;
case 12:
destinationcard = new CardTwelve(destinationcardPosition);
break;
case 13:
destinationcard = new CardThirteen(destinationcardPosition);
break;
default:
break;
}
}
else
{
pGrid->PrintErrorMessage("Error: The Clipboard is Empty");
return;
}
bool added = pGrid->AddObjectToCell(destinationcard);
if (added)
{
if (sourcecard->GetPosition().GetCellNum() == -1) delete sourcecard;
else pGrid->RemoveObjectFromCell(sourcecard->GetPosition());
pGrid->SetClipboard(NULL);
}
// D- if the GameObject cannot be added in the Cell, Print the appropriate error message on statusbar
else
{
pGrid->PrintErrorMessage("Error: Cell already has an object, Click to continue ...");
delete destinationcard;
}
return;
}