#include<iostream>
#include<cstdio>
#include<windows.h>
#include<conio.h>
using namespace std;
const int N=5,M=10;
char ma[N+5][M+5],ctl;
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()
{
for(int i=0;i<=N+1;i++)
{
ma[i][M+1]=ma[i][0]='#';
print(i,M+1),print(i,0);
}
for(int i=0;i<=M+1;i++)
{
ma[N+1][i]='#';
print(N+1,i);
}
}
class Wall
{
int x,y;
public:
Wall()
{
x=N,y=M/2;
ma[x][y]='_';
print(x,y);
}
void set(int p)
{
if(ma[x][y+p]=='#') return;
setma(' ',x,y);
y+=p;
setma('_',x,y);
}
}wall;/**/
class Ball
{
int x,y,dir;
int d[4][2]={
{
-1,1},{
-1,-1},{
1,1},{
1,-1}};
public:
Ball()
{
x=N-1,y=M/2;
dir=1;
setma('.',x,y);
}
void move()
{
int xx=x+d[dir][0],yy=y+d[dir][1];
if(yy>M||yy<1) dir^=1;
if(xx<0||xx>N) dir=(dir+2)%4;
if(ma[xx][y]=='*') dir^=1,setma(' ',xx,y);
if(ma[x][yy]=='*') dir=(2+dir)%4,setma(' ',x,yy);
if(ma[xx][yy]=='*') dir^=1,setma(' ',xx,yy);
setma(' ',x,y);
x+=d[dir][0],y+=d[dir][1];
setma('.',x,y);
}
}ball;
int main()
{
mkmap();
hdcs();
while(1)
{
ctl=getch();
if(ctl=='a') wall.set(-1);
if(ctl=='d') wall.set(1);
/*Sleep(100);
ball.move();*/
}
return 0;
}
打砖块(未完成)
猜你喜欢
转载自blog.csdn.net/weixin_45383207/article/details/111053048
今日推荐
周排行