Files
snake/src/main.c
T
2026-03-03 23:06:32 -05:00

40 lines
767 B
C

#include <fcntl.h>
#include <termios.h>
#include <unistd.h>
#include <time.h>
#include "engine.h"
int
main()
{
Engine engine;
engine_init(&engine);
char status[64] = { 0 };
static struct termios oldt, newt;
struct timespec req;
tcgetattr(STDIN_FILENO, &oldt);
newt = oldt;
newt.c_lflag &= ~(ICANON | ECHO);
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
req.tv_nsec = 1.5e8;
req.tv_sec = 0;
fcntl(0, F_SETFL, fcntl(0, F_GETFL) | O_NONBLOCK);
while (is_open(status, 64, &engine) && process_input(&engine.dir))
{
if(equals(&engine.fruit, &engine.head)) {
eat(&engine);
}
move(&engine);
engine_display(&engine);
nanosleep(&req, NULL);
}
write(1, status, sizeof(status));
write(1, "\033[?25h", 6);
tcsetattr(0, TCSANOW, &oldt);
return 0;
}