游戏动过dos窗口不断刷新进行实现,画面比较丑陋。其实效果已经比那个赛车好多了,但是还是没有同学愿意去玩,很是伤心。游戏只涉及了三关,要是有同学喜欢的话留个评论,
马上更新欧,^0^。
#include "stdio.h"
#include "conio.h"
#include "stdlib.h"
#define M 30
#define N 39
char map[M][N]={0};
char finash[M][N]={0};
int finash_number[2];
int people[2]={0,0};
int out_put(int level)
{
int i,j;
printf("\t第%d关\n\t▓是箱子\n",level);
for(i=0;i<15;i++)
{
for(j=10;j<N;j++)
{
if(people[0]==i && people[1]==j)
printf("♀");
else
{
if(finash[i][j]=='-')
if(map[i][j]!='B')
printf("□");
else
{
printf("▓");
finash_number[1]++;
if(finash_number[0]==finash_number[1])
return 1;
}
else
if(map[i][j]=='S')
printf("■");
else
if(map[i][j]=='B')
printf("※");
else
printf("%c ",map[i][j]);
}
}
putchar('\n');
}
finash_number[1]=0;
return 0;
}
int moveable(char direction)
{
int i;
switch(direction-'0')
{
case 8:
if(map[people[0]-2][people[1]]==0 && map[people[0]-1][people[1]]!='S')
{
if(map[people[0]-1][people[1]]=='B')
return 2;
else
return 1;
}
if(map[people[0]-1][people[1]]==0)
{
return 1;
}
else
return 0;
break;
case 5:
if(map[people[0]+2][people[1]]==0 && map[people[0]+1][people[1]]!='S')
{
if(map[people[0]+1][people[1]]=='B')
return 2;
else
return 1;
}
if(map[people[0]+1][people[1]]==0)
{
return 1;
}
else
return 0;
break;
case 4:
if(map[people[0]][people[1]-2]==0 && map[people[0]][people[1]-1]!='S')
{
if(map[people[0]][people[1]-1]=='B')
return 2;
else
return 1;
}
if(map[people[0]][people[1]-1]==0)
{
return 1;
}
else
return 0;
break;
case 6:
if(map[people[0]][people[1]+2]==0 && map[people[0]][people[1]+1]!='S')
{
if(map[people[0]][people[1]+1]=='B')
return 2;
else
return 1;
}
if(map[people[0]][people[1]+1]==0)
{
return 1;
}
else
return 0;
break;
}
return 1;
}
int move(char direction,int level)
{
int way;
int i;
switch(direction-'0')
{
case 8:
if(way=moveable(direction))
{
people[0]--;
if(way==2)
{
map[people[0]][people[1]]=0;
map[people[0]-1][people[1]]='B';
}
}
break;
case 5:
if(way=moveable(direction))
{
people[0]++;
if(way==2)
{
map[people[0]][people[1]]=0;
map[people[0]+1][people[1]]='B';
}
}
break;
case 4:
if(way=moveable(direction))
{
people[1]--;
if(way==2)
{
map[people[0]][people[1]]=0;
map[people[0]][people[1]-1]='B';
}
}
break;
case 6:
if(way=moveable(direction))
{
people[1]++;
if(way==2)
{
map[people[0]][people[1]]=0;
map[people[0]][people[1]+1]='B';
}
}
break;
}
return 0;
}
int Game(int level)
{
char direction;
while(1)
{
system("CLS");
if(out_put(level))
return 0;
direction=getch();
if(direction=='a')
return 1;
move(direction,level);
}
return 0;
}
void Level(int level)
{
int i,j;
switch(level)
{
case 1:
for(i=0;i<M;i++)
for(j=0;j<N;j++)
map[i][j]=finash[i][j]=0;
finash_number[0]=finash_number[1]=0;
people[0]=people[1]=0;
for(i=10;i<18;i++)
map[0][i]='S';
for(i=0;i<7;i++)
map[i][10]=map[i][17]=map[i][14]='S';
map[3][14]=0;
for(i=14;i<18;i++)
map[7][i]='S';
for(i=10;i<15;i++)
map[6][i]='S';
map[2][12]=map[4][12]='S';
map[2][15]=map[3][15]=map[4][15]='B';
finash[2][16]=finash[3][16]=finash[4][16]='-';
people[0]=6;
people[1]=15;
finash_number[0]=3;
finash_number[1]=0;
break;
case 2:
for(i=0;i<M;i++)
for(j=0;j<N;j++)
map[i][j]=finash[i][j]=0;
finash_number[0]=finash_number[1]=0;
people[0]=people[1]=0;
for(i=12;i<=15;i++)
map[0][i]='S';
for(i=15;i<=19;i++)
map[1][i]='S';
map[1][12]='S';
map[2][10]=map[2][11]=map[2][12]=map[2][15]=map[2][19]='S';
map[3][10]=map[3][19]='S';
for(i=12;i<=19;i++)
map[4][i]='S';
map[4][10]='S';
map[5][10]=map[5][17]='S';
map[6][10]=map[6][11]=map[6][12]=map[6][17]='S';
map[7][12]=map[7][15]=map[7][16]=map[7][17]='S';
for(i=12;i<=15;i++)
map[8][i]='S';
people[0]=3;
people[1]=11;
map[3][14]=map[4][14]=map[5][14]='B';
finash[2][14]=finash[4][14]=finash[6][14]='-';
finash_number[0]=3;
finash_number[1]=0;
break;
case 3:
for(i=0;i<M;i++)
for(j=0;j<N;j++)
map[i][j]=finash[i][j]=0;
finash_number[0]=finash_number[1]=0;
people[0]=people[1]=0;
for(i=13;i<=16;i++)
map[0][i]='S';
for(i=10;i<=19;i++)
if(i!=14 && i!=15)
map[1][i]='S';
for(i=1;i<=5;i++)
map[i][10]=map[i][19]='S';
for(i=11;i<=15;i++)
map[5][i]='S';
for(i=5;i<=8;i++)
map[i][20]='S';
map[8][19]='S';
for(i=4;i<=9;i++)
map[i][15]='S';
for(i=15;i<=19;i++)
map[9][i]='S';
for(i=11;i<=17;i++)
if(i!=12)
finash[3][i]='-';
finash[4][17]=finash[5][17]=finash[6][17]='-';
for(i=12;i<=17;i++)
map[3][i]='B';
map[4][17]=map[5][17]=map[6][17]='B';
people[0]=4;
people[1]=14;
finash_number[0]=9;
finash_number[1]=0;
break;
}
}
int main(void)
{
system("color 4e");
int level;
char index;
for(level=1;level<200;level++)
{
Level(level);
if(Game(level))
level--;
if(level==4)
level=0;
}
return 0;
}
马上更新欧,^0^。