Skip to content

Commit 76ad8b3

Browse files
committed
Poucas alterações. Lig 4: modo RGB padrão implantado
1 parent 378d481 commit 76ad8b3

File tree

4 files changed

+102
-8
lines changed

4 files changed

+102
-8
lines changed

Jogo da Velha/Jogo da Velha.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ int* winVerifyer(int grid[3][3])
8080
}
8181
}
8282

83+
84+
8385
for (j = 0; j < 3; j++)
8486
{
8587
if (grid[0][j] == -1)

Lig 4/Lig 4.c

Lines changed: 85 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88

99
extern void setupConsole(void);
10+
extern void restoreConsoleMode(void);
1011
extern void restoreConsole(void);
1112

1213
Win winVerifyer(int grid[6][7])
@@ -186,23 +187,23 @@ void supergridPrinter(char supergrid[37][98], int grid[6][7], Move winCoordinate
186187
for (int count = 0; count < 4; count++)
187188
{
188189
if (winCoordinates[count].col == gridJ && winCoordinates[count].row == gridI)
189-
setBackgroundColorBright(WHITE_BKG);
190+
setBackgroundColorRGB(50, 50, 50);
190191
}
191192
printf("%c", supergrid[i][j]);
192193
setTextColor(WHITE_TXT);
193-
setBackgroundColor(BLACK_BKG);
194+
setBackgroundColorRGB(20, 20, 20);
194195
}
195196
if (grid[gridI][gridJ] == -1)
196197
{
197198
setTextColorBright(RED_TXT);
198199
for (int count = 0; count < 4; count++)
199200
{
200201
if (winCoordinates[count].col == gridJ && winCoordinates[count].row == gridI)
201-
setBackgroundColor(WHITE_BKG);
202+
setBackgroundColorRGB(50, 50, 50);
202203
}
203204
printf("%c", supergrid[i][j]);
204205
setTextColor(WHITE_TXT);
205-
setBackgroundColor(BLACK_BKG);
206+
setBackgroundColorRGB(20, 20, 20);
206207
}
207208
if (grid[gridI][gridJ] == 0)
208209
printf("%c", supergrid[i][j]);
@@ -283,8 +284,39 @@ int main(int argc, char* argv)
283284
int grid[6][7] = { 0 };
284285
char supergrid[37][98];
285286

286-
printf("\n");
287+
printf("Test Mode?\n");
288+
int test_mode;
289+
test_mode = getchar();
290+
while (test_mode == '1')
291+
{
292+
int r, g, b, text;
293+
bool textColor;
294+
printf("Red __ Green __ Blue __\n");
295+
scanf(" %i %i %i", &r, &g, &b);
296+
if (r == -1 || g == -1 || b == -1)
297+
break;
298+
printf(" True - Blue, False - Red\n");
299+
scanf(" %d", &text);
300+
textColor = text;
301+
if (textColor == true)
302+
setTextColor(BLUE_TXT);
303+
else
304+
setTextColor(RED_TXT);
305+
setBackgroundColorRGB(r, g, b);
306+
char circle[5][12] = { { ' ', ' ', ' ', '.', '-', '\"', '\"', '-', '.', ' ', ' ', ' ' },
307+
{ ' ', ' ', '/', ' ', ' ', ' ', ' ', ' ', ' ', '\\', ' ', ' ' },
308+
{ ' ', ';', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ';', ' ' },
309+
{ ' ', ' ', '\\', ' ', ' ', ' ', ' ', ' ', ' ', '/', ' ' , ' '},
310+
{ ' ', ' ', ' ', '\'', '-', '.', '.', '-', '\'', ' ', ' ', ' ' } };
311+
for (int i = 0; i < 5; i++)
312+
{
313+
for (int j = 0; j < 12; j++)
314+
printf("%c", circle[i][j]);
315+
printf("\n");
316+
}
317+
287318

319+
}
288320

289321
for (bool mainMenu = true; mainMenu == true;)
290322
{
@@ -294,6 +326,38 @@ int main(int argc, char* argv)
294326
char playerMovement[3];
295327
Win winVerifyerReturn;
296328
Move winCoordinates[4];
329+
bool isMaximazed = false;
330+
setupConsole();
331+
setBackgroundColorRGB(20, 20, 20);
332+
printf("Você vai precisar maximizar a janela do console para poder jogar\n");
333+
printf("Gostaria de testar pra ver se está funcionando? s- sim n- não\n");
334+
restoreConsoleMode();
335+
if (getchar() == 's')
336+
{
337+
supergridGenerator(supergrid);
338+
for (int i = 0; i < 6; i++)
339+
{
340+
for (int j = 0; j < 7; j++)
341+
grid[i][j] = 0;
342+
}
343+
setupConsole();
344+
setBackgroundColorRGB(20, 20, 20);
345+
moveTo(0, 0);
346+
clearScreenToBottom();
347+
moveTo(0, 0);
348+
supergridPrinter(supergrid, grid, winCoordinates);
349+
printf("\n\n\n\n");
350+
supergridPrinter(supergrid, grid, winCoordinates);
351+
restoreConsoleMode();
352+
printf("\nEsses dois tabuleiros foram impressos iguais? s- sim n- não\n");
353+
if (getchar() == 's')
354+
{
355+
printf("Confirmado, executando modo expandido!\n");
356+
isMaximazed = true;
357+
}
358+
printf("Bem, aparentemente não. Caso você errou o teste você pode reiniciar o programa\n");
359+
360+
}
297361
printf("Gostaria de jogar o modo: 1- Singleplyer ou 2- Multiplayer\n");
298362
if (scanf("%i", &player) == 1);
299363

@@ -317,12 +381,25 @@ int main(int argc, char* argv)
317381
if (player == 3)
318382
player = 1;
319383
setupConsole();
320-
printf("/033[90");
384+
setBackgroundColorRGB(20, 20, 20);
385+
if (isMaximazed == true)
386+
{
387+
moveTo(0, 0);
388+
clearScreenToBottom();
389+
moveTo(0, 0);
390+
}
391+
else
392+
clearScreen();
321393
supergridPrinter(supergrid, grid, winCoordinates);
322-
restoreConsole();
394+
restoreConsoleMode();
323395
printf("Jogue jogador %i\n", player);
324396
if(scanf(" %i", &playerMove.col) == 1);
325397
playerMove.col--;
398+
if (playerMove.col > 6 || playerMove.col < 0)
399+
{
400+
printf("Fora de Alcance!");
401+
continue;
402+
}
326403
getTheRow(grid, &playerMove);
327404
if (playerMove.row == -1)
328405
{
@@ -385,7 +462,7 @@ int main(int argc, char* argv)
385462
if (scanf(" %c", &keepPlaying) == 1)
386463
continue;
387464
printf("Voltar ao menu principal? s-sim n-não\n");
388-
if (getchar() == '\n');
465+
getchar();
389466
if (getchar() == 'n')
390467
mainMenu = false;
391468
}

Lig 4/ansi_escapes.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ void setupConsole(void) {
4545
}
4646
}
4747

48+
void restoreConsoleMode(void) {
49+
if (!SetConsoleMode(stdoutHandle, outModeInit) || !SetConsoleMode(stdinHandle, inModeInit)) {
50+
exit(GetLastError());
51+
}
52+
}
53+
4854
void restoreConsole(void) {
4955
// Reset colors
5056
printf("\x1b[0m");

Lig 4/ansi_escapes.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,14 @@ enum ClearCodes {
3030
};
3131

3232
void setupConsole(void);
33+
void restoreConsoleMode(void);
3334
void restoreConsole(void);
3435
void getCursorPosition(int* row, int* col);
3536

37+
static inline setTextColorRGB(int r, int g, int b) {
38+
printf("\x1b[38;2;%d;%d;%dm", r, g, b);
39+
}
40+
3641
static inline void setTextColor(int code) {
3742
printf("\x1b[%dm", code);
3843
}
@@ -41,6 +46,10 @@ static inline void setTextColorBright(int code) {
4146
printf("\x1b[%d;1m", code);
4247
}
4348

49+
static inline setBackgroundColorRGB(int r, int g, int b) {
50+
printf("\x1b[48;2;%d;%d;%dm", r, g, b);
51+
}
52+
4453
static inline void setBackgroundColor(int code) {
4554
printf("\x1b[%dm", code);
4655
}

0 commit comments

Comments
 (0)