-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
132 lines (128 loc) · 2.13 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include "interpreter.h"
#include <stdlib.h>
#include <stdio.h>
#include "robot.h"
#include "map.h"
#include "commands.h"
#include <time.h>
#include "display.h"
#include <ncurses.h>
#define TIMEOUT 100
int main()
{
initDisplay();
int delay = 5;
setDelay(delay);
WINDOW *mainWin;
WINDOW *statsWin;
int winSizeX;
int winSizeY;
getmaxyx(stdscr, winSizeY, winSizeX);
map *curMap = initMapfromCF("map.cfg");
if(curMap->sizeY<winSizeY)
{
winSizeY = curMap->sizeY;
}
if(curMap->sizeX<winSizeX - 15)
{
winSizeX = curMap->sizeX - 15;
}
else
{
winSizeX -= 15;
}
mainWin = initWindow(winSizeY, winSizeX, 0, 0);
statsWin = initWindow(winSizeY, 15, 0, winSizeX + 1);
robot *list[ROBOTSLIMIT];
for(int i = 0; i<ROBOTSLIMIT; i++)
{
list[i] = calloc(1, sizeof(robot));
}
initBases(curMap, list);
int scrCount[2]= {0, 0};
script **test[2];
makeTeamScripts("scrRed", true, test, scrCount);
makeTeamScripts("scrGreen", false, test, scrCount);
int input=0;
int px=0, py=0;
int state = 0;
int i=0;
while(!state)
{
input = getch();
switch(input)
{
case KEY_LEFT:
if(px > 0)
{
px--;
}
break;
case KEY_RIGHT:
if(px+winSizeX<curMap->sizeX)
{
px++;
}
break;
case KEY_UP:
if(py > 0)
{
py--;
}
break;
case KEY_DOWN:
if(py+winSizeY<curMap->sizeY)
{
py++;
}
break;
case 'k':
if(delay > 1)
{
delay--;
setDelay(delay);
}
break;
case 'l':
delay++;
setDelay(delay);
break;
case 'q':
state = 3;
break;
case 's':
while((state = tickRobots(test, list, curMap))==0 && i!=TIMEOUT)
{
i++;
}
i = 0;
break;
default:
state = tickRobots(test, list, curMap);
break;
}
printMap(curMap, list, mainWin, px, py, winSizeX, winSizeY, statsWin);
}
freeMap(curMap);
freeBook(test, scrCount);
for(int i = 0; i<ROBOTSLIMIT; i++)
{
free(list[i]->path);
free(list[i]);
}
delWindow(statsWin);
delWindow(mainWin);
endDisplay();
if(state == 1)
{
printf("\ngreen won\n");
}
if(state == 2)
{
printf("\nred won\n");
}
if(state == 3)
{
printf("\nquited before end\n");
}
}