-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
410 lines (371 loc) · 18.8 KB
/
main.cpp
File metadata and controls
410 lines (371 loc) · 18.8 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
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
#include <SDL.h>
#include <SDL_image.h>
int main()
{
SDL_Event e ;
int x , y ;
int s2 , s4 = 0 , h = 0 , s = 0;
int a[4][4] ;
a[0][0] = 1;a[0][1] = 2;a[0][2] = 6;a[0][3] = 8;
a[1][0] = 4;a[1][1] = 3;a[1][2] = 7;a[1][3] = 5;
a[2][0] = 1;a[2][1] = 5;a[2][2] = 8;a[2][3] = 4;
a[3][0] = 6;a[3][1] = 2;a[3][2] = 3;a[3][3] = 7;
int b1,b2,b3,b4;
SDL_Init (SDL_INIT_VIDEO) ;
bool t = true ;
SDL_Window * w = SDL_CreateWindow("Memory Game" , 0 , 0 , 800 , 600 , 0) ;
SDL_Renderer * r = SDL_CreateRenderer(w , -1 , 0) ;
SDL_Surface * per[16] = {IMG_Load ("image/0.jfif"),IMG_Load ("image/1.png") , IMG_Load ("image/2.png"), IMG_Load ("image/3.jfif"), IMG_Load ("image/4.png"), IMG_Load ("image/5.jfif"), IMG_Load ("image/6.jfif"), IMG_Load ("image/7.png"), IMG_Load ("image/8.jfif"), IMG_Load ("image/9.png"), IMG_Load ("image/10.png"), IMG_Load ("image/11.jpg"), IMG_Load ("image/12.png"), IMG_Load ("image/13.png"), IMG_Load ("image/14.png"), IMG_Load ("image/15.jfif")} ;
SDL_Rect i_peraa = {0 , 0 , 800 , 600} ;
SDL_Texture * per_saa = SDL_CreateTextureFromSurface (r , per[10]) ;
SDL_RenderCopy(r , per_saa , NULL , &i_peraa) ;
SDL_RenderPresent (r) ;
SDL_Delay(500);
SDL_Rect i_perab = {0 , 0 , 800 , 600} ;
SDL_Texture * per_sab = SDL_CreateTextureFromSurface (r , per[11]) ;
SDL_RenderCopy(r , per_sab , NULL , &i_perab) ;
SDL_RenderPresent (r) ;
SDL_Delay(500);
SDL_Rect i_perac = {0 , 0 , 800 , 600} ;
SDL_Texture * per_sac = SDL_CreateTextureFromSurface (r , per[12]) ;
SDL_RenderCopy(r , per_sac , NULL , &i_perac) ;
SDL_RenderPresent (r) ;
SDL_Delay(500);
SDL_Rect i_perad = {0 , 0 , 800 , 600} ;
SDL_Texture * per_sad = SDL_CreateTextureFromSurface (r , per[13]) ;
SDL_RenderCopy(r , per_sad , NULL , &i_perad) ;
SDL_RenderPresent (r) ;
SDL_Delay(500);
SDL_Rect i_perae = {0 , 0 , 800 , 600} ;
SDL_Texture * per_sae = SDL_CreateTextureFromSurface (r , per[14]) ;
SDL_RenderCopy(r , per_sae , NULL , &i_perae) ;
SDL_RenderPresent (r) ;
SDL_Delay(500);
//==============================================
SDL_Rect i_pera = {0 , 0 , 100 , 100} ;
SDL_Texture * per_sa = SDL_CreateTextureFromSurface (r , per[a[0][0]]) ;
SDL_RenderCopy(r , per_sa , NULL , &i_pera) ;
SDL_Rect i_per1a = {0 , 150 , 100 , 100} ;
SDL_Texture * per_s1a = SDL_CreateTextureFromSurface (r , per[a[0][1]]) ;
SDL_RenderCopy(r , per_s1a , NULL , &i_per1a) ;
SDL_Rect i_per2a = {0 , 300 , 100 , 100} ;
SDL_Texture * per_s2a = SDL_CreateTextureFromSurface (r , per[a[0][2]]) ;
SDL_RenderCopy(r , per_s2a , NULL , &i_per2a) ;
SDL_Rect i_per3a = {0 , 450 , 100 , 100} ;
SDL_Texture * per_s3a = SDL_CreateTextureFromSurface (r , per[a[0][3]]) ;
SDL_RenderCopy(r , per_s3a , NULL , &i_per3a) ;
SDL_Rect i_per4a = {150 , 0 , 100 , 100} ;
SDL_Texture * per_s4a = SDL_CreateTextureFromSurface (r , per[a[1][0]]) ;
SDL_RenderCopy(r , per_s4a , NULL , &i_per4a) ;
SDL_Rect i_per5a = {150 , 150 , 100 , 100} ;
SDL_Texture * per_s5a = SDL_CreateTextureFromSurface (r , per[a[1][1]]) ;
SDL_RenderCopy(r , per_s5a , NULL , &i_per5a) ;
SDL_Rect i_per6a = {150 , 300 , 100 , 100} ;
SDL_Texture * per_s6a = SDL_CreateTextureFromSurface (r , per[a[1][2]]) ;
SDL_RenderCopy(r , per_s6a , NULL , &i_per6a) ;
SDL_Rect i_per7a = {150 , 450 , 100 , 100} ;
SDL_Texture * per_s7a = SDL_CreateTextureFromSurface (r , per[a[1][3]]) ;
SDL_RenderCopy(r , per_s7a , NULL , &i_per7a) ;
SDL_Rect i_per8a = {300 , 0 , 100 , 100} ;
SDL_Texture * per_s8a = SDL_CreateTextureFromSurface (r , per[a[2][0]]) ;
SDL_RenderCopy(r , per_s8a , NULL , &i_per8a) ;
SDL_Rect i_per9a = {300 , 150 , 100 , 100} ;
SDL_Texture * per_s9a = SDL_CreateTextureFromSurface (r , per[a[2][1]]) ;
SDL_RenderCopy(r , per_s9a , NULL , &i_per9a) ;
SDL_Rect i_per10a = {300 , 300 , 100 , 100} ;
SDL_Texture * per_s10a = SDL_CreateTextureFromSurface (r , per[a[2][2]]) ;
SDL_RenderCopy(r , per_s10a , NULL , &i_per10a) ;
SDL_Rect i_per11a = {300 , 450 , 100 , 100} ;
SDL_Texture * per_s11a = SDL_CreateTextureFromSurface (r , per[a[2][3]]) ;
SDL_RenderCopy(r , per_s11a , NULL , &i_per11a) ;
SDL_Rect i_per12a = {450 , 0 , 100 , 100} ;
SDL_Texture * per_s12a = SDL_CreateTextureFromSurface (r , per[a[3][0]]) ;
SDL_RenderCopy(r , per_s12a , NULL , &i_per12a) ;
SDL_Rect i_per13a = {450 , 150 , 100 , 100} ;
SDL_Texture * per_s13a = SDL_CreateTextureFromSurface (r , per[a[3][1]]) ;
SDL_RenderCopy(r , per_s13a , NULL , &i_per13a) ;
SDL_Rect i_per14a = {450 , 300 , 100 , 100} ;
SDL_Texture * per_s14a = SDL_CreateTextureFromSurface (r , per[a[3][2]]) ;
SDL_RenderCopy(r , per_s14a , NULL , &i_per14a) ;
SDL_Rect i_per15a = {450 , 450 , 100 , 100} ;
SDL_Texture * per_s15a = SDL_CreateTextureFromSurface (r , per[a[3][3]]) ;
SDL_RenderCopy(r , per_s15a , NULL , &i_per15a) ;
SDL_RenderPresent (r) ;
SDL_Delay(3500);
//=========================================================
SDL_Rect i_per = {0 , 0 , 100 , 100} ;
SDL_Texture * per_s = SDL_CreateTextureFromSurface (r , per[0]) ;
SDL_RenderCopy(r , per_s , NULL , &i_per) ;
SDL_Rect i_per1 = {0 , 150 , 100 , 100} ;
SDL_Texture * per_s1 = SDL_CreateTextureFromSurface (r , per[0]) ;
SDL_RenderCopy(r , per_s1 , NULL , &i_per1) ;
SDL_Rect i_per2 = {0 , 300 , 100 , 100} ;
SDL_Texture * per_s2 = SDL_CreateTextureFromSurface (r , per[0]) ;
SDL_RenderCopy(r , per_s2 , NULL , &i_per2) ;
SDL_Rect i_per3 = {0 , 450 , 100 , 100} ;
SDL_Texture * per_s3 = SDL_CreateTextureFromSurface (r , per[0]) ;
SDL_RenderCopy(r , per_s3 , NULL , &i_per3) ;
SDL_Rect i_per4 = {150 , 0 , 100 , 100} ;
SDL_Texture * per_s4 = SDL_CreateTextureFromSurface (r , per[0]) ;
SDL_RenderCopy(r , per_s4 , NULL , &i_per4) ;
SDL_Rect i_per5 = {150 , 150 , 100 , 100} ;
SDL_Texture * per_s5 = SDL_CreateTextureFromSurface (r , per[0]) ;
SDL_RenderCopy(r , per_s5 , NULL , &i_per5) ;
SDL_Rect i_per6 = {150 , 300 , 100 , 100} ;
SDL_Texture * per_s6 = SDL_CreateTextureFromSurface (r , per[0]) ;
SDL_RenderCopy(r , per_s6 , NULL , &i_per6) ;
SDL_Rect i_per7 = {150 , 450 , 100 , 100} ;
SDL_Texture * per_s7 = SDL_CreateTextureFromSurface (r , per[0]) ;
SDL_RenderCopy(r , per_s7 , NULL , &i_per7) ;
SDL_Rect i_per8 = {300 , 0 , 100 , 100} ;
SDL_Texture * per_s8 = SDL_CreateTextureFromSurface (r , per[0]) ;
SDL_RenderCopy(r , per_s8 , NULL , &i_per8) ;
SDL_Rect i_per9 = {300 , 150 , 100 , 100} ;
SDL_Texture * per_s9 = SDL_CreateTextureFromSurface (r , per[0]) ;
SDL_RenderCopy(r , per_s9 , NULL , &i_per9) ;
SDL_Rect i_per10 = {300 , 300 , 100 , 100} ;
SDL_Texture * per_s10 = SDL_CreateTextureFromSurface (r , per[0]) ;
SDL_RenderCopy(r , per_s10 , NULL , &i_per10) ;
SDL_Rect i_per11 = {300 , 450 , 100 , 100} ;
SDL_Texture * per_s11 = SDL_CreateTextureFromSurface (r , per[0]) ;
SDL_RenderCopy(r , per_s11 , NULL , &i_per11) ;
SDL_Rect i_per12 = {450 , 0 , 100 , 100} ;
SDL_Texture * per_s12 = SDL_CreateTextureFromSurface (r , per[0]) ;
SDL_RenderCopy(r , per_s12 , NULL , &i_per12) ;
SDL_Rect i_per13 = {450 , 150 , 100 , 100} ;
SDL_Texture * per_s13 = SDL_CreateTextureFromSurface (r , per[0]) ;
SDL_RenderCopy(r , per_s13 , NULL , &i_per13) ;
SDL_Rect i_per14 = {450 , 300 , 100 , 100} ;
SDL_Texture * per_s14 = SDL_CreateTextureFromSurface (r , per[0]) ;
SDL_RenderCopy(r , per_s14 , NULL , &i_per14) ;
SDL_Rect i_per15 = {450 , 450 , 100 , 100} ;
SDL_Texture * per_s15 = SDL_CreateTextureFromSurface (r , per[0]) ;
SDL_RenderCopy(r , per_s15 , NULL , &i_per15) ;
SDL_Rect i_per15aa = {600 , 500 , 200 , 100} ;
SDL_Texture * per_s15aa = SDL_CreateTextureFromSurface (r , per[15]) ;
SDL_RenderCopy(r , per_s15aa , NULL , &i_per15aa) ;
while (t)
{
Uint8 SDL_GetMouseState(int *x, int *y);
SDL_WaitEvent (&e) ;
while(SDL_PollEvent( &e ) != 0)
{
if( e.type == SDL_QUIT )
t = false ;
if (e.type == SDL_MOUSEBUTTONDOWN&&h == 0){
if (x > 0 && x < 100 && y > 0 && y < 100){
if (e.type == SDL_MOUSEBUTTONDOWN && s <= 2){
SDL_Rect i_per = {0 , 0 , 100 , 100} ;
SDL_Texture * per_s = SDL_CreateTextureFromSurface (r , per[1]) ;
SDL_RenderCopy(r , per_s , NULL , &i_per) ;
s++;
s2 = 1;
if (s == 1){b1 = 0 ; b2 = 0;}
if (s == 2){b3 = 0; b4 = 0;}
}
}
if (x > 0 && x < 100 && y > 150 && y < 250){
if (e.type == SDL_MOUSEBUTTONDOWN && s <= 2){
SDL_Rect i_per1 = {0 , 150 , 100 , 100} ;
SDL_Texture * per_s1 = SDL_CreateTextureFromSurface (r , per[2]) ;
SDL_RenderCopy(r , per_s1 , NULL , &i_per1) ;s++;
s2 = 2;
if (s == 1){b1 = 0 ; b2 = 1;}
if (s == 2){b3 = 0; b4 = 1;}
}
}
if (x > 0 && x < 100 && y > 300 && y < 400){
if (e.type == SDL_MOUSEBUTTONDOWN && s <= 2){
SDL_Rect i_per2 = {0 , 300 , 100 , 100} ;
SDL_Texture * per_s2 = SDL_CreateTextureFromSurface (r , per[6]) ;
SDL_RenderCopy(r , per_s2 , NULL , &i_per2) ;s++;
s2 = 6;
if (s == 1){b1 = 0 ; b2 = 2;}
if (s == 2){b3 = 0; b4 = 2;}
}
}
if (x > 0 && x < 100 && y > 450 && y < 550){
if (e.type == SDL_MOUSEBUTTONDOWN && s <= 2){
SDL_Rect i_per3 = {0 , 450 , 100 , 100} ;
SDL_Texture * per_s3 = SDL_CreateTextureFromSurface (r , per[8]) ;
SDL_RenderCopy(r , per_s3 , NULL , &i_per3) ;
s++;
s2 = 8;
if (s == 1){b1 = 0 ; b2 = 3;}
if (s == 2){b3 = 0; b4 = 3;}
}
}
if (x > 150 && x < 250 && y > 0 && y < 100){
if (e.type == SDL_MOUSEBUTTONDOWN && s <= 2){
SDL_Rect i_per4 = {150 , 0 , 100 , 100} ;
SDL_Texture * per_s4 = SDL_CreateTextureFromSurface (r , per[4]) ;
SDL_RenderCopy(r , per_s4 , NULL , &i_per4) ;
s++;
s2 = 4;
if (s == 1){b1 = 1; b2 = 0;}
if (s == 2){b3 = 1; b4 = 0;}
}
}
if (x > 150 && x < 250 && y > 150 && y < 250){
if (e.type == SDL_MOUSEBUTTONDOWN && s <= 2){
SDL_Rect i_per5 = {150 , 150 , 100 , 100} ;
SDL_Texture * per_s5 = SDL_CreateTextureFromSurface (r , per[3]) ;
SDL_RenderCopy(r , per_s5 , NULL , &i_per5) ;
s++;
s2 = 3;
if (s == 1){b1 = 1 ; b2 = 1;}
if (s == 2){b3 = 1; b4 = 1;}
}
}
if (x > 150 && x < 250 && y > 300 && y < 400){
if (e.type == SDL_MOUSEBUTTONDOWN && s <= 2){
SDL_Rect i_per6 = {150 , 300 , 100 , 100} ;
SDL_Texture * per_s6 = SDL_CreateTextureFromSurface (r , per[7]) ;
SDL_RenderCopy(r , per_s6 , NULL , &i_per6) ;
s++;
s2 = 7;
if (s == 1){b1 = 1 ; b2 = 2;}
if (s == 2){b3 = 1; b4 = 2;}
}
}
if (x > 150 && x < 250 && y > 450 && y < 550){
if (e.type == SDL_MOUSEBUTTONDOWN && s <= 2){
SDL_Rect i_per7 = {150 , 450 , 100 , 100} ;
SDL_Texture * per_s7 = SDL_CreateTextureFromSurface (r , per[5]) ;
SDL_RenderCopy(r , per_s7 , NULL , &i_per7) ;
s++;
s2 = 5;
if (s == 1){b1 = 1 ; b2 = 3;}
if (s == 2){b3 = 1; b4 = 3;}
}
}
if (x > 300 && x < 400 && y > 0 && y < 100){
if (e.type == SDL_MOUSEBUTTONDOWN && s <= 2){
SDL_Rect i_per8 = {300 , 0 , 100 , 100} ;
SDL_Texture * per_s8 = SDL_CreateTextureFromSurface (r , per[1]) ;
SDL_RenderCopy(r , per_s8 , NULL , &i_per8) ;
s++;
s2 = 1;
if (s == 1){b1 = 2 ; b2 = 0;}
if (s == 2){b3 = 2; b4 = 0;}
}
}
if (x > 300 && x < 400 && y > 150 && y < 250){
if (e.type == SDL_MOUSEBUTTONDOWN && s <= 2){
SDL_Rect i_per9 = {300 , 150 , 100 , 100} ;
SDL_Texture * per_s9 = SDL_CreateTextureFromSurface (r , per[5]) ;
SDL_RenderCopy(r , per_s9 , NULL , &i_per9) ;
s++;
s2 = 5;
if (s == 1){b1 = 2 ; b2 = 1;}
if (s == 2){b3 = 2; b4 = 1;}
}
}
if (x > 300 && x < 400 && y > 300 && y < 400){
if (e.type == SDL_MOUSEBUTTONDOWN && s <= 2){
SDL_Rect i_per10 = {300 , 300 , 100 , 100} ;
SDL_Texture * per_s10 = SDL_CreateTextureFromSurface (r , per[8]) ;
SDL_RenderCopy(r , per_s10 , NULL , &i_per10) ;
s++;
s2 = 8;
if (s == 1){b1 = 2 ; b2 = 2;}
if (s == 2){b3 = 2; b4 = 2;}
}
}
if (x > 300 && x < 400 && y > 450 && y < 550){
if (e.type == SDL_MOUSEBUTTONDOWN && s <= 2){
SDL_Rect i_per11 = {300 , 450 , 100 , 100} ;
SDL_Texture * per_s11 = SDL_CreateTextureFromSurface (r , per[4]) ;
SDL_RenderCopy(r , per_s11 , NULL , &i_per11) ;
s++;
s2 = 4;
if (s == 1){b1 = 2 ; b2 = 3;}
if (s == 2){b3 = 2; b4 = 3;}
}
}
if (x > 450 && x < 550 && y > 0 && y < 100){
if (e.type == SDL_MOUSEBUTTONDOWN && s <= 2){
SDL_Rect i_per12 = {450 , 0 , 100 , 100} ;
SDL_Texture * per_s12 = SDL_CreateTextureFromSurface (r , per[6]) ;
SDL_RenderCopy(r , per_s12 , NULL , &i_per12) ;
s++;
s2 = 6;
if (s == 1){b1 = 3 ; b2 = 0;}
if (s == 2){b3 = 3; b4 = 0;}
}
}
if (x > 450 && x < 550 && y > 150 && y < 250){
if (e.type == SDL_MOUSEBUTTONDOWN && s <= 2){
SDL_Rect i_per13 = {450 , 150 , 100 , 100} ;
SDL_Texture * per_s13 = SDL_CreateTextureFromSurface (r , per[2]) ;
SDL_RenderCopy(r , per_s13 , NULL , &i_per13) ;
s++;
s2 = 2;
if (s == 1){b1 = 3 ; b2 = 1;}
if (s == 2){b3 = 3; b4 = 1;}
}
}
if (x > 450 && x < 550 && y > 300 && y < 400){
if (e.type == SDL_MOUSEBUTTONDOWN && s <= 2){
SDL_Rect i_per14 = {450 , 300 , 100 , 100} ;
SDL_Texture * per_s14 = SDL_CreateTextureFromSurface (r , per[3]) ;
SDL_RenderCopy(r , per_s14 , NULL , &i_per14) ;
s++;
s2 = 3;
if (s == 1){b1 = 3 ; b2 = 2;}
if (s == 2){b3 = 3; b4 = 2;}
}
}
if (x > 450 && x < 550 && y > 450 && y < 550){
if (e.type == SDL_MOUSEBUTTONDOWN && s <= 2){
SDL_Rect i_per15 = {450 , 450 , 100 , 100} ;
SDL_Texture * per_s15 = SDL_CreateTextureFromSurface (r , per[7]) ;
SDL_RenderCopy(r , per_s15 , NULL , &i_per15) ;
s++;
s2 = 7;
if (s == 1){b1 = 3 ; b2 = 3;}
if (s == 2){b3 =3; b4 = 3;}
}
}
if (x > 600 && x < 800 && y > 500 && y < 600){
if (e.type == SDL_MOUSEBUTTONDOWN && s <= 2){return 0 ;}
}
}
if (x > 600 && x < 800 && y > 500 && y < 600){
if (e.type == SDL_MOUSEBUTTONDOWN && s <= 2){return 0 ;}
}
}
s%=3;
SDL_GetGlobalMouseState(&x,&y);
if (s==2){
if (a[b1][b2]!=a[b3][b4]){
SDL_RenderPresent (r) ;
SDL_Delay(750);
SDL_Rect i_per21 = {b1*100+(b1)*50 , b2*100+(b2)*50 , 100 , 100} ;
SDL_Texture * per_s21 = SDL_CreateTextureFromSurface (r , per[0]) ;
SDL_RenderCopy(r , per_s21 , NULL , &i_per21) ;
SDL_Rect i_per20 = {b3*100+(b3)*50 , b4*100+(b4)*50 , 100 , 100} ;
SDL_Texture * per_s20 = SDL_CreateTextureFromSurface (r , per[0]) ;
SDL_RenderCopy(r , per_s20 , NULL , &i_per20) ;
s = 0 ;
}
else{s4++;}
}
if(s4 == 8){
SDL_Rect i_per20c = {600 , 100 , 200 , 200} ;
SDL_Texture * per_s20c = SDL_CreateTextureFromSurface (r , per[9]) ;
SDL_RenderCopy(r , per_s20c , NULL , &i_per20c) ;
h = 1;
}
s%=3;
if (s == 2){s=0;}
SDL_RenderPresent (r) ;
SDL_Delay (20) ;
}
for (int j=0 ; j <=10 ; j++)
SDL_FreeSurface(per[j]);
SDL_DestroyRenderer(r);
SDL_DestroyWindow(w);
SDL_Quit();
return 0;
}