-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEditAction.cpp
More file actions
96 lines (95 loc) · 2.64 KB
/
Copy pathEditAction.cpp
File metadata and controls
96 lines (95 loc) · 2.64 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
#include "EditAction.h"
#include "Card.h"
#include "CardM10.h"
#include "CardM11.h"
#include "CardM12.h"
#include "CardM13.h"
EditAction::EditAction(ApplicationManager* pApp) : Action(pApp)
{
// Initializes the pManager pointer of Action with the passed pointer
}
EditAction::~EditAction()
{
}
void EditAction::ReadActionParameters()
{
// 1- Get a Pointer to the Input / Output Interfaces
Grid* pGrid = pManager->GetGrid();
Output* pOut = pGrid->GetOutput();
Input* pIn = pGrid->GetInput();
// 2- Read the "cardNumber" parameter and set its data member
pOut->PrintMessage("Edit : Click on cell that you want to Edit ...");
cardPosition = pIn->GetCellClicked();
// 5- Clear status bar
pOut->ClearStatusBar();
}
void readof10to13(int& p, int& f,Grid* pGrid)
{
Output* pOut = pGrid->GetOutput();
Input* pIn = pGrid->GetInput();
pOut->PrintMessage("New Card10: Enter the price: ");
p = pIn->GetInteger(pOut);
pOut->ClearStatusBar();
pOut->PrintMessage("Enter the fees: ");
f = pIn->GetInteger(pOut);
pOut->ClearStatusBar();
}
void EditAction::Execute()
{
// 1- The first line of any Action Execution is to read its parameter first
ReadActionParameters();
Grid* pGrid = pManager->GetGrid();
Output* pOut = pGrid->GetOutput();
Input* pIn = pGrid->GetInput();
if (cardPosition.IsValidCell())
{
Card* pCard = NULL;
pCard = dynamic_cast<Card*>(pGrid->GetGameObject(cardPosition));
if (pCard)
{
int price, fees;
switch ((pCard)->GetCardNumber())
{
case 1:
case 2:
case 9:
pCard->ReadCardParameters(pGrid);
pGrid->AddObjectToCell(pCard);
pOut->PrintMessage("Card cell have been Edited, Click to continue ...");
break;
case 10:
readof10to13(price, fees, pGrid);
dynamic_cast<CardM10*>(pCard)->SetPrice(price);
dynamic_cast<CardM10*>(pCard)->SetFees(fees);
break;
case 11:
readof10to13(price, fees, pGrid);
dynamic_cast<CardM11*>(pCard)->SetPrice(price);
dynamic_cast<CardM11*>(pCard)->SetFees(fees);
break;
case 12:
readof10to13(price, fees, pGrid);
dynamic_cast<CardM12*>(pCard)->SetPrice(price);
dynamic_cast<CardM12*>(pCard)->SetFees(fees);
break;
case 13:
readof10to13(price, fees, pGrid);
dynamic_cast<CardM13*>(pCard)->SetPrice(price);
dynamic_cast<CardM13*>(pCard)->SetFees(fees);
break;
default:
pOut->PrintMessage("Card cell can not be Edited, Click to continue ...");
}
}
else
{
pOut->PrintMessage("you have not Edited a card cell (check if you have choosen a card), Click to continue ...");
}
}
else
{
pOut->PrintMessage("you have not choosen a valid cell, Click to continue ...");
}
pIn->GetCellClicked();
pOut->ClearStatusBar();
}