-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathactif.h
284 lines (237 loc) · 8.03 KB
/
actif.h
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
/******************************************************************************
En-tete du programme
=====================
fichier : actif.h
Auteur : Alexandre Beaulieu et Vincent Philippon
Date de creation : 27 avril 2010
Fichier d'entete des actions actives
*****************************************************************************/
//Directive au pre-processeur
#ifndef ACTIF_H_
#define ACTIF_H_
#include "passif.h"
#include "affichage.h"
using namespace std;
//Le joueur choisi la piece avec laquelle il veut jouer
void selectionPiece(SDL_Surface *ecran, plateau sTabPlateau[8][8], int &x,
int &y, int iTour, SOCKET sockEnvoi, SOCKET &sock,
SOCKET &cSock)
{
//Declaration des variables
SDL_Event event; //evenement capte par SDL_WaitEvent
bool bSelection = false; //Si le joueur a selectionne une piece
do
{
SDL_WaitEvent(&event);
switch (event.type)
{
case SDL_QUIT: //Sur le x de la fenetre, on arrete le programme
quitter(sTabPlateau, sock, cSock);
break;
case SDL_KEYDOWN:
if (event.key.keysym.sym == SDLK_ESCAPE)
quitter(sTabPlateau, sock, cSock);
break;
case SDL_MOUSEBUTTONUP: //Lorsque l'utilisateur clique
//Si c'est le bouton gauche
if (event.button.button == SDL_BUTTON_LEFT)
{
//Conversion coord �cran pour coord tableau si dans le damier
if (cliqueDansDamier(event.button.x, event.button.y))
{
x = event.button.x / 60 - 1;
y = event.button.y / 60 - 1;
//Si la pi�ce est � lui
if (sTabPlateau[y][x].pieceEchec->getEquipe() * iTour > 0)
{
bSelection = true;
afficherImage(ecran, "Selection.PNG", &sTabPlateau[y][x].posCase);
envoyerInt(sockEnvoi, x);
envoyerInt(sockEnvoi, y);
}
}
}
break;
}
}while (!bSelection);
}
//Le joueur s�lectionne la destination de sa pi�ce
void selectionDestination(SDL_Surface *ecran, plateau sTabPlateau[8][8],
int &iXPiece, int &iYPiece, int &iXDeplacement,
int &iYDeplacement, int iTour, bool &bAction,
SOCKET sockEnvoi, SOCKET &sock, SOCKET &cSock)
{
//D�claration des variables
SDL_Event event; //�v�nement capt� par SDL_WaitEvent
bool bContinuer = 1; //Continuer la boucle ou non
int iAction; //Si on fait l'action ou non
iAction = bAction = 0;
do
{
SDL_WaitEvent(&event);
switch (event.type)
{
case SDL_QUIT: //Sur le x de la fenetre, on arr�te le programme
quitter(sTabPlateau, sock, cSock);
break;
case SDL_KEYDOWN:
if (event.key.keysym.sym == SDLK_ESCAPE)
quitter(sTabPlateau, sock, cSock);
break;
case SDL_MOUSEBUTTONUP: //Lorsque l'utilisateur clique
//Si c'est le bouton gauche
if (event.button.button == SDL_BUTTON_LEFT)
{
//Conversion coord �cran pour coord tableau si dans le damier
if (cliqueDansDamier(event.button.x, event.button.y))
{
iXDeplacement = event.button.x / 60 - 1;
iYDeplacement = event.button.y / 60 - 1;
bAction = sTabPlateau[iYPiece][iXPiece].pieceEchec->destination(
sTabPlateau, iXPiece, iYPiece, iXDeplacement, iYDeplacement,
iTour);
iAction = bAction;
if (bAction)
{
envoyerInt(sockEnvoi, iAction);
envoyerInt(sockEnvoi, iXDeplacement);
envoyerInt(sockEnvoi, iYDeplacement);
}
}
bContinuer = false;
}
//Si c'est le bouton droit
else if (event.button.button == SDL_BUTTON_RIGHT)
bContinuer = false;
break;
}
}while (bContinuer);
if (!bAction)
envoyerInt(sockEnvoi, iAction);
}
void attenteClique(plateau sTabPlateau[8][8], SOCKET &sock, SOCKET &cSock)
{
//D�clarations des variables
int iContinuer = 1; //Attente
SDL_Event event; //�venement SDL
//Boucle d'attente
do
{
SDL_WaitEvent(&event);
switch (event.type)
{
case SDL_QUIT: //Sur le x de la fenetre, on arr�te le programme
quitter(sTabPlateau, sock, cSock);
break;
case SDL_KEYDOWN:
if (event.key.keysym.sym == SDLK_ESCAPE)
quitter(sTabPlateau, sock, cSock);
break;
case SDL_MOUSEBUTTONUP: //Lorsque l'utilisateur clique
iContinuer = 0;
}
}while (iContinuer);
}
//Choix de la piece pour la promotion
int choixPromotion(SDL_Surface *ecran, int iTour, int sockTransmition,
plateau sTabPlateau[8][8], int sock, int cSock)
{
//D�clarations des variables
int iChoix = 0; //Choix de piece
SDL_Event event; //Evenement capt�
SDL_Rect posTexte, //Position du texte d'indication
posTour, //Rectangle du tour
posCavalier, //Rectangle du cavalier
posFou, //Rectangle du fou
posReine; //Rectangle du reine
SDL_Color couleur =
{136, 0, 21}; //Couleur pour le texte en jeu
Uint32 couleurFond = 12632256; //Couleur de fond pour le texte
posTexte.x = 610;
posTexte.y = 350;
posReine.x = 610;
posReine.y = 400;
posReine.h = 60;
posReine.w = 60;
posTour.x = 670;
posTour.y = 400;
posTour.h = 60;
posTour.w = 60;
posFou.x = 610;
posFou.y = 460;
posFou.h = 60;
posFou.w = 60;
posCavalier.x = 670;
posCavalier.y = 460;
posCavalier.h = 60;
posCavalier.w = 60;
afficherTexte(ecran, "Cliquer pour choisir :", "papyrus.ttf", 20, couleur,
posTexte, couleurFond);
//Si tour au blanc
if (iTour > 0)
{
afficherImage(ecran, "reine_blanc.png", &posReine);
afficherImage(ecran, "tour_blanc.png", &posTour);
afficherImage(ecran, "fou_blanc.png", &posFou);
afficherImage(ecran, "cavalier_blanc.png", &posCavalier);
}
//Si tour au noir
else
{
afficherImage(ecran, "reine_noir.png", &posReine);
afficherImage(ecran, "tour_noir.png", &posTour);
afficherImage(ecran, "fou_noir.png", &posFou);
afficherImage(ecran, "cavalier_noir.png", &posCavalier);
}
do
{
SDL_WaitEvent(&event);
switch (event.type)
{
case SDL_QUIT: //Sur le x de la fenetre, on arr�te le programme
quitter(sTabPlateau, sock, cSock);
break;
case SDL_KEYDOWN:
if (event.key.keysym.sym == SDLK_ESCAPE)
quitter(sTabPlateau, sock, cSock);
break;
case SDL_MOUSEBUTTONUP: //Lorsque l'utilisateur clique
//Si c'est le bouton gauche
if (event.button.button == SDL_BUTTON_LEFT)
{
//Si la reine
if (event.button.x > posReine.x && event.button.x
< posReine.x + posReine.w
&& event.button.y > posReine.y
&& event.button.y < posReine.y + posReine.h)
iChoix = 1;
//Si c'est la tour
else if (event.button.x > posTour.x
&& event.button.x < posTour.x + posTour.w
&& event.button.y > posTour.y
&& event.button.y < posTour.y + posTour.h)
iChoix = 2;
//Si c'est le fou
else if (event.button.x > posFou.x
&& event.button.x < posFou.x + posFou.w
&& event.button.y > posFou.y
&& event.button.y < posFou.y + posFou.h)
iChoix = 3;
//Si c'est la cavalier
else if (event.button.x > posCavalier.x
&& event.button.x < posCavalier.x + posCavalier.w
&& event.button.y > posCavalier.y
&& event.button.y < posCavalier.y + posCavalier.h)
iChoix = 4;
}
}
}while (iChoix == 0); //Tant qu'il n'y a pas de choix
afficherTexte(ecran, "", "papyrus.ttf", 20, couleur, posTexte, couleurFond);
SDL_FillRect(ecran, &posReine, couleurFond);
SDL_FillRect(ecran, &posTour, couleurFond);
SDL_FillRect(ecran, &posFou, couleurFond);
SDL_FillRect(ecran, &posCavalier, couleurFond);
SDL_Flip(ecran);
return iChoix;
}
#endif