自己编的打砖块 用c语言在vc6.0里 求大神指教怎么样才能使板子banz控制更灵活,由于ball在运动的时候板子控制貌似没用 求指点

jack521101 2012-09-14 12:44:27
#include<stdio.h>
#include<windows.h>
#include<conio.h>

void gotoxy(int x,int y)
{
COORD coord;
coord.X=x;
coord.Y=y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
}
int key_value()
{

if(GetKeyState(VK_UP)<0) return 1; //1表示按下上键
if(GetKeyState(VK_DOWN)<0) return 2; //2表示按下下键
if(GetKeyState(VK_LEFT)<0) return 3; //3表示按下左键
if(GetKeyState(VK_RIGHT)<0)return 4; //4表示按下右键
return 0;
}
struct BANZ
{
int x,y;
int vx,vy;
};
struct BALL
{
int x,y;
int vx,vy;
};
void delay()
{
int i,j;
for(i=10000;i>0;i--)
{
for(j=5000;j>0;j--);
}
}
void display()
{
gotoxy(0,0);
printf("*******************************************************\n");
printf("*#####################################################*\n");
printf("*#####################################################*\n");
printf("*#####################################################*\n");
printf("*#####################################################*\n");
printf("*#####################################################*\n");
printf("*#####################################################*\n");
printf("*#####################################################*\n");
printf("*#####################################################*\n");
printf("* *\n");
printf("* *\n");
printf("* *\n");
printf("* *\n");
printf("* *\n");
printf("* *\n");
printf("* *\n");
printf("* *\n");
printf("* ======== *\n");
printf("*******************************************************\n");

}



void ball_move(struct BALL *ball,struct BANZ *banz);

char rocks[][100]={"#####################################################",
"#####################################################",
"#####################################################",
"#####################################################",
"#####################################################",
"#####################################################",
"#####################################################",
"#####################################################"};
char wall[][100]={"*******************************************************",
"* *",
"* *",
"* *",
"* *",
"* *",
"* *",
"* *",
"* *",
"* *",
"* *",
"* *",
"* *",
"* *",
"* *",
"* *",
"* *",
"* *",
"*******************************************************"};
void main()
{
system("color B5");
int choice=key_value();

int i;

struct BALL ball={20,9,1,1};
struct BANZ banz={21,17,4,4};
display();
while(1)
{
for(i=0;i<10;i++)
{
choice=key_value();
switch(choice)
{
case 3:
delay();
if(banz.x>0)
{

gotoxy(banz.x,banz.y);
printf(" ");
banz.x-=banz.vx;
gotoxy(banz.x,banz.y);
printf("========");
}
break;
case 4:
delay();
if(banz.x<44)
{

gotoxy(banz.x,banz.y);
printf(" ");
banz.x+=banz.vx;
gotoxy(banz.x,banz.y);
printf("========");
}
break;
}

}
ball_move(&ball,&banz);




}




}
void ball_move(struct BALL *ball,struct BANZ *banz)
{

delay();
delay();



gotoxy(ball->x,ball->y);
printf(" ");
if(rocks[ball->y-1][ball->x]=='#'||rocks[ball->y+1][ball->x]=='#'||wall[ball->y-1][ball->x]=='*')
{
if(rocks[ball->y-1][ball->x]=='#')
{
gotoxy(ball->x,ball->y-1);
printf(" ");
}
if(rocks[ball->y+1][ball->x]=='#')
{
gotoxy(ball->x,ball->y+1);
printf(" ");
}
ball->vy=-ball->vy;
ball->x+=ball->vx;
ball->y+=ball->vy;
}
else if(rocks[ball->y][ball->x+1]=='#'||wall[ball->y][ball->x+1]=='*'||rocks[ball->y][ball->x-1]=='#'||wall[ball->y][ball->x-1]=='*')
{

if(rocks[ball->y][ball->x+1]=='#')
{
gotoxy(ball->x+1,ball->y);
printf(" ");
}
else if(rocks[ball->y][ball->x-1]=='#')
{
gotoxy(ball->x-1,ball->y);
printf(" ");
}
ball->vx=-ball->vx;
ball->x+=ball->vx;
ball->y+=ball->vy;
}
else if(wall[ball->y+1][ball->x]=='*')
{
system("cls");
gotoxy(23,5);
printf("GAME OVER!!!");
}
else if((banz->y-1)==(ball->y)&&(ball->x)>=(banz->x)&&(ball->x)<=(banz->x+7))
{
ball->vy=-ball->vy;
ball->x+=ball->vx;
ball->y+=ball->vy;
}

else
{
ball->x+=ball->vx;
ball->y+=ball->vy;
}
gotoxy(ball->x,ball->y);
printf("@");

}





...全文
100 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2012-09-14
  • 打赏
  • 举报
回复

70,023

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧