-
Notifications
You must be signed in to change notification settings - Fork 1
/
new_old_game.c
109 lines (91 loc) · 2.72 KB
/
new_old_game.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
#include <curses.h>
#include <unistd.h>
#include "types.h"
#include "car.h"
#define DELAY_DURATION 100
#define KEY_ESCAPE 27
/*void draw_border(Border old_border, Border new_border) {
for (int y = 0; y < SCREEN_HEIGHT; y++) {
move(y, old_border[y].left);
addch(' ');
move(y, new_border[y].left);
addch('#');
move(y, old_border[y].right);
addch(' ');
move(y, new_border[y]. right);
addch('#');
}
}*/
Action next_action() {
int key = getch();
if (key == KEY_ESCAPE) {
return ActionQuit;
}
if (key == KEY_UP) {
return ActionMoveUp;
}
if (key == KEY_DOWN) {
return ActionMoveDown;
}
if (key == KEY_LEFT) {
return ActionMoveLeft;
}
if (key == KEY_RIGHT) {
return ActionMoveRight;
}
return ActionNothing;
}
int main() {
Point car_position;
Border border;
int ord_x, ord_y;
Action action;
initscr(); /* вызвали библиотеку*/
curs_set(0); /* скрыть курсив клавиатуры */
cbreak(); /* введеный символ доступен сразу же после ввода */
keypad(stdscr, 1); /* обработка escape поседовательности */
noecho();
getmaxyx(stdscr, ord_y, ord_x);
border.min_x = 0;
border.max_x = ord_x;
border.min_y = 0;
border.max_y = ord_y;
car_position.x = ord_x/2;
car_position.y = ord_y/2;
move(car_position.y, car_position.x);
addch('*');
refresh();
while( (action = next_action()) != ActionQuit) {
Point old_position = car_position;
switch(action) {
case ActionMoveUp: {
car_position = get_next_car_position(car_position, MoveUp, border);
draw_car_at_point(old_position, car_position);
break;
}
case ActionMoveDown: {
car_position = get_next_car_position(car_position, MoveDown, border);
draw_car_at_point(old_position, car_position);
break;
}
case ActionMoveLeft: {
car_position = get_next_car_position(car_position, MoveLeft, border);
draw_car_at_point(old_position, car_position);
break;
}
case ActionMoveRight: {
car_position = get_next_car_position(car_position, MoveRight, border);
draw_car_at_point(old_position, car_position);
break;
}
default:
break;
}
/*Border old_border = border;
border = get_next_border(border ... );
draw_border(old_boder, border);*/
refresh();
}
endwin();
return 0;
}