Skip to content

Commit da907c7

Browse files
committed
Jogo da Velha: Correção dos Header, include protectors
Lig 4: adicionado o código para suporte à cores, alé do desenvolvimento das funções de interface
1 parent b9e5ae2 commit da907c7

File tree

12 files changed

+462
-7
lines changed

12 files changed

+462
-7
lines changed

Jogo da Velha/Jogo da Velha.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ int main(int argc, char* argv[])
720720
memcpy(freeCellsReturn, freeCells(grid), sizeof(freeCellsReturn));
721721
if (freeCellsReturn[0][0] != -1)
722722
{
723-
if (freeCellsReturn[0][0] = 3)
723+
if (freeCellsReturn[0][0] == 3)
724724
{
725725
gridPrinter(gridTiedReturner(grid, 1), 2);
726726
printf("\nDeu velha...\n");

Jogo da Velha/Jogo da Velha.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef FUNCTIONS_H_INCLUDED
2-
#define FUNCTIONS_H_INCLUDED
1+
#ifndef JOGO_DA_VELHA_MAIN_H
2+
#define JOGO_DA_VELHA_MAIN_H
33
/* ^^ these are the include guards */
44

55
/* Prototypes for the functions */

Jogo da Velha/ai.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef FUNCTIONS_H_INCLUDED
2-
#define FUNCTIONS_H_INCLUDED
1+
#ifndef TIC_TAC_TOE_AI_H
2+
#define TIC_TAC_TOE_AI_H
33
/* ^^ these are the include guards */
44

55
/* Prototypes for the functions */

Jogo da Velha/minimax.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef FUNCTIONS_H_INCLUDED
2-
#define FUNCTIONS_H_INCLUDED
1+
#ifndef MINIMAX_TIC_TAC_TOE_ALGORITHM_H
2+
#define MINIMAX_TIC_TAC_TOE_ALGORITHM_H
33

44

55

Lig 4/Lig 4.c

Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,230 @@
1+
#define _CRT_SECURE_NO_WARNINGS
12
#include <stdio.h>
3+
#include <stdbool.h>
4+
#include "ai.h"
5+
#include "ansi_escapes.h"
6+
#include "Lig 4.h"
27

38

9+
extern void setupConsole(void);
10+
extern void restoreConsole(void);
11+
12+
Win winVerifyer(int grid[6][7])
13+
{
14+
15+
}
16+
17+
void supergridGenerator(char supergrid[37][98])
18+
{
19+
for (int i = 0; i < 37; i++)
20+
{
21+
for (int j = 0; j < 97; j++)
22+
{
23+
if (j != 0 && j != 13 && j != 14 && j != 27 && j != 28 && j != 41 && j != 42 && j != 55 && j != 56 && j != 69 && j != 70 && j != 83 && j != 84 && j != 97)
24+
supergrid[i][j] = ' ';
25+
}
26+
supergrid[i][0] = '|';
27+
supergrid[i][13] = '|';
28+
supergrid[i][14] = '|';
29+
supergrid[i][27] = '|';
30+
supergrid[i][28] = '|';
31+
supergrid[i][41] = '|';
32+
supergrid[i][42] = '|';
33+
supergrid[i][55] = '|';
34+
supergrid[i][56] = '|';
35+
supergrid[i][69] = '|';
36+
supergrid[i][70] = '|';
37+
supergrid[i][83] = '|';
38+
supergrid[i][84] = '|';
39+
supergrid[i][97] = '|';
40+
if (i == 0 || i == 6 || i == 12 || i == 18 || i == 24 || i == 30 || i == 36)
41+
{
42+
for (int j = 0; j < 98; j++)
43+
{
44+
if (supergrid[i][j] != '|')
45+
supergrid[i][j] = ':';
46+
}
47+
}
48+
}
49+
}
50+
51+
void supergridPrinter(char supergrid[37][98], int grid[6][7])
52+
{
53+
for (int i = 0, gridI = 0; i < 37; i++)
54+
{
55+
printf(" ");
56+
if (i > 5)
57+
gridI = 1;
58+
if (i > 11)
59+
gridI = 2;
60+
if (i > 17)
61+
gridI = 3;
62+
if (i > 23)
63+
gridI = 4;
64+
if (i > 29)
65+
gridI = 5;
66+
67+
for (int j = 0, gridJ = 0; j < 98; j++)
68+
{
69+
if (j > 12)
70+
gridJ = 1;
71+
if (j > 26)
72+
gridJ = 2;
73+
if (j > 40)
74+
gridJ = 3;
75+
if (j > 54)
76+
gridJ = 4;
77+
if (j > 68)
78+
gridJ = 5;
79+
if (j > 82)
80+
gridJ = 6;
81+
82+
if (supergrid[i][j] != ':' && supergrid[i][j] != '|')
83+
{
84+
if (grid[gridI][gridJ] == 1)
85+
{
86+
setTextColorBright(BLUE_TXT);
87+
printf("%c", supergrid[i][j]);
88+
setTextColor(WHITE_TXT);
89+
}
90+
if (grid[gridI][gridJ] == -1)
91+
{
92+
setTextColorBright(RED_TXT);
93+
printf("%c", supergrid[i][j]);
94+
setTextColor(WHITE_TXT);
95+
}
96+
if (grid[gridI][gridJ] == 0)
97+
printf("%c", supergrid[i][j]);
98+
}
99+
else
100+
printf("%c", supergrid[i][j]);
101+
}
102+
printf("\n");
103+
}
104+
}
105+
106+
void supergridModifyer(char supergrid[37][98], Move modification)
107+
{
108+
Move startCoordinate, copy_of_startCoordinate, circleCoordinates;
109+
char circle[5][12] = { { ' ', ' ', ' ', '.', '-', '\"', '\"', '-', '.', ' ', ' ', ' ' },
110+
{ ' ', ' ', '/', ' ', ' ', ' ', ' ', ' ', ' ', '\\', ' ', ' ' },
111+
{ ' ', ';', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ';', ' ' },
112+
{ ' ', ' ', '\\', ' ', ' ', ' ', ' ', ' ', ' ', '/', ' ' , ' '},
113+
{ ' ', ' ', ' ', '\'', '-', '.', '.', '-', '\'', ' ', ' ', ' ' } };
114+
115+
if (modification.row == 0)
116+
startCoordinate.row = 1;
117+
if (modification.row == 1)
118+
startCoordinate.row = 7;
119+
if (modification.row == 2)
120+
startCoordinate.row = 13;
121+
if (modification.row == 3)
122+
startCoordinate.row = 19;
123+
if (modification.row == 4)
124+
startCoordinate.row = 25;
125+
if (modification.row == 5)
126+
startCoordinate.row = 31;
127+
128+
if (modification.col == 0)
129+
startCoordinate.col = 1;
130+
if (modification.col == 1)
131+
startCoordinate.col = 15;
132+
if (modification.col == 2)
133+
startCoordinate.col = 29;
134+
if (modification.col == 3)
135+
startCoordinate.col = 43;
136+
if (modification.col == 4)
137+
startCoordinate.col = 57;
138+
if (modification.col == 5)
139+
startCoordinate.col = 71;
140+
if (modification.col == 6)
141+
startCoordinate.col = 85;
142+
copy_of_startCoordinate.col = startCoordinate.col;
143+
copy_of_startCoordinate.row = startCoordinate.row;
144+
for (startCoordinate.row = copy_of_startCoordinate.row, circleCoordinates.row = 0; startCoordinate.row < (copy_of_startCoordinate.row + 5); startCoordinate.row++, circleCoordinates.row++)
145+
{
146+
for (startCoordinate.col = copy_of_startCoordinate.col, circleCoordinates.col = 0; startCoordinate.col < (copy_of_startCoordinate.col + 12); startCoordinate.col++, circleCoordinates.col++)
147+
{
148+
supergrid[startCoordinate.row][startCoordinate.col] = circle[circleCoordinates.row][circleCoordinates.col];
149+
}
150+
}
151+
152+
}
153+
154+
void getTheRow(int grid[6][7], Move *move)
155+
{
156+
for (int i = 6; i >= 0; i--)
157+
{
158+
if (grid[i][move->col] == 0)
159+
{
160+
move->row = i;
161+
break;
162+
}
163+
if (i == 0)
164+
{
165+
move->row = -1;
166+
}
167+
}
168+
}
169+
4170
int main(int argc, char* argv)
5171
{
172+
int grid[6][7] = { 0 };
173+
char supergrid[37][98];
174+
175+
supergridGenerator(supergrid);
176+
printf("\n");
177+
178+
179+
for (int mainMenu = 0; mainMenu == 0;)
180+
{
181+
int player;
182+
char playerNumber[3];
183+
Move playerMove;
184+
char playerMovement[3];
185+
printf("Gostaria de jogar o modo: 1- Singleplyer ou 2- Multiplayer\n");
186+
if (scanf("%i", &player) == 1);
187+
188+
for (char keepPlaying = 's'; keepPlaying == 's' || keepPlaying == 'S';)
189+
{
190+
player = 1;
191+
for (int win = 0, tie = 0; win == 0 && tie == 0;)
192+
{
193+
if (player == 3)
194+
player = 1;
195+
setupConsole();
196+
supergridPrinter(supergrid, grid);
197+
restoreConsole();
198+
printf("Jogue jogador %i\n", player);
199+
if(scanf(" %i", &playerMove.col) == 1);
200+
playerMove.col--;
201+
getTheRow(grid, &playerMove);
202+
if (playerMove.row == -1)
203+
{
204+
printf("Você não pode jogar aí!\n");
205+
getchar();
206+
getchar();
207+
continue;
208+
}
209+
if (player == 1)
210+
grid[playerMove.row][playerMove.col] = 1;
211+
if (player == 2)
212+
grid[playerMove.row][playerMove.col] = -1;
213+
supergridModifyer(supergrid, playerMove);
214+
player++;
215+
}
216+
217+
printf("\nContinuar jogando? s-sim n-não\n");
218+
if (scanf(" %c", &keepPlaying) == 1);
219+
}
220+
}
221+
6222

223+
setBackgroundColor(MAGENTA_BKG);
224+
setTextColorBright(RED_TXT);
225+
puts("Hello, World\n");
226+
setTextColorBright(BLUE_TXT);
227+
puts("Hello, World\n");
228+
restoreConsole();
229+
7230
}

Lig 4/Lig 4.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#ifndef CONNECT_4_MAIN_H
2+
#define CONNECT_4_MAIN_H
3+
4+
#include <stdbool.h>
5+
6+
typedef struct MoveCoordinates {
7+
int row, col;
8+
}Move;
9+
10+
typedef struct WinInfo {
11+
bool win;
12+
char victoryType;
13+
int row, col;
14+
}Win;
15+
16+
#endif

Lig 4/Lig 4.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,12 @@
152152
</ItemDefinitionGroup>
153153
<ItemGroup>
154154
<ClCompile Include="ai.c" />
155+
<ClCompile Include="ansi_escapes.c" />
155156
<ClCompile Include="Lig 4.c" />
156157
</ItemGroup>
157158
<ItemGroup>
158159
<ClInclude Include="ai.h" />
160+
<ClInclude Include="ansi_escapes.h" />
159161
<ClInclude Include="Lig 4.h" />
160162
</ItemGroup>
161163
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

Lig 4/Lig 4.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
<ClCompile Include="ai.c">
2222
<Filter>Arquivos de Origem</Filter>
2323
</ClCompile>
24+
<ClCompile Include="ansi_escapes.c">
25+
<Filter>Arquivos de Origem</Filter>
26+
</ClCompile>
2427
</ItemGroup>
2528
<ItemGroup>
2629
<ClInclude Include="Lig 4.h">
@@ -29,5 +32,8 @@
2932
<ClInclude Include="ai.h">
3033
<Filter>Arquivos de Cabeçalho</Filter>
3134
</ClInclude>
35+
<ClInclude Include="ansi_escapes.h">
36+
<Filter>Arquivos de Cabeçalho</Filter>
37+
</ClInclude>
3238
</ItemGroup>
3339
</Project>

Lig 4/ai.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#include "Lig 4.h"
2+

Lig 4/ai.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#ifndef CONNECT_4_AI_H
2+
#define CONNECT_4_AI_H
3+
4+
5+
#endif

0 commit comments

Comments
 (0)