博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
c语言int speed=1,求大神帮忙看看这个弹弹球消砖块的游戏代码,为什么speed只能15...
阅读量:6903 次
发布时间:2019-06-27

本文共 2364 字,大约阅读时间需要 7 分钟。

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

#include

#include

#include

#include

int ball_x,ball_y;//定义小球的x,y坐标

int v_x,v_y;//定义小球的x,y的运动速度

int high=20;

int wideth=36;//定义画面大小

int banzi_x,banzi_y;

int banjing;

int left,right;//定义下面板子的各种参数

int score1=0;

int score2=0;//定义两个得分

int zhuankuai_x1,zhuankuai_y1;//定义砖块的位置

void HideCursor()

{

CONSOLE_CURSOR_INFO cursor_info = {1, 0};

SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);

}

void gotoxy(int x, int y)

{

HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);

COORD pos;

pos.X=x;

pos.Y=y;

SetConsoleCursorPosition(hOut, pos);

}

void initialization()//初始化各数据

{

ball_x = 0;

ball_y = wideth/2;//初始化小球的位置

v_x = 1;

v_y = 1;//初始化速度方向默认向右下角

zhuankuai_x1 = 0;

zhuankuai_y1 = 5;//初始化砖块位置

banzi_y = 13;

banzi_x = high-2;

banjing = 3;

left = banzi_y - banjing;

right = banzi_y + banjing;//板子位置

}

void show()//显示的位置;

{

int i,j;

gotoxy(0,0);//清屏函数

for(i=0;i<=high;i++)

{

for(j=0;j<=wideth;j++)

{

if((i == ball_x) && (j == ball_y))

printf("o");//输出小球

else if((i == zhuankuai_x1) && (j == zhuankuai_y1))

printf("B");//输出砖块

else if(j == wideth)

printf("|");//输出右边界

else if((i == banzi_x) && (j <= right) && (j >= left))

printf("*");//输出板子

else if(i == high)

printf("_");//输出下边界

else

printf(" ");

}

printf("\n");

}

printf("你的得分:%d\n",score1);

printf("你的弹数是:%d",score2/15);//输出两个得分

}

void updatenowithkeyboard()//键盘输入无关的参量

{

if((ball_x == banzi_x-1) && (ball_y <= right) && (left <= ball_y))

{

v_x = (-1) * v_x;

v_y = (-1) * v_y;

score2++;

}//小球弹到板子上时反弹,并且弹数得分增加

static int speed=0;

if(speed < 15)

speed++;

if(speed == 15)

{

ball_x = ball_x + v_x;

ball_y = ball_y + v_y;

speed=0;

}//定义一个静态变量,使小球的速度变慢,板子速度不受影响,但是不知道为什么数字只能设置为15,其他的小球都显示不了

if(ball_x == 0)

v_x = (-1) * v_x;

if((ball_y == 0) || (ball_y == wideth))

v_y = (-1) * v_y;//小球碰到上边界,左右边界时反弹

if((ball_x == zhuankuai_x1) && (ball_y == zhuankuai_y1))

{

zhuankuai_x1 = rand() % wideth;

score1++;

}//小球碰到砖块时,砖块随机任意位置生成一个,得分+1

if(ball_x > banzi_x)

{

printf("\nGAME OVER\n");

exit(0);//当小球落到板子下面时,游戏结束

}

}

void updatewithkeyboard()//键盘输入有关的参量

{

char input;

if(kbhit())

{

input = getch();

if(input == 'a')

banzi_y--;

if(input == 'd')

banzi_y++;

left = banzi_y - banjing;

right = banzi_y + banjing;

}//用a和d来控制板子的左右移动

}

int main()

{

HideCursor();

initialization();

while(1)

{

show();

updatewithkeyboard();

updatenowithkeyboard();

}

return 0;

}

详情在updatenowithkeyboard()这个函数中,为什么改变speed的值小球就不显示了

转载地址:http://hqodl.baihongyu.com/

你可能感兴趣的文章
HDU - 3966-Aragorn' Story(树链剖分+线段树)
查看>>
Linux基础第五章 进程控制
查看>>
[转载]孤儿进程与僵尸进程[总结]
查看>>
jquery事件机制扩展,jquery鼠标右键事件。
查看>>
windows phone Image checkbox
查看>>
[pycharm]远程调试服务器项目
查看>>
7 Java NIO Selector-翻译
查看>>
All Users in SharePoint Site Custom Webpart
查看>>
pip下载源更换为豆瓣源
查看>>
React Render props
查看>>
自动类型转换
查看>>
C# winfrom 当前程序内存读取和控制
查看>>
电话号码分身
查看>>
计算机专业术语
查看>>
Leetcode-探索 | 移动零
查看>>
DBI 数据库模块剖析:Perl DBI 数据库通讯模块规范,工作原理和实例
查看>>
Tesseract+opencv+VS+win实现OCR
查看>>
android在activity中锁屏解锁后重走OnCreate的问题的解决办法
查看>>
[学习笔记]博弈论
查看>>
python os sys模块(二)
查看>>