|
作者: w181948297 [w181948297] 论坛用户 | 登录 |
看不懂下面的句子啊!谁看懂了帮我说一下它实现了什么功能啊?在线急等!谢谢! #include <dos.h> #include <math.h> #include <conio.h> #include <stdio.h> #include <stdlib.h> #include <stdarg.h> #include <graphics.h> #include <string.h> #include <ctype.h> #define UP 0x48 #define DOWN 0x50 #define LEFT 0x4b #define RIGHT 0x4d #define ENTER 0x0d void *rar; struct palettetype palette; int GraphDriver; int GraphMode; int ErrorCode; int MaxColors; int MaxX, MaxY; double AspectRatio; void drawboder(void); void initialize(void); void computer(void); void changetextstyle(int font, int direction, int charsize); void mwindow(char *header); int specialkey(void) ; int arrow(); int main() { initialize(); computer(); closegraph(); return(0); } void initialize(void) { int xasp, yasp; GraphDriver = DETECT; initgraph( &GraphDriver, &GraphMode, "" ); ErrorCode = graphresult(); if( ErrorCode != grOk ) { printf("Graphics System Error: %s\n", grapherrormsg( ErrorCode ) ); exit( 1 ); } getpalette( &palette ); MaxColors = getmaxcolor() + 1; MaxX = getmaxx(); MaxY = getmaxy(); getaspectratio( &xasp, &yasp ); AspectRatio = (double)xasp/(double)yasp; } void computer(void) { struct viewporttype vp; int color, height, width; int x, y,x0,y0, i, j,v,m,n,act,flag=1; float num1=0,num2=0,result; char cnum[5],str2[20]={""},c,temp[20]={""}; char str1[]="1230.456+-789*/Qc=^%"; mwindow( "Calculator" ); color = 7; getviewsettings( &vp ); width=(vp.right+1)/10; height=(vp.bottom-10)/10 ; x = width /2; y = height/2; setfillstyle(SOLID_FILL, color+3); bar( x+width*2, y, x+7*width, y+height ); setcolor( color+3 ); rectangle( x+width*2, y, x+7*width, y+height ); setcolor(RED); outtextxy(x+3*width,y+height/2,"0."); x =2*width-width/2; y =2*height+height/2; for( j=0 ; j<4 ; ++j ) { for( i=0 ; i<5 ; ++i ) { setfillstyle(SOLID_FILL, color); setcolor(RED); bar( x, y, x+width, y+height ); rectangle( x, y, x+width, y+height ); sprintf(str2,"%c",str1[j*5+i]); outtextxy( x+(width/2), y+height/2, str2); x =x+width+ (width / 2) ; } y +=(height/2)*3; x =2*width-width/2; } x0=2*width; y0=3*height; x=x0; y=y0; gotoxy(x,y); arrow(); putimage(x,y,rar,XOR_PUT); m=0; n=0; strcpy(str2,""); while((v=specialkey())!=45) { while((v=specialkey())!=ENTER) { putimage(x,y,rar,XOR_PUT); if(v==RIGHT) if(x>=x0+6*width) { x=x0; m=0; } else { x=x+width+width/2; m++; } if(v==LEFT) if(x<=x0) { x=x0+6*width; m=4; } else { x=x-width-width/2; m--; } if(v==UP) if(y<=y0) { y=y0+4*height+height/2; n=3; } else { y=y-height-height/2; n--; } if(v==DOWN) if(y>=7*height) { y=y0; n=0; } else { y=y+height+height/2; n++; } putimage(x,y,rar,XOR_PUT); } c=str1[n*5+m]; if(isdigit(c)||c=='.') { if(flag==-1) { strcpy(str2,"-"); flag=1; } sprintf(temp,"%c",c); strcat(str2,temp); setfillstyle(SOLID_FILL,color+3); bar(2*width+width/2,height/2,15*width/2,3*height/2); outtextxy(5*width,height,str2); } if(c=='+') { num1=atof(str2); strcpy(str2,""); act=1; setfillstyle(SOLID_FILL,color+3); bar(2*width+width/2,height/2,15*width/2,3*height/2); outtextxy(5*width,height,"0."); } if(c=='-') { if(strcmp(str2,"")==0) flag=-1; else { num1=atof(str2); strcpy(str2,""); act=2; setfillstyle(SOLID_FILL,color+3); bar(2*width+width/2,height/2,15*width/2,3*height/2); outtextxy(5*width,height,"0."); } } if(c=='*') { num1=atof(str2); strcpy(str2,""); act=3; setfillstyle(SOLID_FILL,color+3); bar(2*width+width/2,height/2,15*width/2,3*height/2); outtextxy(5*width,height,"0."); } if(c=='/') { num1=atof(str2); strcpy(str2,""); act=4; setfillstyle(SOLID_FILL,color+3); bar(2*width+width/2,height/2,15*width/2,3*height/2); outtextxy(5*width,height,"0."); } if(c=='^') { num1=atof(str2); strcpy(str2,""); act=5; setfillstyle(SOLID_FILL,color+3); bar(2*width+width/2,height/2,15*width/2,3*height/2); outtextxy(5*width,height,"0."); } if(c=='%') { num1=atof(str2); strcpy(str2,""); act=6; setfillstyle(SOLID_FILL,color+3); bar(2*width+width/2,height/2,15*width/2,3*height/2); outtextxy(5*width,height,"0."); } if(c=='=') { num2=atof(str2); switch(act) { case 1:result=num1+num2;break; case 2:result=num1-num2;break; case 3:result=num1*num2;break; case 4:result=num1/num2;break; case 5:result=pow(num1,num2);break; case 6:result=fmod(num1,num2);break; } setfillstyle(SOLID_FILL,color+3); bar(2*width+width/2,height/2,15*width/2,3*height/2); sprintf(temp,"%f",result); outtextxy(5*width,height,temp); } if(c=='c') { num1=0; num2=0; flag=1; strcpy(str2,""); setfillstyle(SOLID_FILL,color+3); bar(2*width+width/2,height/2,15*width/2,3*height/2); outtextxy(5*width,height,"0."); } if(c=='Q')exit(0); } putimage(x,y,rar,XOR_PUT); return; } void mwindow( char *header ) { int height; cleardevice(); setcolor( MaxColors - 1 ); setviewport( 20, 20, MaxX/2, MaxY/2, 1 ); height = textheight( "H" ); settextstyle( DEFAULT_FONT, HORIZ_DIR, 1 ); settextjustify( CENTER_TEXT, TOP_TEXT ); outtextxy( MaxX/4, 2, header ); setviewport( 20,20+height+4, MaxX/2+4, MaxY/2+20, 1 ); drawboder(); } void drawboder(void) { { int key; while(bioskey(1)==0); key=bioskey(0); key=key&0xff? key&0xff:key>>8; return(key); } |
地主 发表时间: 04-06-09 09:54 |
回复: yangliwei [yangliwei] 论坛用户 | 登录 |
唉~! 这是一个小游戏呀! |
B1层 发表时间: 04-06-09 17:20 |
回复: w181948297 [w181948297] 论坛用户 | 登录 |
能不能数具体点啊 大哥,他是怎么一步一步实现的啊? |
B2层 发表时间: 04-06-10 08:38 |
回复: yangliwei [yangliwei] 论坛用户 | 登录 |
兄弟,程序是没时间多看, 但从前面的些许代码可以想出来, 是在图形模式下实现的,还定义了相关的按键, 所以,我想应是小游戏之类的~! 这是DOS的TC可以编译通过的吧?!、 程序定得还可以,你可以研究研究! |
B3层 发表时间: 04-06-10 09:35 |
回复: w181948297 [w181948297] 论坛用户 | 登录 |
谢谢 啊威哥哥的指点!!小弟一定努力学习! |
B4层 发表时间: 04-06-10 10:07 |
回复: yangliwei [yangliwei] 论坛用户 | 登录 |
不客气, 指点谈不上~! |
B5层 发表时间: 04-06-10 10:11 |
回复: w181948297 [w181948297] 论坛用户 | 登录 |
我在绿色兵团 贴了两天,没人理我呢? |
B6层 发表时间: 04-06-10 10:36 |
|
20CN网络安全小组版权所有
Copyright © 2000-2010 20CN Security Group. All Rights Reserved.
论坛程序编写:NetDemon
粤ICP备05087286号