想用C / C ++移动球
it1352
帮助1人
问题说明
#include<graphics.h>
#include<conio.h>
#include<alloc.h>
#include<dos.h>
#include<stdlib.h>
void *ball;
void image()
{
setcolor(RED);
setfillstyle(SOLID_FILL,RED);
fillellipse(10,10,10,10);
ball=malloc(imagesize(0,0,20,20));
getimage(0,0,20,20,ball);
cleardevice();
}
void main(void)
{
int gmode,gdriver=DETECT;
initgraph(&gdriver,&gmode,"c:\\tc\\bgi");
int l=getmaxx()/2,r=0,t=0,b=0;
int x=1,y=1;
int s=0,key=0;
int xstep=1,ystep=1;
image();
setbkcolor(GREEN);
while(key!=27)
{
while(!kbhit())
{
outtextxy(250,350,"");
setcolor(7);
putimage(l,t,ball,XOR_PUT);
delay(5);
putimage(l,t,ball,XOR_PUT);
if(l>=getmaxx()||l<=0)
{
x*=-1;sound(1000);
s=0;xstep=x*(random(4) 1);
ystep=y*(random(3) 1);
if(l<=0)
l=0;
else
l=getmaxx();
}
if(t>=getmaxy()||t<=0)
{
y*=-1;sound(1000);
s=0;ystep=y*(random(4) 1);
xstep=x*(random(3) 1);
if(t<=0)
t=0;
else
t=getmaxy();
}
l =x xstep;
t =y ystep;
s ;
if(s==5)
{
nosound();
}
}
key=getch();
}
closegraph();
}
这个球随机移动,但我想把这个球向左(中),右(中),向上(中),向下移动(中心)像钻石<>
This ball moves randomly, but I would like to move this ball just left(center), right(center), up(center), down(center) like diamond <>
正确答案
#1
这不是问题。你使用随机
,然后抱怨球随机移动。这没有道理。 Obvious上尉说:如果你想以某种方式移动它,就这样移动它。 :-)
-SA
This is not a question. You userandom
and then complain that the ball moves randomly. It makes no sense. Captain Obvious says: if you want to move it in certain way, move it in this way. :-)
—SA
您可以使用第一个随机数来决定哪个您要移动的轴。然后根据第一个数字,执行水平或垂直移动。
You might use a first random number to decide along which axis you want to move. Then according to that first number, you execute either the horizontal or the vertical move.
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /reply/detail/tanhcfiahg
系列文章
更多
同类精品
更多
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
检查邮件是否发送成功
it1352 07-25 -
Android微调工具-删除当前选择
it1352 06-20 -
希伯来语的空格句子标记化错误
it1352 06-22 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20