-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathOpenGridAction.cpp
147 lines (133 loc) · 3.3 KB
/
OpenGridAction.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
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
140
141
142
143
144
145
146
147
#include "OpenGridAction.h"
#include "Grid.h"
#include "Ladder.h"
#include "Snake.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 <fstream>
OpenGridAction::OpenGridAction(ApplicationManager* pApp) : Action(pApp)
{
// Initializes the pManager pointer of Action with the passed pointer
}
OpenGridAction::~OpenGridAction()
{
}
void OpenGridAction::ReadActionParameters()
{
}
// Execute the action
void OpenGridAction::Execute()
{
int numberOfObjects = 0;
int startPos;
int endPos;
int cardNumber;
GameObject* pGameObject = NULL;
// Deleting current grid
Grid* pGrid = pManager->GetGrid();
Output* pOut = pGrid->GetOutput();
pOut->PrintMessage("Grid Opened...");
pGrid->RemoveAllObjects();
// Just a check so that if the file is corrupt nothing happens
ifstream InFile("Grid.txt");
if (InFile.fail())
return;
// Reading from the file
InFile >> numberOfObjects;
for (int i = 0; i < numberOfObjects; i++)
{
CellPosition StartCellPosition(1);
CellPosition EndCellPosition(13);
pGameObject = new Ladder(StartCellPosition, EndCellPosition);
pGameObject->Load(InFile);
pGrid->AddObjectToCell(pGameObject);
}
InFile >> numberOfObjects;
for (int i = 0; i < numberOfObjects; i++)
{
CellPosition StartCellPosition(13);
CellPosition EndCellPosition(1);
pGameObject = new Snake(StartCellPosition, EndCellPosition);
pGameObject->Load(InFile);
pGrid->AddObjectToCell(pGameObject);
}
InFile >> numberOfObjects;
for (int i = 0; i < numberOfObjects; i++)
{
InFile >> cardNumber;
CellPosition cardPos(1);
switch(cardNumber)
{
case 1:
pGameObject = new CardOne(cardPos);
pGameObject->Load(InFile);
pGrid->AddObjectToCell(pGameObject);
break;
case 2:
pGameObject = new CardTwo(cardPos);
pGameObject->Load(InFile);
pGrid->AddObjectToCell(pGameObject);
break;
case 3:
pGameObject = new CardThree(cardPos);
pGameObject->Load(InFile);
pGrid->AddObjectToCell(pGameObject);
break;
case 4:
pGameObject = new CardFour(cardPos);
pGameObject->Load(InFile);
pGrid->AddObjectToCell(pGameObject);
break;
case 5:
pGameObject = new CardFive(cardPos);
pGameObject->Load(InFile);
pGrid->AddObjectToCell(pGameObject);
break;
case 6:
pGameObject = new CardSix(cardPos);
pGameObject->Load(InFile);
pGrid->AddObjectToCell(pGameObject);
break;
case 7:
pGameObject = new CardSeven(cardPos);
pGameObject->Load(InFile);
pGrid->AddObjectToCell(pGameObject);
break;
case 8:
pGameObject = new CardEight(cardPos);
pGameObject->Load(InFile);
pGrid->AddObjectToCell(pGameObject);
break;
case 9:
pGameObject = new CardNine(cardPos);
pGameObject->Load(InFile);
pGrid->AddObjectToCell(pGameObject);
break;
case 10:
pGameObject = new CardTen(cardPos);
pGameObject->Load(InFile);
pGrid->AddObjectToCell(pGameObject);
break;
case 11:
pGameObject = new CardEleven(cardPos);
pGameObject->Load(InFile);
pGrid->AddObjectToCell(pGameObject);
break;
case 12:
pGameObject = new CardTwelve(cardPos);
pGameObject->Load(InFile);
pGrid->AddObjectToCell(pGameObject);
break;
}
}
}