ncurses-gameoflife/main.c

46 lines
655 B
C
Raw Normal View History

2020-06-27 08:21:47 +08:00
#include <stdio.h>
2020-06-12 09:46:44 +08:00
#include <ncurses.h>
// Delay and timing.
2020-06-12 09:46:44 +08:00
#include <unistd.h>
#include <time.h>
// math
#include <math.h>
// game
#include "game.h"
2020-07-01 09:01:52 +08:00
#include "log.h"
2020-06-12 09:46:44 +08:00
2020-06-12 09:46:44 +08:00
int main()
{
// framerate of the game
2020-06-23 09:34:29 +08:00
const int FRAME_RATE = 30;
const float FRAME_TIME = 1.f/(float)FRAME_RATE;
2020-07-01 09:01:52 +08:00
startLog("log.txt");
2020-06-12 09:46:44 +08:00
initGame();
2020-06-23 09:34:29 +08:00
float t = 0;
while (isRunning()) {
clock_t start_t = clock();
char ch = getch();
handleInput(ch);
drawGame();
drawLastPressed(ch);
drawCurPos();
refresh();
2020-06-24 11:05:49 +08:00
updateGame();
2020-06-12 09:46:44 +08:00
usleep(pow(10,6)*(FRAME_TIME-t));
2020-07-05 20:47:00 +08:00
t = (float) (clock()-start_t) / (float) CLOCKS_PER_SEC;
2020-06-12 09:46:44 +08:00
}
2020-06-27 08:21:47 +08:00
endGame();
2020-07-01 09:01:52 +08:00
endLog();
2020-06-12 09:46:44 +08:00
return 0;
}