-
Notifications
You must be signed in to change notification settings - Fork 0
/
interactive.c
81 lines (72 loc) · 2.35 KB
/
interactive.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
#include"system.h"
#include"interactive.h"
static void PrintTab(WINDOW *win, int tabuleiro[][10]){
if(ps == NULL){
for(int i=0, x=55; i < 10; i++, x+=4){
for(int j=0, y=0; j < 10; j++, y++)
mvwprintw(win, y+2, x+2,(tabuleiro[j][i] == 0) ? " %d " : "%d ",tabuleiro[j][i]);
wprintw(win, "\n");
}
}
else{
Point *p = (Point *) malloc(sizeof(Point));
for(int i=0, x=55; i < 10; i++, x+=4){
for(int j=0, y=0; j < 10; j++, y++){
p->x = j;
p->y = i;
if(verifyPoint(p)){
wattron(win, COLOR_PAIR(1));
mvwprintw(win, y+2, x+2, " %d ",tabuleiro[j][i]);
wattroff(win,COLOR_PAIR(1));
}
else
mvwprintw(win, y+2, x+2,(tabuleiro[j][i] == 0) ? " %d " : "%d ",tabuleiro[j][i]);
usleep(50000);
wrefresh(win);
}
wprintw(win, "\n");
}
}
}
void searchPath(WINDOW *win, int tabuleiro[][10], int row, int col){
if(tabuleiro != NULL){
Point *p = NULL;
p = init(p);
for(; p->x < row; p->x++){
for(; p->y+1 < col; p->y++){
if(tabuleiro[p->x][p->y] == 0)
savePoint(p);
else{
p->y--;
if(verifyPoint(p)){
if(tabuleiro[p->x+1][p->y] == -1)
*p = loadPoint();
}
break;
}
}
if(p->y == col - 1 && tabuleiro[p->x][p->y] == 0){
if(tabuleiro[p->x+1][p->y] == 0)
savePoint(p);
else if(tabuleiro[p->x+1][p->y] == -1)
*p = loadPoint();
}
else if(p->y == col -1 && tabuleiro[p->x][p->y] == -1){
p->x--;
if(tabuleiro[p->x+1][p->y] == -1)
*p = loadPoint();
}
}
if(p->y < col){
p->x--;
while(p->y < col){
if(tabuleiro[p->x][p->y] == 0)
if(!verifyPoint(p))
savePoint(p);
p->y++;
}
}
}
wrefresh(win);
PrintTab(win, tabuleiro);
}