-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathOpenAction.cpp
More file actions
139 lines (130 loc) · 2.95 KB
/
OpenAction.cpp
File metadata and controls
139 lines (130 loc) · 2.95 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
133
134
135
136
137
138
139
#include "OpenAction.h"
#include "Output.h"
#include "Input.h"
#include "Grid.h"
#include "Ladder.h"
#include "Snake.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"
OpenAction::OpenAction(ApplicationManager* pApp) : Action(pApp)
{
// Initializes the pManager pointer of Action with the passed pointer
}
bool OpenAction::ReadActionParameters()
{
// Get a Pointer to the Input / Output Interfaces
Grid* pGrid = pManager->GetGrid();
Output* pOut = pGrid->GetOutput();
Input* pIn = pGrid->GetInput();
// Read the startPos parameter
pOut->PrintMessage("Open Grid: Enter The Name of The File ...");
filename = pIn->GetSrting(pOut);
load.open("SavedGrids/" + filename + ".txt");
if (!load.is_open() || load.eof()) return false;
// Clear messages
pOut->ClearStatusBar();
return true;
}
void OpenAction::Execute()
{
Grid* pGrid = pManager->GetGrid(); // We get a pointer to the Grid from the ApplicationManager
// The first line of any Action Execution is to read its parameter first
// and hence initializes its data members
if (!ReadActionParameters())
{
load.close();
pGrid->PrintErrorMessage("Error: Invalid File Name ! Click to continue ...");
return;
}
pGrid->ClearGrid();
int lnum;
load >> lnum;
for (int i = 0; i < lnum; i++)
{
CellPosition temp;
Ladder* pLadder = new Ladder(temp,temp);
pLadder->Read(load);
pGrid->AddObjectToCell(pLadder);
}
int snum;
load >> snum;
for (int i = 0; i < snum; i++)
{
CellPosition temp;
Snake* pSnake = new Snake(temp,temp);
pSnake->Read(load);
pGrid->AddObjectToCell(pSnake);
}
int cnum;
load >> cnum;
for (int i = 0; i < cnum; i++)
{
CellPosition temp;
int cardNumber;
load >> cardNumber;
Card* pCard = NULL; // will point to the card object type
switch (cardNumber)
{
case 1:
pCard = new CardOne(temp);
break;
case 2:
pCard = new CardTwo(temp);
break;
case 3:
pCard = new CardThree(temp);
break;
case 4:
pCard = new CardFour(temp);
break;
case 5:
pCard = new CardFive(temp);
break;
case 6:
pCard = new CardSix(temp);
break;
case 7:
pCard = new CardSeven(temp);
break;
case 8:
pCard = new CardEight(temp);
break;
case 9:
pCard = new CardNine(temp);
break;
case 10:
pCard = new CardTen(temp);
break;
case 11:
pCard = new CardEleven(temp);
break;
case 12:
pCard = new CardTwelve(temp);
break;
case 13:
pCard = new CardThirteen(temp);
break;
// A- Add the remaining cases
default:
break;
}
pCard->Read(load);
pGrid->AddObjectToCell(pCard);
}
load.close();
}
OpenAction::~OpenAction()
{
}