Skip to content

Commit 34d8730

Browse files
committed
A definição de cores personalizadas por arquivo ou argumento foi retirada. Tentando fazer arte com o console: faze-lo mudar de tamanho. Já consigo pegar o tamanho do cmd. Ele tem que estar com resolução de 100x40 caracteres
1 parent de2480e commit 34d8730

File tree

1 file changed

+77
-56
lines changed

1 file changed

+77
-56
lines changed

Lig 4/Lig 4.c

Lines changed: 77 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,34 @@
55
#include "ansi_escapes.h"
66
#include "lig 4.h"
77

8+
#ifdef __linux__
9+
#define linux
10+
#include <sys/ioctl.h>
11+
#endif //define to just compile linux code
12+
13+
#ifdef _WIN32
14+
#define windows
15+
#include <windows.h>
16+
#include <wincon.h>
17+
#include <consoleapi2.h>
18+
19+
BOOL WINAPI SetConsoleWindowInfo(
20+
_In_ HANDLE hConsoleOutput,
21+
_In_ BOOL bAbsolute,
22+
_In_ const SMALL_RECT* lpConsoleWindow
23+
);
24+
#endif //define to just compile windows code
25+
26+
#ifdef __APPLE__ && __MACH__
27+
#define mac
28+
#include <sys/ioctl.h>
29+
#endif // __APPLE__ && __MACH__
830

931
extern void setupConsole(void);
1032
extern void restoreConsoleMode(void);
1133
extern void restoreConsole(void);
1234

35+
1336
Win winVerifyer(int grid[6][7])
1437
{
1538
Win returnValue;
@@ -192,9 +215,11 @@ void supergridPrinter(char supergrid[37][98], int grid[6][7], Move winCoordinate
192215
printf("%c", supergrid[i][j]);
193216
setTextColor(WHITE_TXT);
194217
setBackgroundColorRGB(20, 20, 20);
218+
195219
}
196220
if (grid[gridI][gridJ] == -1)
197221
{
222+
198223
setTextColorBright(RED_TXT);
199224
for (int count = 0; count < 4; count++)
200225
{
@@ -204,6 +229,7 @@ void supergridPrinter(char supergrid[37][98], int grid[6][7], Move winCoordinate
204229
printf("%c", supergrid[i][j]);
205230
setTextColor(WHITE_TXT);
206231
setBackgroundColorRGB(20, 20, 20);
232+
207233
}
208234
if (grid[gridI][gridJ] == 0)
209235
printf("%c", supergrid[i][j]);
@@ -223,7 +249,7 @@ void supergridModifyer(char supergrid[37][98], Move modification)
223249
{ ' ', ';', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ';', ' ' },
224250
{ ' ', ' ', '\\', ' ', ' ', ' ', ' ', ' ', ' ', '/', ' ' , ' '},
225251
{ ' ', ' ', ' ', '\'', '-', '.', '.', '-', '\'', ' ', ' ', ' ' } };
226-
252+
227253
if (modification.row == 0)
228254
startCoordinate.row = 1;
229255
if (modification.row == 1)
@@ -263,7 +289,7 @@ void supergridModifyer(char supergrid[37][98], Move modification)
263289

264290
}
265291

266-
void getTheRow(int grid[6][7], Move *move)
292+
void getTheRow(int grid[6][7], Move* move)
267293
{
268294
for (int i = 5; i >= 0; i--)
269295
{
@@ -279,45 +305,14 @@ void getTheRow(int grid[6][7], Move *move)
279305
}
280306
}
281307

282-
int main(int argc, char* argv)
308+
309+
310+
int main(int argc, char** argv)
283311
{
284312
int grid[6][7] = { 0 };
285313
char supergrid[37][98];
286314

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-
318315

319-
}
320-
321316
for (bool mainMenu = true; mainMenu == true;)
322317
{
323318
int player;
@@ -327,21 +322,45 @@ int main(int argc, char* argv)
327322
Win winVerifyerReturn;
328323
Move winCoordinates[4];
329324
bool isMaximazed = false;
325+
char choice[10];
326+
327+
//used to freeze the program instead of getchar
328+
char trashCan[10];
329+
330330
setupConsole();
331331
setBackgroundColorRGB(20, 20, 20);
332332
printf("Você vai precisar maximizar a janela do console para poder jogar\n");
333+
334+
#ifdef windows
335+
while (0) {
336+
CONSOLE_SCREEN_BUFFER_INFO csbi;
337+
int columns, rows;
338+
339+
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
340+
columns = csbi.srWindow.Right - csbi.srWindow.Left + 1;
341+
rows = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
342+
343+
printf(" %i %i", rows, columns);
344+
if (columns == 0 && rows == 0)
345+
{
346+
printf("A janela não está no tamanha adequado!\n");
347+
printf("Aparentemente sua resolução de tela é pequena, rodando no modo legacy");
348+
}
349+
getchar();
350+
}
351+
#endif
352+
333353
printf("Gostaria de testar pra ver se está funcionando? s- sim n- não\n");
334354
restoreConsoleMode();
335-
if (getchar() == 's')
355+
fgets(trashCan, 5, stdin);
356+
if (trashCan[0] == 's' || trashCan[0] == 'S')
336357
{
337358
supergridGenerator(supergrid);
338359
for (int i = 0; i < 6; i++)
339360
{
340361
for (int j = 0; j < 7; j++)
341362
grid[i][j] = 0;
342363
}
343-
setupConsole();
344-
setBackgroundColorRGB(20, 20, 20);
345364
moveTo(0, 0);
346365
clearScreenToBottom();
347366
moveTo(0, 0);
@@ -377,23 +396,35 @@ int main(int argc, char* argv)
377396
winCoordinates[count].row = -1;
378397
winCoordinates[count].col = -1;
379398
}
380-
381399
if (player == 3)
382-
player = 1;
400+
player = 1;
383401
setupConsole();
384402
setBackgroundColorRGB(20, 20, 20);
403+
385404
if (isMaximazed == true)
386405
{
387406
moveTo(0, 0);
388407
clearScreenToBottom();
389408
moveTo(0, 0);
390409
}
410+
391411
else
392412
clearScreen();
413+
393414
supergridPrinter(supergrid, grid, winCoordinates);
415+
#ifdef windows
416+
CONSOLE_SCREEN_BUFFER_INFO csbi;
417+
int columns, rows;
418+
419+
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
420+
columns = csbi.srWindow.Right - csbi.srWindow.Left + 1;
421+
rows = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
422+
423+
printf(" %i %i\n", rows, columns);
424+
#endif
394425
restoreConsoleMode();
395426
printf("Jogue jogador %i\n", player);
396-
if(scanf(" %i", &playerMove.col) == 1);
427+
while (scanf(" %i", &playerMove.col) != 1);
397428
playerMove.col--;
398429
if (playerMove.col > 6 || playerMove.col < 0)
399430
{
@@ -404,8 +435,7 @@ int main(int argc, char* argv)
404435
if (playerMove.row == -1)
405436
{
406437
printf("Você não pode jogar aí!\n");
407-
getchar();
408-
getchar();
438+
fgets(trashCan, 5, stdin);
409439
continue;
410440
}
411441
if (player == 1)
@@ -460,20 +490,11 @@ int main(int argc, char* argv)
460490

461491
printf("\nContinuar jogando? s-sim n-não\n");
462492
if (scanf(" %c", &keepPlaying) == 1)
463-
continue;
493+
continue;
464494
printf("Voltar ao menu principal? s-sim n-não\n");
465-
getchar();
466-
if (getchar() == 'n')
495+
fgets(trashCan, 5, stdin);
496+
if (trashCan[0] == 'n' || trashCan[1] == 'N')
467497
mainMenu = false;
468498
}
469499
}
470-
471-
472-
setBackgroundColor(MAGENTA_BKG);
473-
setTextColorBright(RED_TXT);
474-
puts("Hello, World\n");
475-
setTextColorBright(BLUE_TXT);
476-
puts("Hello, World\n");
477-
restoreConsole();
478-
479500
}

0 commit comments

Comments
 (0)