ncurses-gameoflife/main.c

49 lines
695 B
C
Raw Permalink 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-07-10 06:58:17 +08:00
#include "ui.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-06-12 09:46:44 +08:00
2020-07-10 06:58:17 +08:00
startLog("log.txt");
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();
2020-07-10 06:58:17 +08:00
//drawLastPressed(ch);
drawCurPos();
2020-07-10 06:58:17 +08:00
drawUI();
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-07-10 06:58:17 +08:00
endUI();
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;
}