-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.cpp
130 lines (110 loc) · 2.61 KB
/
main.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
#include "mainwindow.h"
#include <QApplication>
#include <iostream>
#include <string>
#include <random>
#include <ctime>
#include "exception.h"
#include "personnage.h"
#include "ennemi.h"
#include "clyde.h"
#include <random>
#include <ctime>
#include <iostream>
bool detecter_collision(int ennemis_x[], int ennemis_y[], int nb_ennemis, int x, int y );
bool deplacer_personnage(int* x, int* y, std::string cmd);
int main(int argc, char** argv)
{
srand(time(NULL));
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
/*
Personnage pacman(0, 0, "UP");
Clyde Clydi1(5, 5);
Clyde Clydi2(10, 10);
Clydi1.addObserver(pacman);
Clydi2.addObserver(pacman);
pacman.addObserver(Clydi1);
pacman.addObserver(Clydi2);
while(true){
//std::string saisie;
//std::getline(std::cin, saisie);
//pacman.set(saisie);
try{
pacman.new_pos();
}
catch(ExceptionBounds){
std::cout << "Hors limite";
}
catch(ExceptionCommand){
std::cout << "Commande non reconnue";
}
}
int x=5, y=4;
int nb_éléments=4;
int enn_x[4] = {1, 2, 3, 4}, enn_y[4]= {1, 2, 3, 4};
try
{
if (detecter_collision(enn_x, enn_y, nb_éléments, x, y) == true)
{
std::cout << "Collision" << std::endl;
}
}
catch(ExceptionSizeTab){
std::cout << "Nombre d'ennemis incorrect" << std::endl;
}
*/
return 0;
}
bool detecter_collision(int ennemis_x[], int ennemis_y[], int nb_ennemis, int x, int y)
{
bool collision = false;
if(nb_ennemis <= 0)
throw ExceptionSizeTab();
for(int i=0;i<nb_ennemis;i++)
{
if(ennemis_x[i] == x && ennemis_y[i] == y)
collision = true;
}
if(collision == true){
return true;
}else{
return false;
}
}
bool deplacer_personnage(int& x, int& y, std::string cmd)
{
if (cmd=="UP"){
if((y-1)> ymin){
throw ExceptionBounds();
}else{
y-=1;
return true;
}
}else if (cmd=="DOWN"){
if((y+1)> ymax){
throw ExceptionBounds();
}else{
y+=1;
return true;
}
}else if (cmd=="RIGHT"){
if((x+1)> xmax){
throw ExceptionBounds();
}else{
x+=1;
return true;
}
}else if (cmd=="LEFT"){
if((x-1)> xmin){
throw ExceptionBounds();
}else{
x-=1;
return true;
}
}else{
throw ExceptionCommand();
}
}