-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtiny.c
94 lines (88 loc) · 1.54 KB
/
tiny.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
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <assert.h>
#include <stdbool.h>
#define H 4
#define W 6
#define ITERS 512
char maze[H][W] = { "+-+-+",
"| |#|",
"| |",
"+---+" };
void draw ()
{
int i, j;
for (i = 0; i < H; i++)
{
for (j = 0; j < W; j++)
printf ("%c", maze[i][j]);
printf ("\n");
}
printf ("\n");
}
int
main (int argc, char *argv[])
{
int x, y; //Player position
int ox, oy; //Old player position
int i = 0; //Iteration number
char program[ITERS];
x = 1;
y = 1;
maze[y][x]='X';
draw();
read(0,program,ITERS);
while(i < ITERS)
{
#ifndef MAZE_NO_BT
maze[y][x]=' ';
#endif
ox = x; //Save old player position
oy = y;
//transition(hashint(x,y));
//IJON_SET(ijon_hashint(x,y));
switch (program[i])
{
case 'w':
y--;
break;
case 's':
y++;
break;
case 'a':
x--;
break;
case 'd':
x++;
break;
default:
printf("Wrong command!(only w,s,a,d accepted!)\n");
printf("You lose!\n");
exit(-1);
}
if (maze[y][x] == '#')
{
char sys_show[ITERS + 100];
strcpy(sys_show,"gnome-terminal --geometry=80x40+70+30 --command \"./maze_show ");
strcat(sys_show,program);
strcat(sys_show," \"");
system(sys_show);
assert(0);
}
if (maze[y][x] != ' ') {
x = ox;
y = oy;
}
#ifdef MAZE_NO_BT
if (ox==x && oy==y){
printf("You lose\n");
exit(-2);
}
#endif
maze[y][x]='X';
draw (); //draw it
i++;
}
printf("You lose\n");
}