Bonjour,
J'ai un petit problème, je voudrait faire ne sorte que mon programme loop toujour. j'utilise déjà un while pour le loop mais on dirait que OpenGL que j'utilise brise la loop a chaque fois que le niveau est terminer. Alors je doit repartir le jeu. J'ai esseyer les while,dowhile,la chose qui dit avec un while (O/N) si "o" le programme continu. Mais rien n'est arriver a terme. Je pense que le problème se situe en bas de mon code a la toute fin lorsqu'il dit(nom de la fonction) : TestVictoire. celui ci ferme le programme. Alors j'ai esseyer d'enlever le exit(0); mais sans success le programme bogue et se ferme pareil. Alors tous mes effort sans success.

BUT:Jaimerait que le programme montre de nouveau le menu apres que le niveau soit terminer en ayant perdu ou gagnier la partie!

Deuxiemement ce n'est pas mon code en entier. Si vous vouler toutes les parties,par exemple les entêtes et les parties des joueurs et des ennemis je vous les fournirai.Cela n'est que le Main de la fonction. Merci de m'aider a résoudre mon probleme!!!

PS; J'utilise windows visual C++ 2010
PS2: j'ai fait mes propres recherches et je ne suis arriver a rien.


Merci de votre temp!!









Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
#include <iostream>
#include <windows.h>
#include <string>
 
using namespace std;
#include "GL/glut.h"
#include <fstream>
#include "Joueur.h"
#include "EnnemiVert.h"
#include "EnnemiRouge.h"
#include "EnnemiBase.h"
#include <time.h>
 
 
int NbColonnes, NbLignes; 
int SortieC = 0, SortieL = 0; 
char** Matrice; 
Joueur monJoueur;  
EnnemiBase* premierEnnemi = NULL; 
 
const int TIMER_MILLIS=500; 
 
 
 
enum TYPE_ENNEMI
{
    ENNEMI_VERT,    
    ENNEMI_ROUGE    
};
 
void LabyAffichage();
void LabyRedim(int x, int y);
void LabyClavierSpecial(int key, int x, int y);
void LabyTimer(int value);
 
void OuvrirNiveau(char* nom_fichier);
void LibererMemoire();
void DessinerNiveau();
void TestVictoire();
void AjouterEnnemi(TYPE_ENNEMI type,int Colonne,int Ligne);
 
 
void main(void)
{
//******************************************************************************************
//******************************************************************************************
 
 
 
	bool boucler = true;
	while(boucler)
	{
		cout<<"Login information"<<endl;
		string pass;
		string user;
		cout <<"Nom d'utilisateur: ";
		cin  >>user;
		cout <<"Mot de passe: ";
		cin  >>pass;
 
 
		while (user!="koliter"||pass!="omg")
		{
			cout<< "\nMauvais utilisateur et/ou mot de passe."<<endl;
			Sleep(500);
			cout<<"Veuillez reesseyer"<<endl;
			cout <<"Nom d'utilisateur: ";
			cin  >>user;
			cout <<"Mot de passe: ";
			cin  >>pass;
		}
 
	system("cls");
 
	cout<< "Processing...";
	Sleep(2000);
	cout<< "\nOuverture de la session en cour...";
	Sleep(3000);
 
 
	system("cls");
		cout << "Editeur : Jean-Philippe Vallee\n\n "<< endl;
		cout <<	"\n                            LE CHERCHEUR DE TRESOR!		"  <<endl;
		cout << "\n                        ************ MENU ************	"<<endl;
		cout << "                        **  1 - Niveau 1 (Facile)   **		" <<endl;
		cout << "                        **  2 - Niveau 2 (Moyen)    **		" <<endl;
		cout << "                        **  3 - Niveau 3 (Moyen)    **		" <<endl;
		cout << "                        **  4 - Niveau 4 (Difficile)**		" <<endl;
		cout << "                        **  5 - Niveau 5 (Expert)   **		" <<endl;
		cout << "                        **  6 - Sortir du programme **		" <<endl;
		cout << "                        ******************************	\n\n" <<endl;
 
		int choix;
		cout<<"                        Veuiller entrer votre choix : ";
		cin >> choix;
		while(choix < 1 || choix > 6)
		{
			cout << "Valeur incorect!"<< endl;
			cout << "Veuillez le saisir de nouveau : ";
			cin >> choix;
		}
 
 
		switch(choix)
		{
		case 1:
			{
				system("cls");
 
	srand((int)time(NULL));
 
    NbColonnes=NbLignes=0;	
	Matrice = NULL;			
 
 
    glutInitWindowPosition(10, 10);
 
    glutInitWindowSize(500, 500);
 
	glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
 
    glutCreateWindow("Labyrinthe");
 
 
    glutDisplayFunc(LabyAffichage);
 
    glutReshapeFunc(LabyRedim);
 
	glutSpecialFunc(LabyClavierSpecial);
 
	glutTimerFunc(TIMER_MILLIS, LabyTimer, 0);
 
 
	OuvrirNiveau("niveau1.txt");
 
 
    glutMainLoop();
 
					system("pause");
					break;
 
			}
 
		case 2:
			{
				system("cls");
 
	srand((int)time(NULL));
 
    NbColonnes=NbLignes=0;
	Matrice = NULL;			
 
 
    glutInitWindowPosition(10, 10);
 
    glutInitWindowSize(500, 500);
 
	glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE); 
 
    glutCreateWindow("Labyrinthe");
 
 
    glutDisplayFunc(LabyAffichage);
 
    glutReshapeFunc(LabyRedim);
 
	glutSpecialFunc(LabyClavierSpecial);
 
	glutTimerFunc(TIMER_MILLIS, LabyTimer, 0);
 
 
	OuvrirNiveau("niveau2.txt");
 
    glutMainLoop();	
				break;
			}
 
		case 3 : {
				 				system("cls");
 
	srand((int)time(NULL));
 
    NbColonnes=NbLignes=0;
	Matrice = NULL;			
 
 
    glutInitWindowPosition(10, 10);
 
    glutInitWindowSize(500, 500);
 
	glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE); 
 
    glutCreateWindow("Labyrinthe");
 
 
    glutDisplayFunc(LabyAffichage);
 
    glutReshapeFunc(LabyRedim);
 
	glutSpecialFunc(LabyClavierSpecial);
 
	glutTimerFunc(TIMER_MILLIS, LabyTimer, 0);
 
 
	OuvrirNiveau("niveau3.txt");
 
    glutMainLoop();	
				break;
 
				 }
		case 4:
			{
				 				system("cls");
 
	srand((int)time(NULL));
 
    NbColonnes=NbLignes=0;
	Matrice = NULL;			
 
 
    glutInitWindowPosition(10, 10);
 
    glutInitWindowSize(500, 500);
 
	glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE); 
 
    glutCreateWindow("Labyrinthe");
 
 
    glutDisplayFunc(LabyAffichage);
 
    glutReshapeFunc(LabyRedim);
 
	glutSpecialFunc(LabyClavierSpecial);
 
	glutTimerFunc(TIMER_MILLIS, LabyTimer, 0);
 
 
	OuvrirNiveau("niveau4.txt");
 
    glutMainLoop();	
				break;
 
				 }
		case 5:
			{
				 				system("cls");
 
	srand((int)time(NULL));
 
    NbColonnes=NbLignes=0;
	Matrice = NULL;			
 
 
    glutInitWindowPosition(10, 10);
 
    glutInitWindowSize(500, 500);
 
	glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE); 
 
    glutCreateWindow("Labyrinthe");
 
 
    glutDisplayFunc(LabyAffichage);
 
    glutReshapeFunc(LabyRedim);
 
	glutSpecialFunc(LabyClavierSpecial);
 
	glutTimerFunc(TIMER_MILLIS, LabyTimer, 0);
 
 
	OuvrirNiveau("niveau5.txt");
 
    glutMainLoop();	
				break;
 
				 }
 
		case 6:{cout<<"\nFermeture\n\n";
				boucler = false;
				break;}
		}
 
 
 
	}
 
}
//******************************************************************************************
//******************************************************************************************
 
void LabyAffichage()
{
 
    glClearColor(1.0, 1.0, 1.0, 1.0);
 
    glClear(GL_COLOR_BUFFER_BIT);
 
    glMatrixMode(GL_MODELVIEW);
 
 
    DessinerNiveau();
 
 
	monJoueur.Dessiner();
 
 
	EnnemiBase* Pointeur = premierEnnemi;
	while(Pointeur != NULL) 
	{
 
		Pointeur->Dessiner();
 
		Pointeur = Pointeur->GetSuivant();
	}
 
 
    glutSwapBuffers();
}
 
 
 
void DessinerNiveau()
{
 
    glColor3d(0.5, 0.5, 0.5);  
 
    glBegin(GL_QUADS);
 
    for(int i=0; i<NbColonnes; i++)
        for(int j=0; j<NbLignes; j++)
 
            if(Matrice[i][j] == '0')
            {
 
                glVertex2d(i,   j);
                glVertex2d(i,   j+1);
                glVertex2d(i+1, j+1);
                glVertex2d(i+1, j);
            }
    glEnd();   
 
 
    glPushMatrix();
 
    glTranslated(SortieC+0.5, SortieL+0.5, 0.0);
        glColor3d(0.3, 1.0, 0.3);  
 
        for(double taille=0.1; taille<1.0; taille+=0.2)
 
            glutWireCube(taille);
    glPopMatrix();
}
 
 
 
void LabyRedim(int x, int y)
{
    glViewport(0, 0, x, y);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluOrtho2D(0.0, (double)NbColonnes,
               (double)NbLignes, 0.0);
}
 
 
 
void LabyClavierSpecial(int key, int x, int y)
{
	switch(key) {
	case GLUT_KEY_UP: {
 
		monJoueur.BougerEnHaut();
		break;}
	case GLUT_KEY_DOWN: {
 
		monJoueur.BougerEnBas();
		break;}
	case GLUT_KEY_LEFT: {
 
		monJoueur.BougerAGauche();
		break;}
	case GLUT_KEY_RIGHT: {
 
		monJoueur.BougerADroite();
		break;}
	}
 
 
TestVictoire();
 
	EnnemiBase* Pointeur = premierEnnemi;
	while(Pointeur != NULL)  
	{
 
		Pointeur->TestCollision();
 
		Pointeur = Pointeur->GetSuivant();
	}
 
 
	glutPostRedisplay();
 
 
 
 
}
 
 
void LabyTimer(int value)
{
 
    EnnemiBase* Pointeur = premierEnnemi;
    while(Pointeur != NULL)  
    {
 
        Pointeur->DeplacementAuto();
 
        Pointeur->TestCollision();
 
        Pointeur = Pointeur->GetSuivant();
    }
 
 
    glutPostRedisplay();
 
 
    glutTimerFunc(TIMER_MILLIS, LabyTimer, 0);
}
 
 
 
 
 
 
 
void OuvrirNiveau(char* nom_fichier)
{
    ifstream fichier;       
    fichier.open(nom_fichier); 
 
    if(fichier == 0) {  
        cout << "Erreur lors de l'ouverture du fichier !"
             << endl;
        system("pause");
        exit(1);
    }
 
 
    fichier >> NbColonnes;
    fichier >> NbLignes;
 
 
    Matrice = new char*[NbColonnes];
    for(int i=0; i<NbColonnes; i++)
        Matrice[i] = new char[NbLignes];
 
 
    for(int i=0; i<NbColonnes; i++)
        for(int j=0; j<NbLignes; j++)
            Matrice[i][j] = '0';
 
 
    for(int j=0; j<NbLignes; j++)
		for(int i=0; i<NbColonnes; i++)
		{
			fichier >> Matrice[i][j]; 
 
			switch(Matrice[i][j])    
			{
 
			case 'j':
			case 'J': {
				monJoueur.SetPosC(i);
				monJoueur.SetPosL(j);
				break;
				}
 
 
			case 's':
			case 'S': {
				SortieC = i;
				SortieL = j;
				break;
				}
 
 
			case 'v':
			case 'V': {
				AjouterEnnemi(ENNEMI_VERT, i, j);
				break;
				}
 
 
			case 'r':
			case 'R': {
				AjouterEnnemi(ENNEMI_ROUGE, i, j);
				break;
				}
			}
		}
 
    fichier.close();  
}
 
 
void LibererMemoire()
{
    if(Matrice != NULL)
    {
        for(int i=0; i<NbColonnes; i++)
 
            delete [] Matrice[i];
 
        delete [] Matrice;
    }
 
 
    EnnemiBase* Pointeur = NULL;
    while(premierEnnemi != NULL) 
    {
 
        Pointeur = premierEnnemi;
 
        premierEnnemi = premierEnnemi->GetSuivant();
 
        delete Pointeur;
    }
}
 
 
 
void TestVictoire()
{
 
    if(monJoueur.GetPosC()==SortieC &&
       monJoueur.GetPosL()==SortieL)
    {
       	LabyAffichage();
		LibererMemoire();
			cout << "\n\n\n\n\n\n\nVOUS AVEZ GAGNIER! :) :) :)\n\n\n\n\n\n" << endl;
        	system("pause");
			exit(0);
 
 
 
 
 
 
 
	}
}
 
 
void AjouterEnnemi(TYPE_ENNEMI type, int Colonne, int Ligne)
{
    EnnemiBase* Pointeur = NULL;
    switch(type) {
    case ENNEMI_VERT:  Pointeur = new EnnemiVert();  break;
    case ENNEMI_ROUGE: Pointeur = new EnnemiRouge(); break;
    default: exit(0); 
    }
 
    Pointeur->SetPosC(Colonne); 
    Pointeur->SetPosL(Ligne);   
 
 
    Pointeur->SetSuivant(premierEnnemi);
 
    premierEnnemi = Pointeur;
}