-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
71 lines (65 loc) · 1.48 KB
/
main.c
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "puzzleData.h"
#include "render.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char **argv) {
Direction inputDir;
int frameCounter = 0;
FILE *file;
if (argc > 1) {
file = fopen(argv[1], "r");
if (!file) {
fprintf(stderr, "could not open %s\n", argv[1]);
return 1;
}
} else {
fprintf(stderr, "Please provide a puzzlescript file\n");
return 1;
}
Runtime rt;
startGame(&rt, file);
initRenderer(rt.pd->title);
while (1) {
render(&rt);
frameCounter++;
if (rt.doAgain) {
if (rt.pd->againInterval * 60.0f < frameCounter) {
tick(&rt);
frameCounter = 0;
}
continue;
} else if (rt.pd->setRealtimeInterval && rt.pd->realTimeInterval > 0 &&
rt.pd->realTimeInterval * 60.0f < frameCounter) {
tick(&rt);
frameCounter = 0;
} else {
inputDir = handleInput(&rt, input());
if (inputDir != UNSPECIFIED) {
if (inputDir == QUIT) {
break;
}
if (inputDir == UNDO) {
if (rt.statesCount > 0) {
undo(&rt);
}
rt.didUndo = 0;
} else if (inputDir == NEXT_LEVEL) {
nextLevel(&rt);
} else {
update(&rt, inputDir);
if (rt.doAgain) {
frameCounter = 0;
}
}
if (rt.gameWon == 1) {
break;
}
}
}
}
printHistory(&rt);
closeRenderer();
endGame(&rt);
return 0;
}