Match3 - Galeria de Exemplos
 Match3
 Descrição: Match3 é um jogo de puzzle cujo objetivo é juntar 3 ou mais ETs iguais verticalmente ou horizontalmente para ganhar pontos.
Autores: William Sathler Lacerda
Gabrielle Brandemburg dos Anjos
Raphael Accioly Novello
Pedro Henrique Braga Lisboa

 

Download (Executável): Match3.zip

Download (Código Fonte): Match3_SRC.zip


Código Fonte:

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
#include <stdio.h>
#include "Graphics.h"
#include <time.h>
#include <stdlib.h>
#include "Audio.h"
Graphics graphics;
int board[8][8];
int xx, yy, b1, b2;
int w = 1, x3, x4, y3, y4;
int mov = 25, cmov = 0;
int pontos = 0, cpontos;
int b, k = 2;
int cc = 0;
int dd;
bool t_inicial = true;
bool gmove = false;
bool g_over = false;
bool semcredito = false;
Image img;
Image tinicial, tcredit, button_play, button_menu, gover, iPonto, iMoves;
Image alien1, alien2, alien3, alien4, alien5, alien6;
Image grid, back;
Audio Musica, boom;
void MainLoop()
{      
    int Xw = ((graphics.GetScreenWidth() / 2) - (292));
    int Yw = ((graphics.GetScreenHeight() / 2) - (200));
    int xb = ((graphics.GetScreenWidth() / 2) - (90)); 
    int yb = ((graphics.GetScreenHeight() / 2) - (16));
            
    mov = mov - cmov;
    cmov = 0;
    if (mov == 0)
    {
        g_over = true;
    }
    
    for(b1 = 0; b1 < 3000 ; b1 += 256)
    {
        for ( b2 = 0; b2 < 1000 ; b2 += 256)
        {
            graphics.DrawImage2D(b1, b2, 256, 256, back);
        }
    }
    if (t_inicial == true)
    {
        mov = 25;
        pontos = 0;
        cpontos=0;
        graphics.DrawImage2D(Xw, Yw, 584, 400, tcredit);
        graphics.DrawImage2D(button_play);
        button_play.SetPosition(xb,yb + 20,200,52);
        g_over = false;
    }
    else if (g_over == true)
    {
        graphics.DrawImage2D(Xw, Yw, 584, 400, gover);
        graphics.DrawImage2D(xb, yb, 180, 32, button_menu);
        button_menu.SetPosition(xb,yb,180,32);     
        graphics.DrawImage2D((xb-10),(yb-50),200,52, iPonto);
        graphics.DrawText2D((xb+50),(yb-70),"%d",pontos);  
    }
    else
    {
        int xw = ((graphics.GetScreenWidth() / 2) - (256));
        int yw = ((graphics.GetScreenHeight() / 2) - (256));
        graphics.DrawImage2D(xw,yw,512,512, grid);
        
        graphics.DrawImage2D((xw+490),(yw+450),150,32, iPonto);
        graphics.DrawText2D((xw+520),(yw+425),"%d",pontos);
        graphics.DrawImage2D((xw+490),(yw+350),150,32, iMoves);
        graphics.DrawText2D((xw+520),(yw+325),"%d",mov);
        graphics.DrawImage2D(button_menu);
        button_menu.SetPosition((xw+490),(yw+250),180,52); 
        for (xx = 0 ; xx < 8 ; xx ++)
        {
            for(yy = 0; yy < 8; yy ++)
            {
                if (board[xx][yy] == 0)
                {
                    graphics.DrawImage2D(xw + xx*64, yw + yy*64, 64, 64, alien1);
                }
                if (board[xx][yy] == 1)
                {
                    graphics.DrawImage2D(xw + xx*64, yw + yy*64, 64, 64, alien2);
                }
                if (board[xx][yy] == 2)
                {
                    graphics.DrawImage2D(xw + xx*64, yw + yy*64, 64, 64, alien3);
                }
                if (board[xx][yy] == 3)
                {
                    graphics.DrawImage2D(xw + xx*64, yw + yy*64, 64, 64, alien4);
                }
                if (board[xx][yy] == 4)
                {
                    graphics.DrawImage2D(xw + xx*64, yw + yy*64, 64, 64, alien5);
                }
                if (board[xx][yy] == 5)
                {
                    graphics.DrawImage2D(xw + xx*64, yw + yy*64, 64, 64, alien6);
                }
            }
        }
        for (xx = 0 ; xx < 8 ; xx ++)
        {
            
            for (yy = 0 ; yy < 8 ; yy ++)
            {
                cc = 0;
                //Destroi pecas iguais na horizontal
                if (board[xx][yy] != -1)
                {
                    while (board[xx + cc][yy] == board[xx + cc + 1][yy])
                    {
                        cc++;
                        if (xx + cc + 1 > 7)
                            break;
                    }
                }
                if (cc >= 2)
                {
                    for (int aa = 0; aa <= cc; aa++)
                    {
                        if (xx + aa > 7)
                            break;
                        board[xx + aa][yy] = -1;
                    }
                    boom.Stop();
                    boom.Play();
                }
                k=cc+1;
                cc = 0;
                //Destroi pecas iguais na vertical
                if (board[xx][yy] != -1)
                {
                    while (board[xx][yy + cc] == board[xx][yy + cc + 1])
                    {
                        cc++;
                        if (yy + cc + 1 > 7)
                            break;
                    }
                }
                if (cc >= 2)
                {
                    for (int aa = 0; aa <= cc; aa++)
                    {
                        if (yy + aa > 7)
                            break;
                        board[xx][yy + aa] = -1;
                    }
                    boom.Stop();
                    boom.Play();
                    k = cc + 1;            
                }
                // Pontuação   
                if (k>2)
                {
                    cpontos = 20*k;
                    pontos = pontos + cpontos;
                    k = 0;
                }           
            }
        }      
        //Abaixa as pecas que estiverem em cima
        for (yy = 0 ; yy < 8 ; yy ++)
        {
            for (xx = 0 ; xx < 8 ; xx ++)
            {
                if (board[xx][yy] == -1)
                {
                    for (int aa = yy; aa < 7; aa++)
                    {                      
                        board[xx][aa] = board[xx][aa+1];   
                    }
                    board[xx][7] = -1;
                
                }
            }
        }
        //Gera novas pecas nos lugares vazios
        for (yy = 0 ; yy < 8 ; yy ++)
        {
            for (xx = 0 ; xx < 8 ; xx ++)
            {
                if (board[xx][yy] == -1)
                {
                    int rnd = rand()%6;
                    board[xx][yy] = rnd;
                }
            }
        }
    }
    
}
void ClickButtonPlay(int button, int state, int x, int y)
{
    t_inicial = false;
}
void ClickButtonMenu(int button, int state, int x, int y)
{
    t_inicial = true;
}
void MouseClickInput ( int button, int state, int x, int y)
{
    int xw = ((graphics.GetScreenWidth() / 2) - (256));
    int yw = ((graphics.GetScreenHeight() / 2) - (256));
    if ((!t_inicial)&&(!g_over))
    {
        if (w == 1)
        {
            if ((button == MOUSE_LEFT_BUTTON)&&(state == MOUSE_STATE_DOWN))
            {
                x3 = (int)((x-xw)/64);
                y3 = (int)((y-yw)/64);
                w = 2;
            }
        }
        else if (w == 2)
        {
            if ((button == MOUSE_LEFT_BUTTON)&&(state == MOUSE_STATE_DOWN))
            {
                x4 = (int)((x-xw)/64);
                y4 = (int)((y-yw)/64);
                w = 1;
                if ((x3 == (x4 + 1) || x3 == (x4 -1)) && y3 == y4 )
                {
                    int memoria = board[x3][y3];
                    board[x3][y3] = board[x4][y3];
                    board[x4][y3] = memoria;
                    cmov=1;
                }
                if ((y3 == (y4 +1) || y3 == (y4 - 1)) && x3 == x4 )        
                {
                    int memoria = board[x3][y3];
                    board[x3][y3] = board[x3][y4];
                    board[x3][y4] = memoria;
                    cmov=1;
                }
            }
        }  
    }
}
int main(void)
{
    int x, y;
    graphics.CreateMainWindow(784,572,"Match3");
    srand(time(NULL));
    for(y = 0; y < 8; y++)
    {
        for(x = 0; x < 8; x++)
        {
            int rnd = rand()%6;
            board[x][y] = rnd;
        }
    }
    for (int t = 0; t < 5; t++)
    {
        for (xx = 0 ; xx < 8 ; xx ++)
        {
            for (yy = 0 ; yy < 8 ; yy ++)
            {
                int cc = 0;
                //Destroi pecas iguais na horizontal
                if (board[xx][yy] != -1)
                {
                    while (board[xx + cc][yy] == board[xx + cc + 1][yy])
                    {
                        cc++;
                        if (xx + cc + 1 > 7)
                            break;
                    }
                }
                if (cc >= 2)
                {
                    for (int aa = 0; aa <= cc; aa++)
                    {
                        if (xx + aa > 7)
                            break;
                        board[xx + aa][yy] = -1;
                    }
                }
                cc = 0;
                //Destroi pecas iguais na vertical
                if (board[xx][yy] != -1)
                {
                    while (board[xx][yy + cc] == board[xx][yy + cc + 1])
                    {
                        cc++;
                        if (yy + cc + 1 > 7)
                            break;
                    }
                }
                if (cc >= 2)
                {
                    for (int aa = 0; aa <= cc; aa++)
                    {
                        if (yy + aa > 7)
                            break;
                        board[xx][yy + aa] = -1;
                    }
                }  
            }
        }
        for(y = 0; y < 8; y++)
        {
            for(x = 0; x < 8; x++)
            {
                if (board[x][y] == -1)
                {
                int rnd = rand()%6;
                board[x][y] = rnd;
                }
            }
        }  
    }
    
    for(y = 0; y < 8; y++)
    {
        for(x = 0; x < 8; x++)
        {
            if (board[x][y] == -1)
            {
            int rnd = rand()%6;
            board[x][y] = rnd;
            }
        }
    }
    
    tcredit.LoadPNGImage("Data\\tcredit.png"); 
    tinicial.LoadPNGImage("Data\\tinicial.png");
    iPonto.LoadPNGImage("Data\\button_score.png");
    iMoves.LoadPNGImage("Data\\button_move.png");
    button_play.LoadPNGImage("Data\\button_play.png");
    button_play.SetOnClick(ClickButtonPlay);
    gover.LoadPNGImage("Data\\g_over.png");
    button_menu.LoadPNGImage("Data\\button_menu.png");
    button_menu.SetOnClick(ClickButtonMenu);
    Musica.LoadAudio("Data\\Background.mp3");
    Musica.Play();
    boom.LoadAudio("Data\\boom.mp3");
    back.LoadPNGImage("Data\\background.png");
    grid.LoadPNGImage("Data\\grid.png");
    alien1.LoadPNGImage("Data\\alien1.png");
    alien2.LoadPNGImage("Data\\alien2.png");
    alien3.LoadPNGImage("Data\\alien3.png");
    alien4.LoadPNGImage("Data\\alien4.png");
    alien5.LoadPNGImage("Data\\alien5.png");
    alien6.LoadPNGImage("Data\\alien6.png");
    graphics.SetTextFont("Courier Regular", 36, FONT_WEIGHT_NORMAL, false, false);
    graphics.SetMouseClickInput(MouseClickInput);
    graphics.SetMainLoop(MainLoop);
    graphics.StartMainLoop();
    return 0;
}