You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
2.3 KiB

// System headers
#include <windows.h>
// Standard library C-style
#include <wchar.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <conio.h>
#define ESC "\x1b"
#define CSI "\x1b["
bool EnableVTMode()
{
// Set output mode to handle virtual terminal sequences
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
if (hOut == INVALID_HANDLE_VALUE)
{
return false;
}
DWORD dwMode = 0;
if (!GetConsoleMode(hOut, &dwMode))
{
return false;
}
dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
if (!SetConsoleMode(hOut, dwMode))
{
return false;
}
return true;
}
void gibberish()
{
system("cls");
printf(CSI "1;32m");
printf("HELLO THERE\n");
printf("WHAT IF\n");
printf("YOU COULD\n");
printf("MOVE THE CURSOR\n");
}
int get_key()
{
int c = getch();
switch (c)
{
case 0:
return getch() + 256;
case 224:
return getch() + 512;
}
return c;
}
void printGrid()
{
printf("%s", " _ _ _ \n");
printf("%s", "|_|_|_|\n");
printf("%s", "|_|_|_|\n");
printf("%s", "|_|_|_|\n");
}
// int main()
// {
// system("clear");
// printf(CSI "1;32m");
// printf("HELLO THERE\n");
// printf("WHAT IF\n");
// printf("YOU COULD\n");
// printf("MOVE THE CURSOR\n");
// // printf(CSI "2;2H");
// printf(CSI "1C");
// _getch();
// }
// ┌─┬─┬─┐
// │
// └─┴─┴─┘
int main(int argc, char const *argv[])
{
EnableVTMode();
system("clear");
// gibberish();
printGrid();
printf(CSI "2;2H");
int key = 0;
for (;;)
{
if (kbhit())
{
key = get_key();
switch (key)
{
case 584:
printf(CSI "1A"); //up
break;
case 592:
printf(CSI "1B"); //down
break;
case 589:
printf(CSI "1C"); //right
break;
case 587:
printf(CSI "1D"); //left
break;
case 32:
printf("X");
break;
default:
break;
}
}
}
return 0;
}