#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<windows.h>
#include<time.h>
#include<math.h>
#define sqr(x) x*x
int i,j,x,y,d,k,f,stx,sty,score,e,l,w,h;
char s[21][21];
int a[21][21];
int hard[13]={1,2,5,10,15,20,30,45,60,80,100};
void find()
{
for(int q=1;q<=20;q++)
for(int r=1;r<=20;r++)
if(a[q][r]==e)
{
s[q][r]=' ';
return;
}
}
int yd()
{
if(w=='H'&&k=='P')return 0;
if(w=='P'&&k=='H')return 0;
if(w=='M'&&k=='K')return 0;
if(w=='K'&&k=='M')return 0;
if(w=='K')return 1;
if(w=='P')return 1;
if(w=='H')return 1;
if(w=='M')return 1;
return 0;
}
int main()
{
for(i=1;i<=20;i++)
for(j=1;j<=20;j++)
s[i][j]=' ';
s[9][10]=1;s[10][10]=1;s[11][10]=1;
for(i=9;i<=11;i++)
{
a[i][10]=i-8;
}
stx=11;
sty=10;
e=1;
srand(time(0));
z:;
x=rand()%20+1;
y=rand()%20+1;
while(s[x][y]!=' ')
{
x=rand()%20+1;
y=rand()%20+1;
}
s[x][y]='*';
l=3;
for(i=1;i<=20;i++)
{
s[i][1]=2;
s[1][i]=2;
s[20][i]=2;
s[i][20]=2;
}
w='P';
h=12;
while(!d)
{
system("cls");
for(;kbhit();)w=getch();
if(w!=0&&yd())k=w;
if(k=='H')stx--;
if(k=='M')sty++;
if(k=='P')stx++;
if(k=='K')sty--;
if(s[stx][sty]=='*')
{
score++;
while(s[x][y]!=' ')
{
x=rand()%20+1;
y=rand()%20+1;
}
s[x][y]='*';
l++;
s[stx][sty]=1;
a[stx][sty]=l;
}
else
if(s[stx][sty]!=' ')
{
for(i=1;i<=20;i++)
{
for(j=1;j<=20;j++)
putchar(s[i][j]);
puts("");
}
printf("Game over!\nscore:%d\nhard:%d",score,13-h);
getch();
getch();
return 0;;
}
else
{
l++;
s[stx][sty]=1;
a[stx][sty]=l;
find();
e++;
}
for(i=1;i<=20;i++)
{
for(j=1;j<=20;j++)
printf("%c",s[i][j]);
puts("");
}
printf("score:%d",score,13-h);
printf("\nhard:%d",13-h);
if(score>=hard[13-h])h--;
Sleep(h*sqr((int)sqrt(h))*3);
}
return 0;
}
c++小游戏之贪吃蛇
最新推荐文章于 2023-12-03 21:36:00 发布