#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
int main()
{
printf("推箱子游戏");
printf("wasd操作\n");
system("color 5a");
char a[50][50]={"##########",
"## ###",
"##O### #",
"# S O O #",
"# **# O ##",
"##**# ##",
"##########",
};
char ch;
int i,j,x,y,bb;
x=3;
y=2;
j=0;
bb=0;
for(i=0;i<=10;i++)
{
puts(a[i]);
}
while(1)
{
printf("已用步数%d",j);
ch=getch();
if (ch=='s')
{
if(a[x+1][y]=='O' && a[x+2][y]!='#' && a[x+2][y]!='O')
{
a[x][y]=' ';
x++;
a[x][y]='S';
a[x+1][y]='O';
j++;
}
if(a[x+1][y]==' ' )
{
a[x][y]=' ';
x++;
a[x][y]='S';
j++;
}
}
if (ch=='w')
{
if(a[x-1][y]=='O' && a[x-2][y]!='#' && a[x-2][y]!='O')
{
a[x][y]=' ';
x--;
a[x][y]='S';
a[x-1][y]='O';
j++;
}
if(a[x-1][y]==' ' )
{
a[x][y]=' ';
x--;
a[x][y]='S';
j++;
}
}
if (ch=='a')
{
if(a[x][y-1]=='O' && a[x][y-2]!='#' && a[x][y-2]!='O')
{
a[x][y]=' ';
y--;
a[x][y]='S';
a[x][y-1]='O';
j++;
}
if(a[x][y-1]==' ' )
{
a[x][y]=' ';
y--;
a[x][y]='S';
j++;
}
}
if (ch=='d')
{
if(a[x][y+1]=='O' && a[x][y+2]!='#' && a[x][y+2]!='O')
{
a[x][y]=' ';
y++;
a[x][y]='S';
a[x][y+1]='O';
j++;
}
if(a[x][y+1]==' ' )
{
a[x][y]=' ';
y++;
a[x][y]='S';
j++;
}
}
system("cls");
for(i=0;i<=10;i++)
puts(a[i]);
if(a[4][2]=='O' && a[4][3]=='O' && a[5][2]=='O' && a[5][3]=='O' )
{
printf("你赢了!马上进入下一关");
Sleep("2000");
break;
}
}
system("cls");
char b[50][50]={ "##### ",
"# # ",
"# O # ###",
"#SO # #*#",
"### ###*#",
" ## *#",
" # O # #",
" # ####",
" ##### ",
};
char c;
int v,w,n,m;
n=3;
m=1;
w=0;
for(v=0;v<=10;v++)
{
puts(b[v]);
}
while(b[3][7]=='O' && b[4][7]=='O' && b[5][7]=='O')
{
printf("已用步数%d",w);
c=getch();
if (c=='s')
{
if(b[n+1][m]=='O' && b[n+2][m]!='#' && b[n+2][m]!='O')
{
b[n][m]=' ';
n++;
b[n][m]='S';
b[n+1][m]='O';
w++;
}
if(b[n+1][m]==' ' )
{
b[n][m]=' ';
n++;
b[n][m]='S';
w++;
}
}
if (c=='w')
{
if(b[n-1][m]=='O' && b[n-2][m]!='#' && b[n-2][m]!='O')
{
b[n][m]=' ';
x--;
b[n][n]='S';
b[n-1][m]='O';
w++;
}
if(b[n-1][m]==' ' )
{
b[n][m]=' ';
n--;
b[n][m]='S';
w++;
}
}
if (c=='a')
{
if(b[n][m-1]=='O' && b[n][m-2]!='#' && b[n][m-2]!='O')
{
b[n][m]=' ';
m--;
b[n][m]='S';
b[n][m-1]='O';
w++;
}
if(b[n][m-1]==' ' )
{
b[n][m]=' ';
m--;
b[n][m]='S';
w++;
}
}
if (c=='d')
{
if(b[n][m+1]=='O' && b[n][m+2]!='#' && b[n][m+2]!='O')
{
b[n][m]=' ';
m++;
b[n][m]='S';
b[n][m+1]='O';
w++;
}
if(b[n][m+1]==' ' )
{
b[n][m]=' ';
m++;
b[n][m]='S';
w++;
}
}
system("cls");
for(v=0;v<=10;v++)
puts(b[v]);
}
printf("你赢了");
system("pause");
return 0;
}
|