-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cpp
More file actions
55 lines (45 loc) · 1.05 KB
/
Main.cpp
File metadata and controls
55 lines (45 loc) · 1.05 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//
// Created by Ugnius on 4/22/2019.
//
#include <ctype.h>
#include <unistd.h>
#include <signal.h>
#include <errno.h>
#include <wiringPi.h>
#include <string.h>
#include "display/Display.h"
#include "snake/SSnake.h"
volatile sig_atomic_t interrupted = 0;
void sigintHandler(int sig) {
interrupted = 1;
}
void init() {
struct sigaction sigint_sa;
sigint_sa.sa_handler = sigintHandler;
sigemptyset(&sigint_sa.sa_mask);
sigint_sa.sa_flags = SA_RESTART;
if (sigaction(SIGINT, &sigint_sa, NULL) < 0) {
fprintf(stderr, "sigaction error: %s\n", strerror(errno));
exit(0);
}
}
int main() {
init();
SSnake s;
Display& d = Display::get();
d.startController([&](char in) {
if (isdigit(in)) {
int in_ = in - '0';
s.changeDirection((direction)in_);
}
});
d.startDisplay();
while (!interrupted && s.getGameRunning()) {
delay(400);
s.move();
s.loadToDisplay(d);
d.update();
}
int score = s.getScore();
// HTTP REQUEST TODO
}