converting to c
This commit is contained in:
+42
@@ -0,0 +1,42 @@
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.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))
|
||||
{
|
||||
add_tail_and_respawn_fruit(&engine);
|
||||
determine_index_zero_pos(&engine);
|
||||
move_tail_indicies(engine.tail, engine.tail_size, &engine.prev_head, engine.view);
|
||||
|
||||
engine_display(&engine);
|
||||
nanosleep(&req, NULL);
|
||||
}
|
||||
for(int i = 0; i < engine.tail_size; i++) {
|
||||
free(engine.tail[i]);
|
||||
}
|
||||
write(1, status, sizeof(status));
|
||||
write(1, "\033[?25h", 6);
|
||||
tcsetattr(0, TCSANOW, &oldt);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user