parent
1732aab4b4
commit
62f3ab7e76
@ -1,2 +1,277 @@
|
||||
# c
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <time.h>
|
||||
//#include <conio.h>
|
||||
#define CLS system("cls");
|
||||
#define R 7
|
||||
#define L 7
|
||||
#define AMOUNT 6
|
||||
|
||||
int ca=0,cb=0;
|
||||
bool end=0;
|
||||
int xlocation=0,ylocation=0,sum=0;
|
||||
char ifstart=0;
|
||||
char a[R][L]={0};
|
||||
char b[R][L]={0};
|
||||
char c[R+2][L+2]={0};
|
||||
|
||||
struct Block
|
||||
{
|
||||
bool changable;
|
||||
int value;
|
||||
};
|
||||
struct Block aa[R][L];
|
||||
|
||||
void initial();
|
||||
void game();
|
||||
void choose();
|
||||
int ifsure(int x);
|
||||
void ifbreakend();
|
||||
void ifwinend();
|
||||
void printsituation();//debug函数
|
||||
void printwhole();//打印棋盘
|
||||
|
||||
int main()
|
||||
{
|
||||
initial();
|
||||
choose();
|
||||
}
|
||||
|
||||
void choose()
|
||||
{
|
||||
printf("是否开始游戏\n1-开始\n2-退出\n");
|
||||
scanf("%d",&ifstart);
|
||||
switch(ifstart)
|
||||
{
|
||||
case 1 :
|
||||
printf("开始游戏\n");
|
||||
getchar();
|
||||
CLS
|
||||
game();
|
||||
break;
|
||||
case 2 :
|
||||
printf("成功退出\n");
|
||||
CLS
|
||||
break;
|
||||
default :
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void game()
|
||||
{
|
||||
initial();
|
||||
int ifx=0,ify=0;
|
||||
int i=0,j=0,leix=0,leiy=0,leia=0;
|
||||
bool jd=0,jx=1;
|
||||
printf("\n");
|
||||
while (1)
|
||||
{
|
||||
if(jx)
|
||||
{
|
||||
for(;i<R;i++)
|
||||
{
|
||||
for(;j<L;j++)
|
||||
{
|
||||
printf("?");
|
||||
}
|
||||
j=0;
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
printf("请选择坐标(先行后列)\n");
|
||||
scanf("%d %d",&i,&j);
|
||||
CLS
|
||||
xlocation=i-1;
|
||||
ylocation=j-1;
|
||||
ifx=ifsure(xlocation);
|
||||
ify=ifsure(ylocation);
|
||||
jd=(!(ifx||ify));
|
||||
if(jd)
|
||||
{
|
||||
a[xlocation][ylocation]=1;
|
||||
aa[xlocation][ylocation].changable=0;
|
||||
if(jx)
|
||||
{
|
||||
for(;leia<AMOUNT;leia++)//放置雷
|
||||
{
|
||||
srand(clock());
|
||||
leix=abs(((rand()+1)%(R+1))-1);
|
||||
leiy=abs(((rand()+1)%(L+1))-1);
|
||||
if(b[leix][leiy]==0&&a[leix][leiy]==0)
|
||||
{
|
||||
b[leix][leiy]=1;
|
||||
}
|
||||
else leia--;
|
||||
}
|
||||
jx=0;
|
||||
}
|
||||
printwhole();
|
||||
ifbreakend();
|
||||
if(end)
|
||||
{
|
||||
printf("你踩雷了!拜拜!\n(按任意键继续)");
|
||||
printsituation();
|
||||
getchar();
|
||||
choose();
|
||||
break;
|
||||
}
|
||||
ifwinend();
|
||||
if(end)
|
||||
{
|
||||
printf("恭喜获胜!\n(按任意键继续)");
|
||||
getchar();
|
||||
getchar();
|
||||
CLS
|
||||
choose();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int ifsure(int x)
|
||||
{
|
||||
if(x<0||x>R)
|
||||
{
|
||||
printf("位置不合法,请重新选择!\n");
|
||||
return 1;
|
||||
}
|
||||
else return 0;
|
||||
}
|
||||
|
||||
void ifbreakend()
|
||||
{
|
||||
int i1=0,j1=0;
|
||||
bool r1=0,r2=0;
|
||||
for(;i1<R;i1++)
|
||||
{
|
||||
for(;j1<L;j1++)
|
||||
{
|
||||
r1=a[i1][j1];
|
||||
r2=b[i1][j1];
|
||||
if (r1==r2&&r1==1)
|
||||
{
|
||||
end=1;
|
||||
}
|
||||
}
|
||||
j1=0;
|
||||
}
|
||||
}
|
||||
|
||||
void ifwinend()
|
||||
{
|
||||
int i2=0,j2=0,amo=0;
|
||||
bool r3=0,r4=0;
|
||||
for(;i2<R;i2++)
|
||||
{
|
||||
for(;j2<L;j2++)
|
||||
{
|
||||
r3=a[i2][j2];
|
||||
r4=b[i2][j2];
|
||||
if (r3!=r4)
|
||||
{
|
||||
amo++;
|
||||
}
|
||||
}
|
||||
j2=0;
|
||||
}
|
||||
if(amo==R*L)
|
||||
{
|
||||
end=1;
|
||||
}
|
||||
}
|
||||
|
||||
void printsituation()
|
||||
{
|
||||
int ii=0,ji=0;
|
||||
printf("\n");
|
||||
printf("a:\n");
|
||||
for(;ii<R;ii++)
|
||||
{
|
||||
for(;ji<L;ji++)
|
||||
{
|
||||
printf("%d",a[ii][ji]);
|
||||
}
|
||||
ji=0;
|
||||
printf("\n");
|
||||
}
|
||||
printf("\n");
|
||||
printf("b:\n");
|
||||
ii=0,ji=0;
|
||||
for(;ii<R;ii++)
|
||||
{
|
||||
for(;ji<L;ji++)
|
||||
{
|
||||
printf("%d",b[ii][ji]);
|
||||
}
|
||||
ji=0;
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
void printwhole()
|
||||
{
|
||||
int ip=0,jp=0,is=0,js=0;
|
||||
for(;is<R;is++)
|
||||
{
|
||||
for(;js<L;js++)
|
||||
{
|
||||
if(a[is][js])
|
||||
{
|
||||
for(;ip<R;ip++)
|
||||
{
|
||||
for(;jp<L;jp++)
|
||||
{
|
||||
c[ip+1][jp+1]=b[ip][jp];
|
||||
}
|
||||
jp=0;
|
||||
}
|
||||
ip=jp=0;
|
||||
sum=c[xlocation][ylocation]+c[xlocation][ylocation+1]+c[xlocation][ylocation+2]+c[xlocation+1][ylocation]+c[xlocation+1][ylocation+2]+c[xlocation+2][ylocation]+c[xlocation+2][ylocation+1]+c[xlocation+2][ylocation+2];
|
||||
if (!aa[xlocation][ylocation].changable)
|
||||
{
|
||||
aa[xlocation][ylocation].value=sum;
|
||||
}
|
||||
}
|
||||
if(((aa[is][js].value==0)&&(!aa[is][js].changable))||((aa[is][js].value!=0)&&(!aa[is][js].changable)))
|
||||
{
|
||||
printf("%d",aa[is][js].value);
|
||||
aa[is][js].changable=0;
|
||||
}
|
||||
else printf("?");
|
||||
}
|
||||
js=0;
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
void initial()
|
||||
{
|
||||
ca=cb=0;
|
||||
for(;ca<R;ca++)
|
||||
{
|
||||
for(;cb<L;cb++)
|
||||
{
|
||||
aa[ca][cb].changable=1;
|
||||
aa[ca][cb].value=0;
|
||||
a[ca][cb]=0;
|
||||
b[ca][cb]=0;
|
||||
}
|
||||
cb=0;
|
||||
}
|
||||
ca=cb=0;
|
||||
for(;ca<R+2;ca++)
|
||||
{
|
||||
for(;cb<L+2;cb++)
|
||||
{
|
||||
c[ca][cb]=0;
|
||||
}
|
||||
cb=0;
|
||||
}
|
||||
ca=cb=end=0;
|
||||
xlocation=0,ylocation=0,sum=0;
|
||||
ifstart=0;
|
||||
}
|
||||
|
||||
Loading…
Reference in new issue