本帖最后由 Living Things. 于 2018-3-20 16:46 编辑
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
int x=3,y=5;
const int fx[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
char a[50][50]={" ### ",
" #*# ",
"#####o######",
"#* os o *#",
"#######o####",
" # # ",
" #*# ",
" ### "};
void move(int v)
{
switch(a[x+fx[v][0]][y+fx[v][1]])
{
case 'o':
if(a[x+fx[v][0]*2][y+fx[v][1]*2]!='#')
{
a[x][y]=' ';
a[x+=fx[v][0]][y+=fx[v][1]]='s';
a[x+fx[v][0]][y+fx[v][1]]='o';
}
break;
case '#':
break;
case ' ':
a[x][y]=' ';
a[x+=fx[v][0]][y+=fx[v][1]]='s';
break;
default:
puts("Error");
getch();
exit(0);
}
}
int main()
{
int i;
while(a[1][5]=='*' || a[3][1]=='*' || a[3][9]=='*' || a[6][7]=='*')
{
for(i=0;i<8;i++)
puts(a);
switch(getch())
{
case 'W':case 'w':case '\110':
move(0);
break;
case 'S':case 's':case '\120':
move(1);
break;
case 'A':case 'a':case '\113':
move(2);
break;
case 'D':case 'd':case '\115':
move(3);
break;
}
system("cls");
}
for(i=0;i<8;i++)
puts(a);
puts("你赢了!");
system("pause > nul");
return 0;
} |