40 lines
769 B
C
40 lines
769 B
C
#include <fcntl.h>
|
|
#include <termios.h>
|
|
#include <time.h>
|
|
#include <unistd.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;
|
|
}
|