程序运行后会在屏幕上用triplex_font显示“press any key for set off”,下方是用基本的线条画出的发射架(有点粗糙),即程序中的drawgun()函数,当按下任意键后,将在发射架上方出现一个用横线填充的飞机,同
时背景被繁星填充,此时必须按住任意键不放,否则飞机将不会发射。发射完成后,即飞机坐标小于0,将出现一句话:"successfully!!!,press esc to quit",若中途按esc退出,则飞机y坐标不小于0,将出现"failue,..."这句话。
#include<graphics.h>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#include<alloc.h>
#define esc 0x1b/*esc的ascii码,十六进制*/
void installgraph(void);/*图形程序加载函数的说名语句*/
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;
installgraph();
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;
}
/*****************install the graphics library***********************/
void installgraph(void)
{
int grdriver=detect;
int grmode;
int errorcode;
char *errormsg;
registerbgidriver(egavga_driver);
registerbgifont(triplex_font);
initgraph(&grdriver,&grmode,"");
errorcode=graphresult();
errormsg=grapherrormsg(errorcode);
if(errorcode!=grok){
printf("graphics error: %s\n",errormsg);
printf("press any key to exit.\n");
getch();
exit(1);
}
}
/************************draw the star ********************************/
void drawstar(void)
{
int seed=2000;
int i,dotx,doty,height,width,color,maxcolor;
maxcolor=getmaxcolor();
width=getmaxx();
height=getmaxy();
srand(seed);
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);
}
srand(seed);
}
/****************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);
l.neto(x0+rx+rightx,y0+righty);
moveto(x0+rx+rightx,y0+righty);
l.neto(x0+rx+rightx+10,y0+righty+10);
circle(x0+rx+rightx+10,y0+righty+10,4);
moveto(x0,y0+ry);
l.neto(x0,y0+centery1);
moveto(x0,y0+centery1);
l.neto(x0,y0+centery1+10);
circle(x0,y0+centery1+10,4);
moveto(x0-rx,y0);
l.neto(x0-rx-leftx,y0+lefty);
moveto(x0-rx-leftx,y0+lefty);
l.neto(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);
setfillstyle(1,blue);
ellipse(x0,y0-height,0,180,width1,3*width1);
moveto(x0+width1,y0); /*moveto center right side*/
l.neto(x0+width1,y0-height);
moveto(x0+width1,y0);
l.neto(x0+width2,y0+y2);
moveto(x0-width1,y0); /*moveto center left side*/
l.neto(x0-width1,y0-height);
moveto(x0-width1,y0);
l.neto(x0-width2,y0+y2);
moveto(x0+width2,y0+y3);/*moveto right bottom side*/
l.neto(x0+width2,y0+y1);
moveto(x0+width2,y0+y3);
l.neto(x0+width1,y0+y2);
moveto(x0-width2,y0+y3);/*moveto left bottom side*/
l.neto(x0-width2,y0+y1);
moveto(x0-width2,y0+y3);
l.neto(x0-width1,y0+y2);
moveto(x0,y0+y4); /*moveto the bottomest*/
l.neto(x0+width1,y0+y2);
moveto(x0,y0+y4);
l.neto(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);
}
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器