-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnake_frontend.c
66 lines (59 loc) · 1.21 KB
/
snake_frontend.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
/*
* snake_frontend.c
*
* Created on: Jun 1, 2022
* Author: Piotr
*/
#include <string.h>
#include <stdlib.h>
#include "snake_backend.h"
#include "snake_frontend.h"
#include "lcd.h"
#include "input.h"
void display_points(PointList* points) {
while (points) {
lcd_draw_pixel(points->x, points->y);
points = points->next;
}
}
void display_end_screen() {
char buf[5];
char result[20] = "Wynik: ";
itoa(points, buf, 10);
HAL_Delay(600);
lcd_clear();
lcd_draw_text(2, 16, "Game over");
lcd_draw_text(3, 17, strcat(result, buf));
lcd_copy();
while (1) {
}
}
enum Direction get_next_move(enum Direction previous, int input_left,
int input_right) {
int input = get_input(input_left, input_right);
switch (input) {
case -1:
if (previous == UP)
return LEFT;
else if (previous == RIGHT)
return UP;
else if (previous == DOWN)
return RIGHT;
else if (previous == LEFT)
return DOWN;
break;
case 1:
if (previous == UP)
return RIGHT;
else if (previous == RIGHT)
return DOWN;
else if (previous == DOWN)
return LEFT;
else if (previous == LEFT)
return UP;
break;
default:
return previous;
}
return previous;
}