#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <time.h>
#define lie 70
#define hang 50
char map[lie][hang];
char feiji=15,zidan=4,dapao=6;
int dapaohang=hang-2,dapaolie=lie/2;
void cpmap();
void pmap();
int jiancha();
void main()
{
int ihang=hang,ilie=lie;
char anjian;
int ijiancha;
cpmap();
printf("请按任意键开始,请最大化\n");
getch();
system("cls");
map[dapaolie][dapaohang]=dapao;
while(1)
{
map[dapaolie][1]=feiji;
printf("w发射,a左移,d右移\n");
pmap();
ijiancha=jiancha();
if(ijiancha==0) goto loop;
if(_kbhit())
switch(anjian=getch())
{
case 'w':
map[dapaolie][dapaohang-1]=zidan;
system("cls");
continue;
case 'a':
map[dapaolie][dapaohang]=' ';
dapaolie=dapaolie-1;
map[dapaolie][dapaohang]=dapao;
system("cls");
continue;
case 'd':
map[dapaolie][dapaohang]=' ';
dapaolie=dapaolie+1;
map[dapaolie][dapaohang]=dapao;
system("cls");
continue;
}
system("cls");
}
loop:;
if(getch()!=27) goto loop;
}
void cpmap()
{
int ihang=hang,ilie=lie;
for (ihang=0;ihang<hang;ihang++)
{
for (ilie=0;ilie<lie;ilie++)
{
map[ilie][ihang]=' ';
}
}
for (ihang=0;ihang<hang;ihang++)
{
map[0][ihang]='*';
map[lie-1][ihang]='*';
}
for (ilie=0;ilie<lie;ilie++)
{
map[ilie][0]='*';
map[ilie][hang-1]='*';
}
for (ihang=0;ihang<hang;ihang++)
{
for(ilie=0;ilie<lie;ilie++)
{
printf("%c",map[ilie][ihang]);
}
printf("\n");
}
}
void pmap()
{
int ihang=hang,ilie=lie;
for (ihang=0;ihang<hang;ihang++)
{
for(ilie=0;ilie<lie;ilie++)
{
printf("%c",map[ilie][ihang]);
}
printf("\n");
}
}
int jiancha()
{
int ihang=hang,ilie=lie;
int n=0;
for (ihang=hang-1;ihang>=0;ihang--)
{
for(ilie=lie-1;ilie>=0;ilie--)
{
if(map[ilie][ihang]==feiji)
{
if(map[ilie][ihang+1]=='*'||map[ilie][ihang+1]==dapao)
{
printf("你输了!按esc退出\n");
return 0;
}
else if(map[ilie][ihang+1]==zidan)
{
map[ilie][ihang]=' ';
}
else
{
map[ilie][ihang]=' ';
map[ilie][ihang+1]=feiji;
}
}
}
}
for (ihang=0;ihang<hang;ihang++)
{
for(ilie=0;ilie<lie;ilie++)
{
if(map[ilie][ihang]==zidan)
{
if(map[ilie][ihang-1]=='*')
{
map[ilie][ihang]=' ';
}
else
{
map[ilie][ihang]=' ';
map[ilie][ihang-1]=zidan;
}
}
else if(map[ilie][ihang]==feiji)
{
if(map[ilie][ihang+1]=='*'||map[ilie][ihang+1]==dapao)
{
printf("你输了!按esc退出\n");
return 0;
}
}
}
}
return 1;
}
|