-
Notifications
You must be signed in to change notification settings - Fork 1
/
model.cpp
executable file
·288 lines (265 loc) · 8.73 KB
/
model.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
#include "model.h"
#include "brick.h"
#include "gold.h"
#include <mario.h>
#include <safe.h>
#include <floor.h>
#include "darkeater.h"
#include "blood.h"
#include <splashscreen.h>
#include <header.h>
#include "flame.h"
#include "shock.h"
#include "peach.h"
#include "encart.h"
#include <QDebug>
Model::Model()
{
this->background = new QList<Background *>;
this->floors = new QList<Floor *>;
this->safes = new QList<Safe*>;
this->mushroom = new QList<Mushroom *>;
this->golds = new QList<Gold *>;
this->flames = new QList<Flame *>;
this->splashScreen = new SplashScreen(330, 170, ":images/go2.png");
this->darkEater=new QList<DarkEater *>;
this->background = new QList<Background *>;
this->header = new Header();
this->compteur = new QList<Brick*> ;
this->mysticTrees = new QList<MysticTree *>;
this->mario = new Mario(200, 340);
this->blood = new Blood(0,0);
this->shock = new Shock(0,0);
this->encart = new Encart(0,0, "");
getEncart()->setType(EncartType::NONE);
QFile fichier(":ModelMap.txt");
if(fichier.open(QIODevice::ReadOnly))
{
QTextStream in (&fichier);
while(!in.atEnd())
{
QString stock = in.readLine();
if (stock.left(6)=="LIGNEa")
{
for(int i=0;i<stock.size();++i){
if(stock.at(i).isDigit() || stock.at(i).isLetter()){
ligne1.append(stock.at(i));
}
}
}
else if (stock.left(6)=="LIGNEb")
{
for(int i=0;i<stock.size();++i){
if(stock.at(i).isDigit() || stock.at(i).isLetter()){
ligne2.append(stock.at(i));
}
}
}
else if (stock.left(6)=="LIGNEc")
{
for(int i=0;i<stock.size();++i){
if(stock.at(i).isDigit() || stock.at(i).isLetter()){
ligne3.append(stock.at(i));
}
}
}
else if (stock.left(6)=="LIGNEd")
{
for(int i=0;i<stock.size();++i){
if(stock.at(i).isDigit() || stock.at(i).isLetter()){
ligne4.append(stock.at(i));
}
}
}
else if (stock.left(6)=="LIGNEe")
{
for(int i=0;i<stock.size();++i){
if(stock.at(i).isDigit() || stock.at(i).isLetter()){
ligne5.append(stock.at(i));
}
}
}
else if (stock.left(6)=="LIGNEf")
{
for(int i=0;i<stock.size();++i){
if(stock.at(i).isDigit() || stock.at(i).isLetter()){
ligne6.append(stock.at(i));
}
}
}
}
fichier.close();
}
for (int i=0; i<NbrBrickVisible; i++) {
Floor *k= new Floor(i*brickSize, Hauteur-brickSize, QString(":images/floor_bottom.jpg"));
floors->append(k);
Floor *k2= new Floor(i*brickSize, Hauteur-2*brickSize, QString(":images/floor_grass.png"));
floors->append(k2);
}
for (int i=0; i<NbrBrickVisible; i++) {
Brick *b=new Brick(i*brickSize,Hauteur+brickSize);
compteur->append(b);
}
for (int i=0; i<2; i++) {
Background* b = new Background(i*Model::Longueur, 0);
background->append(b);
}
}
//--------------------------------------------------------------------------------------------------------//
Model::~Model()
{
floors->clear();
delete floors;
safes->clear();
delete safes;
compteur->clear();
delete compteur;
background->clear();
delete background;
mushroom->clear();
delete mushroom;
darkEater->clear();
delete darkEater;
delete flames;
golds->clear();
delete golds;
delete mario;
delete splashScreen;
mysticTrees->clear();
delete mysticTrees;
}
//-----------------------------------------------------------------------------------------------------------------//
void Model::createBrick(QList<QChar> l ,int num ,int x){
QChar myChar = l.at(mapPosition);
if(myChar == '0')
return;
else if(myChar == '1'){
Floor *k= new Floor(x+brickSize,Hauteur-num*brickSize, QString(":images/floor_bottom.jpg"));
floors->append(k);
return;
}
else if(myChar == '2'){
Safe* t= new Safe(x+brickSize, Hauteur-num*brickSize);
safes->append(t);
return;
}
else if(myChar == '3'){
Gold* g= new Gold(x+brickSize, Hauteur-num*brickSize);
golds->append(g);
return;
}
else if(myChar == '4'){
DarkEater* d= new DarkEater(x+brickSize, Hauteur-num*brickSize);
d->setMoveX(false);
darkEater->append(d);
return;
}
else if(myChar == '5'){
Flame* f = new Flame(x+brickSize, Hauteur-num*brickSize);
f->setMoveX(false);
flames->append(f);
return;
}
else if(myChar == '6'){
Safe* t= new Safe(x+brickSize, Hauteur-num*brickSize);
t->setCapacity(2);
safes->append(t);
return;
}
else if(myChar == '7'){
Floor *k= new Floor(x+brickSize,Hauteur-num*brickSize , QString(":images/floor_grass.png"));
floors->append(k);
return;
}
else if(myChar == '8'){
Floor *k= new Floor(x+brickSize,Hauteur-num*brickSize , QString(":images/floor_right.png"));
floors->append(k);
return;
}
else if(myChar == '9'){
Floor *k= new Floor(x+brickSize,Hauteur-num*brickSize , QString(":images/floor_left.png"));
floors->append(k);
return;
}
else if(myChar == 'a'){
MysticTree *k= new MysticTree(x+brickSize,Hauteur-num*brickSize);
mysticTrees->append(k);
qDebug() << "Je Debug";
return;
}
}
//----------------------------------------------------------------------------------------------------------------//
void Model::brickOrganisation()
{
for(int i = 0; i<background->size(); i++){
if(background->at(i)->getRect().x() < - background->at(i)->getRect().width() + 2){
background->removeAt(i);
Background* b = new Background(1000,0);
background->append(b);
}
}
if(compteur->last()->getRect().x()<((NbrBrickVisible)*brickSize)){
Brick *b=new Brick(compteur->last()->getRect().x()+brickSize,Hauteur+brickSize);
createBrick(ligne1,1,compteur->last()->getRect().x());
createBrick(ligne2,2,compteur->last()->getRect().x());
createBrick(ligne3,3,compteur->last()->getRect().x());
createBrick(ligne4,4,compteur->last()->getRect().x());
createBrick(ligne5,5,compteur->last()->getRect().x());
createBrick(ligne6,6,compteur->last()->getRect().x());
compteur->append(b);
mapPosition++;
}
if (compteur->first()->getRect().x()<=-brickSize){
compteur->removeAt(compteur->indexOf(compteur->first()));
}
for(int i = 0; i<floors->size(); i++){
if (floors->at(i)->getRect().x()<=-brickSize || floors->at(i)->isDestroyed()){
floors->removeAt(i);
}
}
for(int i = 0; i<safes->size(); i++){
if (safes->at(i)->getRect().x()<=-brickSize || safes->at(i)->isDestroyed()){
safes->removeAt(i);
}
}
for(int i = 0; i<golds->size(); i++){
if (golds->at(i)->getRect().x()<=-brickSize || golds->at(i)->isDestroyed()){
golds->removeAt(i);
}
}
for(int i = 0; i<mushroom->size(); i++){
if (mushroom->at(i)->getRect().x()<=-brickSize || mushroom->at(i)->isDestroyed()){
mushroom->removeAt(i);
}
}
for(int i = 0; i<flames->size(); i++){
if (flames->at(i)->getRect().x()<=-brickSize || flames->at(i)->isDestroyed()){
flames->removeAt(i);
}
}
for(int i = 0; i<darkEater->size(); i++){
if (darkEater->at(i)->getRect().x()<=-brickSize ){
darkEater->removeAt(i);
}
}
}
void Model::createMushroom(int x, int y, bool up){
Mushroom *m = new Mushroom(x+9, y+10, up);
m->setYR(0);
m->setXR(0);
m->setStartY(m->getRect().y() + 50);
mushroom->append(m);
}
void Model::createGameOver(int x, int y){
this->splashScreen = new SplashScreen(x, y, ":images/gameover.png");
}
void Model::createCompleted(int x, int y){
this->splashScreen = new SplashScreen(x, y, ":images/level_complete.png");
}
void Model::createPeach(int x, int y){
this->peach = new Peach(x, y);
this->peach->setIsMovingL(true);
}
void Model::createEncart(int x, int y, QString image){
this->encart = new Encart(x, y, image);
}