->CHO
daiwancheng
#include <bits/stdc++.h>
#include <conio.h>
using namespace std;
bool outt[20][20],los=0,vis[20][20];
int mapp[20][20],cur1,cur2,t,res=15;
char g;
void pr()
{
printf("-----\n");
system("cls");
for(int i=1;i<=15;i++)
{
for(int j=1;j<=15;j++)
{
if(i==cur1&&j==cur2)printf("! ");
else if(outt[i][j]==0)printf("# ");
else if(mapp[i][j]==10)printf("L ");
else printf("%d ",mapp[i][j]);
}
printf("\n");
}
return;
}
void lexplore(int x,int y,int fir)
{
if(los==1)return;
if(outt[x][y]==1)return;
if(fir==1&&mapp[x][y]==-1){los=1;return;}
if(fir==0&&mapp[x][y]==-1)return;
if(x>15||y>15||x<1||y<1)return;
outt[x][y]=1;
if(mapp[x][y]==0){
for(int k=-1;k<=1;k++)
for(int l=-1;l<=1;l++)
lexplore(x+k,y+l,0);
}
return;
}
void rexlplore(int x,int y)
{
if(mapp[i][j]==10){
t=0;
for(int k=-1;k<=1;k++)
for(int l=-1;l<=1;l++)
if(mapp[x+k][y+l]==-1)t++;
mapp[i][j]=t;
return;
}
if(outt[x][y]==0){
mapp[i][j]=10;
res--;
return;
}
if(outt[x]==1){
t=0;
for(int k=-1;k<=1;k++)
for(int l=-1;l<=1;l++)
{
if(k==0&&l==0)continue;
if(mapp[x+k][y+l]==10&&)t++;
}
}
}
int main()
{
srand(time(0));
for(int i=0;i<15;i++)
{
do{
cur1=rand()%15+1;
cur2=rand()%15+1;
}while(mapp[cur1][cur2]==-1);
mapp[cur1][cur2]=-1;
}
for(int i=1;i<=15;i++)
for(int j=1;j<=15;j++)
{
if(mapp[i][j]==-1)continue;
cur1=0;
for(int k=-1;k<=1;k++)
for(int l=-1;l<=1;l++)
if(mapp[i+k][j+l]==-1)cur1++;
mapp[i][j]=cur1;
}
cur1=cur2=1;
while(los==0||res>0){
pr();
do{
g=getch();
}while(!(g=='w'||g=='a'||g=='s'||g=='d'||g=='k'||g=='l'));
switch(g){
case 'w':{cur1--;break;}
case 'a':{cur2--;break;}
case 's':{cur1++;break;}
case 'd':{cur2++;break;}
case 'k':{lexplore(cur1,cur2,1);break;}
}
if(cur1<1)cur1=1;
if(cur2<1)cur2=1;
if(cur1>15)cur1=15;
if(cur2>15)cur2=15;
}
if(los==1)printf("%d %d %d LOSS!",cur1,cur2,mapp[cur1][cur2]);
return 0;
}