-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplateau.cpp
executable file
·113 lines (96 loc) · 2.49 KB
/
plateau.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
#include "plateau.h"
Plateau::Plateau()
{
}
Plateau::~Plateau()
{
std::vector < Cube* >::iterator i_plat;
for (i_plat = plateau.begin();i_plat != plateau.end();i_plat++)
{
delete (*i_plat);
}
}
void Plateau::affiche(SDL_Surface * screen)
{
std::vector < Cube* >::iterator i_plat;
for (i_plat = plateau.begin();i_plat != plateau.end();i_plat++)
{
(*i_plat)->affiche(screen);
}
}
void Plateau::addCube(const Cube* new_cube)
{
plateau.push_back(new Cube(*new_cube));
}
bool Plateau::collision(Cube* cube_col)
{
std::vector < Cube* >::iterator i_plat;
for (i_plat = plateau.begin();i_plat != plateau.end();i_plat++)
{
if (cube_col->getCoord().y == (*i_plat)->getCoord().y && cube_col->getCoord().x == (*i_plat)->getCoord().x)
return true;
}
return false;
}
int Plateau::ligneComplete()
{
std::vector < Cube* >::iterator i_plat;
int check = 0;
int nb_ligne = 0;
for (int i=0;i<NB_BLOCS_HAUTEUR;i++)
{
check = 0;
for (i_plat = plateau.begin();i_plat != plateau.end();i_plat++)
{
if (((*i_plat)->getCoord().y/TAILLE_BLOC) == i)
check++;
}
if (check == NB_BLOCS_LARGEUR)
{
videLigne(i);
nb_ligne++;
}
}
return nb_ligne;
}
void Plateau::videLigne(int ligneAEffacer)
{
std::vector < Cube* >::iterator i_plat;
while (itr.hasNext()) {
Cube c = itr.next();
}
for (i_plat = plateau.begin();i_plat != plateau.end();)
{
if (((*i_plat)->getCoord().y/TAILLE_BLOC) == ligneAEffacer)
{
delete *i_plat;
plateau.erase(i_plat);
}
else
i_plat++;
}
replaceLigne(ligneAEffacer);
}
void Plateau::replaceLigne(int ligneEffacer)
{
std::vector < Cube* >::iterator i_plat;
for (i_plat = plateau.begin();i_plat != plateau.end();i_plat++)
{
if (((*i_plat)->getCoord().y/TAILLE_BLOC) < ligneEffacer)
{
(*i_plat)->setCoord(((*i_plat)->getCoord().y/TAILLE_BLOC)+1,(*i_plat)->getCoord().x/TAILLE_BLOC);
}
}
}
bool Plateau::game_over()
{
std::vector < Cube* >::iterator i_plat;
for (i_plat = plateau.begin();i_plat != plateau.end();i_plat++)
{
if (((*i_plat)->getCoord().y/TAILLE_BLOC) == 0)
{
return true;
}
}
return false;
}