-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibonefunc.cpp
More file actions
77 lines (68 loc) · 1.48 KB
/
Copy pathlibonefunc.cpp
File metadata and controls
77 lines (68 loc) · 1.48 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "libone.hh"
WINDOW *window_create(int height, int width)
{
WINDOW *my_win;
my_win = newwin(height, width, 0,0);
box(my_win, 0 , 0);
wrefresh(my_win);
return (my_win);
}
void Libone::food(WINDOW *my_win)
{
int randx;
int randy;
int i;
randx = rand()%user_x - 5;
randy = rand()%user_y - 5;
foods.x = randx;
foods.y = randy;
wmove(my_win, foods.y, foods.x);
waddch(my_win,'*');
eat(my_win);
wrefresh(my_win);
}
void Libone::eat(WINDOW *my_win)
{
limit(my_win);
if (my_snake[0].pos_x == foods.x && my_snake[0].pos_y == foods.y)
{
food(my_win);
results += 10;
my_snake.insert(my_snake.end(), snakebody(my_snake[0].pos_x+1, my_snake[0].pos_y+1));
move(user_x / 2, user_y + 1);
printw("Votre score : %d", results);
refresh();
}
}
void Libone::view_snake(WINDOW *my_win)
{
int i = 0;
while (i < my_snake.size())
{
wmove(my_win, my_snake[i].pos_y,my_snake[i].pos_x);
waddch(my_win, 'x');
i++;
}
wrefresh(my_win);
}
void Libone::start()
{
WINDOW *my_win;
int i = 0;
const char *str = "Loading ...";
my_win = window_create(gety, getx);
wmove(my_win, gety / 2, getx / 2);
wprintw(my_win, "%s", str);
wrefresh(my_win);
sleep(2);
wmove(my_win, gety / 2, getx / 2);
while (str[i] != '\0')
{
waddch(my_win, ' ');
wrefresh(my_win);
i++;
}
wborder(my_win, ' ', ' ', ' ',' ',' ',' ',' ',' ');
wrefresh(my_win);
delwin(my_win);
}