-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
39 lines (35 loc) · 938 Bytes
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Created by Srijita Mallick on 18/10/20.
#include <chrono>
#include "constants.h"
#include "ui.h"
#include "game.h"
#include "food.h"
using namespace std;
int key = ERR;
// Moves the game ahead by the specifying time here
void EventLoop() {
auto last_time = chrono::system_clock::now();
auto current_time = chrono::system_clock::now();
int delta_t;
while(true) {
current_time = chrono::system_clock::now();
delta_t = chrono::duration_cast<chrono::milliseconds>(
current_time - last_time
).count(); // count the number of units that have passed
if(delta_t > TICK_INTERVAL) {
int k = getch();
if (k != ERR) {
key = k;
}
tick(key);
refresh();
last_time = current_time;
}
}
}
int main() {
InitUi();
EventLoop();
TearDownUi();
return 0;
}