#include<iostream>
#include<cstdio>
#include<windows.h>
#include<conio.h>
#include<ctime>
using namespace std;
const int N=11,M=24;
char ma[N+5][M+5],ctl;
int poi,flag;
void hdcs()
{
CONSOLE_CURSOR_INFO info={
1,0};
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&info);
}
void print(int x,int y)
{
COORD pos;
pos.X=y;
pos.Y=x;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
putchar(ma[x][y]);
}
void setma(char c,int x,int y)
{
ma[x][y]=c;
print(x,y);
}
void mkmap(int b)
{
for(int i=0;i<=N+1;i++)
setma('#',i,M+1),setma('#',i,0);
for(int i=0;i<=M+1;i++)
setma('#',0,i);
while(b)
{
int x=rand()%(N/3)+1,y=rand()%M+1;
while(ma[x][y]=='*')
x=rand()%(N/3)+1,y=rand()%M+1;
setma('*',x,y);
b--;
}
}
class Wall
{
public:
int x,y;
const int si=3;
Wall()
{
x=N,y=M/2;
set(y);
}
void set(int y)
{
for(int i=max(0,y-si);i<=min(M,y+si);i++)
setma('-',x,i);
}
void move(int p)
{
if(y+p-si<1||y+p+si>M) return;
setma(' ',x,y-si*p);
set(y+p);
y+=p;
}
}wall;
class Ball
{
int x,y,dir,ti;
int d[4][2]={
{
-1,1},{
-1,-1},{
1,1},{
1,-1}};
public:
Ball(int p)
{
x=N-1,y=p;
dir=ti=0;
setma('.',x,y);
}
void move()
{
ti^=1;
if(ti) return;
int xx=x+d[dir][0],yy=y+d[dir][1];
if(xx>N)
{
flag=1;
return;
}
if(yy>M||yy<1) dir^=1;
if(xx<1||ma[xx][yy]=='-'||ma[xx][y]=='-') dir=(dir+2)%4;
if(ma[xx][yy]=='*') dir=3-dir,setma(' ',xx,yy),poi++;
else
{
if(ma[xx][y]=='*') dir=(2+dir)%4,setma(' ',xx,y),poi++;
if(ma[x][yy]=='*') dir^=1,setma(' ',x,yy),poi++;
}
setma(' ',x,y);
x+=d[dir][0],y+=d[dir][1];
setma('.',x,y);
}
};
int main()
{
hdcs();
srand(time(0));
int b=rand()%7+8;
mkmap(b);
while(ctl!=13)
{
setma('.',wall.x-1,wall.y);
ctl=getch();
setma(' ',wall.x-1,wall.y);
if(ctl=='a') wall.move(-1);
if(ctl=='d') wall.move(1);
setma('.',wall.x-1,wall.y);
}
Ball ball(wall.y);
while(!flag)
{
Sleep(30);
ball.move();
if(poi>=b) flag=2;
if(!kbhit()) continue;
ctl=getch();
if(ctl=='a') wall.move(-1);
if(ctl=='d') wall.move(1);
}
system("cls");
if(flag==1)
printf("Your point is %d",poi);
else
printf("You win!!!");
return 0;
}
打砖块(终极版。吧)
猜你喜欢
转载自blog.csdn.net/weixin_45383207/article/details/111389844
今日推荐
周排行