| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 594 人关注过本帖
标题:[求助]关于“火箭发射”这个程序的修改问题
只看楼主 加入收藏
cjls1
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2006-6-25
收藏
 问题点数:0 回复次数:8 
[求助]关于“火箭发射”这个程序的修改问题
在网上能找到火箭发射的这个程序,如下:
#include<graphics.h>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#include<alloc.h>

#define ESC 0x1b /*ESC的ASCII码,十六进制*/

void DrawGun(void); /*画发射架函数的说明语句*/
void DrawPlan(void); /*画飞机函数的说明语句*/
void DrawStar(void); /*画星函数的说明语句*/

void *buf; /*全局变量,用于存储飞机的图像*/
int x0=300; /*以下是飞机的位置初始化参数*/
int y0=340;
int width1=5;
int width2=20;
int height=25;
int y1=8;
int y2=15;
int y3=23;
int y4=38;

/*主函数开始*/
main()
{
int size;
int i=0;
int key;
int station;
int grdriver=DETECT;
int grmode;

initgraph(&grdriver,&grmode,"");
setbkcolor(BLACK);
cleardevice();/*图形驱动程序和屏幕初始化工作完成*/

setcolor(BLUE);/*设置字的颜色*/
settextstyle(TRIPLEX_FONT,0,4);/*设置字体*/
outtextxy(80,100,"Ready!...Any key to SET OFF !!!");
DrawGun(); /*画出发射架*/
getch(); /*if press key,clear the words and start*/

cleardevice();
DrawGun();
DrawPlan();
DrawStar();
setcolor(LIGHTRED);/*define result words color*/

do{ /*程序主循环开始,用于运动飞机,方法是用异或的方式在屏幕上连续画出飞机的图像,每画一次,新图像和来的位置相差两个像素点。这个值是可调的,值越大,飞机飞行的速度越快*/

putimage(x0-width2,y0-height-3*width1-i,buf,XOR_PUT);
i+=2;
putimage(x0-width2,y0-height-3*width1-i,buf,XOR_PUT);

key=getch();
if(y0-height-3*width1-i==0)
outtextxy(60,100,"Successfully!!! Press ESC to quit");
if(key==ESC){
if(y0-height-3*width1-i>0){
cleardevice();
outtextxy(100,100,"Failue. What did you do?");
outtextxy(130,300,"Press any key to quit.");
getch();
}
}

}while(key!=ESC);

free(buf);
closegraph();
return 0;

}


/************************Draw the star ********************************/

void DrawStar(void)
{

int i,dotx,doty,height,width,color,maxcolor;

maxcolor=getmaxcolor();
width=getmaxx();
height=getmaxy();


for(i=0;i<250;i++){
dotx=i+random(width-1);
doty=i+random(height-1);
color=random(maxcolor);

setcolor(color);
putpixel(dotx,doty,color);
circle(dotx+1,doty+1,1);

}
}
/****************Draw the bottom gun********************/
void DrawGun(void)
{
int x0=300;
int y0=430;
int height=45;
int rx=20;
int ry=5;
int rightx,righty,leftx,lefty;
int centery1=30;
rightx=righty=leftx=lefty=12;


setcolor(LIGHTGREEN);
ellipse(x0,y0,180,360,rx,ry);
ellipse(x0,y0-height,0,360,rx,ry);
line(x0+rx,y0,x0+rx,y0-height);
line(x0-rx,y0,x0-rx,y0-height);

moveto(x0+rx,y0);
lineto(x0+rx+rightx,y0+righty);
moveto(x0+rx+rightx,y0+righty);
lineto(x0+rx+rightx+10,y0+righty+10);
circle(x0+rx+rightx+10,y0+righty+10,4);


moveto(x0,y0+ry);
lineto(x0,y0+centery1);
moveto(x0,y0+centery1);
lineto(x0,y0+centery1+10);
circle(x0,y0+centery1+10,4);


moveto(x0-rx,y0);
lineto(x0-rx-leftx,y0+lefty);
moveto(x0-rx-leftx,y0+lefty);
lineto(x0-rx-leftx-10,y0+lefty+10);
circle(x0-rx-leftx-10,y0+lefty+10,4);

line(x0-rx-leftx,y0+lefty,x0,y0+centery1);
line(x0,y0+centery1,x0+rx+rightx,y0+righty);
}
/*****************Draw the plan fly to the sky***********************/
void DrawPlan(void)
{


int size;

setcolor(LIGHTRED);
ellipse(x0,y0-height,0,180,width1,3*width1);

moveto(x0+width1,y0); /*moveto center right side*/
lineto(x0+width1,y0-height);
moveto(x0+width1,y0);
lineto(x0+width2,y0+y2);

moveto(x0-width1,y0); /*moveto center left side*/
lineto(x0-width1,y0-height);
moveto(x0-width1,y0);
lineto(x0-width2,y0+y2);

moveto(x0+width2,y0+y3);/*moveto right bottom side*/
lineto(x0+width2,y0+y1);
moveto(x0+width2,y0+y3);
lineto(x0+width1,y0+y2);

moveto(x0-width2,y0+y3);/*moveto left bottom side*/
lineto(x0-width2,y0+y1);
moveto(x0-width2,y0+y3);
lineto(x0-width1,y0+y2);

moveto(x0,y0+y4); /*moveto the bottomest*/
lineto(x0+width1,y0+y2);
moveto(x0,y0+y4);
lineto(x0-width1,y0+y2);

setfillstyle(2,LIGHTRED); /*fill the plan with a style */
floodfill(x0,y0,LIGHTRED);

size=imagesize(x0-width2-1,y0-height-3*width1,
x0+width2+1,y0+y4);
buf=
malloc(size);
if(!buf){
printf("No enough memory!");
exit(0);
}
getimage(x0-width2,y0-height-3*width1,x0+width2,y0+y4,buf);

}



其中我用红字标出来的那段段,如何修改为按一下键后,火箭就会自动上升,而按ESC键就能退出?(原本是要手动按键,火箭才能上升)
我试着去掉了里面的getch()(我用蓝色标记出了),可是按ESC却无法退出。
望大侠指教~
搜索更多相关主题的帖子: 火箭发射 
2006-06-25 15:04
SunShining
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:31
帖 子:2215
专家分:0
注 册:2006-2-17
收藏
得分:0 
以下是引用cjls1在2006-6-25 15:04:10的发言:
在网上能找到火箭发射的这个程序,如下:

/*主函数开始*/
main()
{
int size;
int i=0;
int key=-2;
int station;
int grdriver=DETECT;
int grmode;

initgraph(&grdriver,&grmode,"");
setbkcolor(BLACK);
cleardevice();/*图形驱动程序和屏幕初始化工作完成*/

setcolor(BLUE);/*设置字的颜色*/
settextstyle(TRIPLEX_FONT,0,4);/*设置字体*/
outtextxy(80,100,"Ready!...Any key to SET OFF !!!");
DrawGun(); /*画出发射架*/
getch(); /*if press key,clear the words and start*/

cleardevice();
DrawGun();
DrawPlan();
DrawStar();
setcolor(LIGHTRED);/*define result words color*/

do{ /*程序主循环开始,用于运动飞机,方法是用异或的方式在屏幕上连续画出飞机的图像,每画一次,新图像和来的位置相差两个像素点。这个值是可调的,值越大,飞机飞行的速度越快*/

putimage(x0-width2,y0-height-3*width1-i,buf,XOR_PUT);
i+=2;
putimage(x0-width2,y0-height-3*width1-i,buf,XOR_PUT);

if(y0-height-3*width1-i==0)
{ outtextxy(60,100,"Successfully!!! Press ESC to quit");
key=getch();}

}while(key==-2);

free(buf);
closegraph();
return 0;

}





其中我用红字标出来的那段段,如何修改为按一下键后,火箭就会自动上升,而按ESC键就能退出?(原本是要手动按键,火箭才能上升)
我试着去掉了里面的getch()(我用蓝色标记出了),可是按ESC却无法退出。
望大侠指教~

这样火箭到头后按任意键退出

[此贴子已经被作者于2006-6-25 15:29:36编辑过]


[glow=255,violet,2]闭关修炼ing...[/glow] [FLASH=360,180]http://www./chinaren.swf[/FLASH]
2006-06-25 15:26
cjls1
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2006-6-25
收藏
得分:0 
以下是引用SunShining在2006-6-25 15:26:21的发言:

这样按火箭到头后按任意见退出

首先谢谢这位大侠的帮助。
但我是想按ESC退出,而按其他键都不会退出,怎么改?

2006-06-25 15:29
SunShining
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:31
帖 子:2215
专家分:0
注 册:2006-2-17
收藏
得分:0 

[CODE]/*主函数开始*/
main()
{
int size;
int i=0;
int key=-2;
int station;
int grdriver=DETECT;
int grmode;
initgraph(&grdriver,&grmode,"");
setbkcolor(BLACK);
cleardevice();/*图形驱动程序和屏幕初始化工作完成*/
setcolor(BLUE);/*设置字的颜色*/
settextstyle(TRIPLEX_FONT,0,4);/*设置字体*/
outtextxy(80,100,"Ready!...Any key to SET OFF !!!");
DrawGun(); /*画出发射架*/
getch(); /*if press key,clear the words and start*/
cleardevice();
DrawGun();
DrawPlan();
DrawStar();
setcolor(LIGHTRED);/*define result words color*/
do{ /*程序主循环开始,用于运动飞机,方法是用异或的方式在屏幕上连续画出飞机的图像,每画一次,新图像和来的位置相差两个像素点。这个值是可调的,值越大,飞机飞行的速度越快*/
putimage(x0-width2,y0-height-3*width1-i,buf,XOR_PUT);
i+=2;
putimage(x0-width2,y0-height-3*width1-i,buf,XOR_PUT);

if(y0-height-3*width1-i==0)
{outtextxy(60,100,"Successfully!!! Press ESC to quit");
while((key=getch())!=ESC);}

}while(key!=ESC);
free(buf);
closegraph();
return 0;
}[/CODE]

主函数改成这样.你去试试吧


[glow=255,violet,2]闭关修炼ing...[/glow] [FLASH=360,180]http://www./chinaren.swf[/FLASH]
2006-06-25 15:32
cjls1
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2006-6-25
收藏
得分:0 
以下是引用SunShining在2006-6-25 15:32:24的发言:

[CODE]/*主函数开始*/
main()
{
int size;
int i=0;
int key=-2;
int station;
int grdriver=DETECT;
int grmode;
initgraph(&grdriver,&grmode,"");
setbkcolor(BLACK);
cleardevice();/*图形驱动程序和屏幕初始化工作完成*/
setcolor(BLUE);/*设置字的颜色*/
settextstyle(TRIPLEX_FONT,0,4);/*设置字体*/
outtextxy(80,100,"Ready!...Any key to SET OFF !!!");
DrawGun(); /*画出发射架*/
getch(); /*if press key,clear the words and start*/
cleardevice();
DrawGun();
DrawPlan();
DrawStar();
setcolor(LIGHTRED);/*define result words color*/
do{ /*程序主循环开始,用于运动飞机,方法是用异或的方式在屏幕上连续画出飞机的图像,每画一次,新图像和来的位置相差两个像素点。这个值是可调的,值越大,飞机飞行的速度越快*/
putimage(x0-width2,y0-height-3*width1-i,buf,XOR_PUT);
i+=2;
putimage(x0-width2,y0-height-3*width1-i,buf,XOR_PUT);

if(y0-height-3*width1-i==0)
{outtextxy(60,100,"Successfully!!! Press ESC to quit");
while((key=getch())!=ESC);}

}while(key!=ESC);
free(buf);
closegraph();
return 0;
}[/CODE]

主函数改成这样.你去试试吧

能行,大侠强,拜下~
不过中途按ESC好像无效,没法退出。

2006-06-25 15:41
SunShining
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:31
帖 子:2215
专家分:0
注 册:2006-2-17
收藏
得分:0 
以下是引用cjls1在2006-6-25 15:41:00的发言:

不过中途按ESC好像无效,没法退出。

有利必有弊, 不可能两样兼得的.最起码我现在还没想到方法.


[glow=255,violet,2]闭关修炼ing...[/glow] [FLASH=360,180]http://www./chinaren.swf[/FLASH]
2006-06-25 15:44
cjls1
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2006-6-25
收藏
得分:0 
以下是引用SunShining在2006-6-25 15:44:15的发言:

有利必有弊, 不可能两样兼得的.最起码我现在还没想到方法.

那有没有就光中途按ESC退出的方法?(不用到顶了)

2006-06-25 15:49
SunShining
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:31
帖 子:2215
专家分:0
注 册:2006-2-17
收藏
得分:0 
以下是引用cjls1在2006-6-25 15:49:54的发言:

那有没有就光中途按ESC退出的方法?(不用到顶了)

这种方法可能就得用到多线程来做了..等老K来看看他有没有办法吧

俺们只要不会的都扔给老K..


[glow=255,violet,2]闭关修炼ing...[/glow] [FLASH=360,180]http://www./chinaren.swf[/FLASH]
2006-06-25 16:11
cjls1
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2006-6-25
收藏
得分:0 
以下是引用SunShining在2006-6-25 16:11:32的发言:

这种方法可能就得用到多线程来做了..等老K来看看他有没有办法吧

俺们只要不会的都扔给老K..

多线程?
C语言能实现吗?我还是在用TC编东西~还是说到时候我要换个编译器或系统?(表笑,偶是菜鸟)

2006-06-25 16:17
快速回复:[求助]关于“火箭发射”这个程序的修改问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015714 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved