-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraphics.cpp
More file actions
117 lines (88 loc) · 2.65 KB
/
graphics.cpp
File metadata and controls
117 lines (88 loc) · 2.65 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
#include "graphics.h"
#define CLEAR_COLOR CINZA_ESCURO
#define EMPATE_COLOR CINZA
#define PLAYER1_COLOR VERMELHO
#define PLAYER2_COLOR AZUL
void draw_board(CONNECT4 * game){
if(game == NULL)
return;
const char * tabuleiro = get_tabuleiro(game);
float x, y;
COR cor;
glColor3ubv(BEGE);
glBegin(GL_POLYGON);
glVertex2d(0.7, 0.7);
glVertex2d(0.7, -0.7);
glVertex2d(-0.7, -0.7);
glVertex2d(-0.7, 0.7);
glEnd();
for (int i = 0; i < TAM_TAB; i++){
for (int j = 0; j < TAM_TAB; j++){
x = -0.6 + j*0.2;
y = -0.6 + i*0.2;
cor = tabuleiro[i * TAM_TAB + j] == 1? PLAYER1_COLOR : tabuleiro[i * TAM_TAB + j] == 0? CLEAR_COLOR : PLAYER2_COLOR;
glColor3ubv(cor);
glBegin(GL_POLYGON);
for (float i = 0; i < 360.0; i+= 5){
glVertex2d(0.07*cos((i/180.0)*M_PI) + x, 0.07*sin((i/180.0)*M_PI) + y);
}
glEnd();
}
}
}
void draw_vencedor(CONNECT4 * game){
if(!acabou(game))
return;
unsigned char vencedor = get_vencedor(game);
COR c;
const char * mensagem;
switch(vencedor){
case 1 :
c = PLAYER1_COLOR;
mensagem = "JOGADOR 1 VENCEU !!!";
break;
case 0 :
c = EMPATE_COLOR;
mensagem = "EMPATE !!!";
break;
default:
c = PLAYER2_COLOR;
mensagem = "JOGADOR 2 VENCEU !!!";
break;
}
glColor3ubv(c);
glBegin(GL_POLYGON);
glVertex2d(-0.6, 0.9);
glVertex2d(0.6, 0.9);
glVertex2d(0.6, 0.75);
glVertex2d(-0.6, 0.75);
glEnd();
glColor3ubv(BRANCO);
glRasterPos2f(-0.5, 0.8); // Set the position for the text
while (*mensagem) {
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, *mensagem); // Render each character
mensagem++;
}
}
void mouse_handler(int button, int state, int x, int y, CONNECT4 * game){
int coluna;
float mouseX, mouseY;
// Converte a entrada para pontos (x,y) na tela
mouseX = 2*((float(x)/WIN_WIDTH)-0.5);
mouseY = -2*((float(y)/WIN_HEIGHT)-0.5);
if(mouseX < -0.7 || mouseX > 0.7 || mouseY < -0.7 || mouseY > 0.7) // mouse fora do tabuleiro, descarta
return;
coluna = (mouseX*10 + 7)/2;
adicionar_peca(game, coluna);
}
void render(CONNECT4 * game){
// Clear the window with the specified color
glClear(GL_COLOR_BUFFER_BIT);
draw_vencedor(game);
draw_board(game);
glutSwapBuffers();
}
void timer(int a){
glutPostRedisplay();
glutTimerFunc(1000/60, timer, 0);
}