-
Notifications
You must be signed in to change notification settings - Fork 1
/
lab1-4
97 lines (94 loc) · 1.67 KB
/
lab1-4
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
#include "stm32f769xx.h"
#include<stdlib.h>
#include<stdint.h>
#include "init.h"
int main(void)
{
Sys_Init();
//printf("\e[2J\e[H");
//fflush(stdout);
printf("\e[2J\e[1;1H");
fflush(stdout);
//printf("\e[44m \e[c\r\n");
//int wall[2][2];
//wall[0][0] = 0;
//wall[0][1] = 1;
//wall[1][0] = 0;
//wall[1][1] = 1;
//printf("%d %d %d %d\r\n",wall[0][0], wall[0][1], wall[1][0], wall[1][1]);
int wall[10][10];
int i=0;
int j=0;
for (i=0; i<10; i++)
{
for (j=0; j<10; j++)
{
if (i == 0 || i == 9 || j == 0 || j == 9 || j == 2 || j == 4 || j == 6)
wall[i][j] = 1;
else
wall[i][j] = 0;
}
}
wall[8][2] = 0;
wall[1][4] = 0;
wall[8][6] = 0;
wall[4][8] = 2;
for (i=0; i<10 ; i++)
{
for (j=0; j<10; j++)
{
if (j==9) //entering the nest line
printf("\e[44m \e[0m\r\n");
//printf("%d\r\n",wall[i][j]);
else //print out the wall
{
if(wall[i][j]==1)
{
printf("\e[44m \e[0m");
//printf("%d",wall[i][j]);
fflush(stdout);
}
else if (wall[i][j]==2) // the treasure place
{
printf("\e[41m \e[0m");
fflush(stdout);
}
else //the path
{
printf(" ");
fflush(stdout);
}
}
}
}
printf("\e[2;2H\e[30;43m*\e[0m");
fflush(stdout);
printf("\e[11;1H");
fflush(stdout);
char key;
key = getchar();
i=1;
j=1;
while(1)
{
if (key == 119 && wall[i-1][j] == 0)
i -= 1;
else if (key == 115 && wall[i+1][j] == 0 )
i += 1;
else if (key == 97 && wall[i][j-1] == 0)
j -=1;
else if (key == 100 && wall[i][j+1] == 0)
j +=1;
if ( wall[i][j] == 2)
{
//LD
}
//pushbutton function
//if()
}
//for (i=0; i<10; i++)
//{
//printf("%d",wall[0][i]);
//fflush(stdout);
//}
}