-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEcranConfiguration.cpp
More file actions
167 lines (132 loc) · 3.78 KB
/
EcranConfiguration.cpp
File metadata and controls
167 lines (132 loc) · 3.78 KB
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
#include "EcranConfiguration.h"
#include "ManagerEcran.h"
#include <iostream>
using namespace std;
/**
* Constructeur
*/
EcranConfiguration::EcranConfiguration(ManagerEcran *man) :
jouer(Bouton("Images/jouerDepart.png", "Images/jouerClique.png")),
nb2(Bouton("Images/2Depart.png", "Images/2Clique.png")),
nb3(Bouton("Images/3Depart.png", "Images/3Clique.png")),
nb4(Bouton("Images/4Depart.png", "Images/4Clique.png")),
nb5(Bouton("Images/5Depart.png", "Images/5Clique.png")),
nb6(Bouton("Images/6Depart.png", "Images/6Clique.png")),
nb7(Bouton("Images/7Depart.png", "Images/7Clique.png")),
nb8(Bouton("Images/8Depart.png", "Images/8Clique.png")),
manager(man)
{
// On charge l'image dans la texture "image"
if(!image.loadFromFile("Images/configuration.png")){};
// On met la texture dans le sprite ecran
ecran.setTexture(image);
}
/**
* Fonction afficher
* @param window la fenetre
*/
void EcranConfiguration::afficher(sf::RenderWindow &fenetre)
{
// Affichage des elements
fenetre.draw(ecran);
sf::Sprite sp;
sp = jouer.getSprite();
sp.move(sf::Vector2f(595, 550));
fenetre.draw(sp);
sp = nb2.getSprite();
sp.move(sf::Vector2f(200, 360));
fenetre.draw(sp);
sp = nb3.getSprite();
sp.move(sf::Vector2f(340, 360));
fenetre.draw(sp);
sp = nb4.getSprite();
sp.move(sf::Vector2f(480, 360));
fenetre.draw(sp);
sp = nb5.getSprite();
sp.move(sf::Vector2f(620, 360));
fenetre.draw(sp);
sp = nb6.getSprite();
sp.move(sf::Vector2f(760, 360));
fenetre.draw(sp);
sp = nb7.getSprite();
sp.move(sf::Vector2f(900, 360));
fenetre.draw(sp);
sp = nb8.getSprite();
sp.move(sf::Vector2f(1040, 360));
fenetre.draw(sp);
}
/**
* Cette fonction permet le changement d'ecran en fonction des evenements
* @param event un evenement envoyé par les classes superieurs
*/
void EcranConfiguration::update(sf::Event event)
{
int x = event.mouseButton.x;
int y = event.mouseButton.y;
if(595<=x && x<=673 && 550<=y && y<=630)
{
if( selectionValide()==true )
{
jouer.clique();
manager->setEcranCourant(manager->getEcranJeu());
}
}
if(200<=x && x<=256 && 360<=y && y<=423)
{
changement(nb2,nb8,nb3,nb4,nb5,nb6,nb7,2);
}
if(340<=x && x<=403 && 360<=y && y<=423)
{
changement(nb3,nb2,nb8,nb4,nb5,nb6,nb7,3);
}
if(480<=x && x<=543 && 360<=y && y<=423)
{
changement(nb4,nb2,nb3,nb8,nb5,nb6,nb7,4);
}
if(620<=x && x<=683 && 360<=y && y<=423)
{
changement(nb5,nb2,nb3,nb4,nb8,nb6,nb7,5);
}
if(760<=x && x<=823 && 360<=y && y<=423)
{
changement(nb6,nb2,nb3,nb4,nb5,nb8,nb7,6);
}
if(900<=x && x<=963 && 360<=y && y<=423)
{
changement(nb7,nb2,nb3,nb4,nb5,nb6,nb8,7);
}
if(1040<=x && x<=1103 && 360<=y && y<=423)
{
changement(nb8,nb2,nb3,nb4,nb5,nb6,nb7,8);
}
}
/**
* Fonction changement
*/
void EcranConfiguration::changement(Bouton &b1,Bouton &b2,Bouton &b3,Bouton &b4, Bouton &b5, Bouton &b6, Bouton &b7, int nombre){
b1.clique();
b2.deselection();
b3.deselection();
b4.deselection();
b5.deselection();
b6.deselection();
b7.deselection();
manager->setNombreJoueur(nombre);
}
/**
* Fonction selectionValide
* Role : cette fonction renvoie vrai si un seul bouton selectionant le nombre de joueurs est clique
* @return si la selection est valide
*/
bool EcranConfiguration::selectionValide()
{
bool res;
if(nb2.getClique()==true || nb3.getClique()==true || nb4.getClique()==true ||
nb5.getClique()==true || nb6.getClique()==true || nb7.getClique()==true ||
nb8.getClique()==true ){
res = true;
}else{
res = false;
}
return res;
}