logo资料库

简易台球仿真系统.doc

第1页 / 共48页
第2页 / 共48页
第3页 / 共48页
第4页 / 共48页
第5页 / 共48页
第6页 / 共48页
第7页 / 共48页
第8页 / 共48页
资料共48页,剩余部分请下载后查看
简易台球仿真系统 NAMEPUT: #include"D:\c\pool\pool.h" void NamePut(PLAYER *Player,char gamemode) { char str[10],a,i=0; /************************** Input Player 1 ******************/ setfillstyle(SOLID_FILL,BLUE); bar(250,160,380,200); setcolor(YELLOW); settextstyle(DEFAULT_FONT,HORIZ_DIR,1); outtextxy(255,165,"Player1's name:"); for(i=0;i<8;i++) { a=bioskey(0); if(a==BACK&&i!=0) { setfillstyle(SOLID_FILL,BLUE); bar(260+9*(i-1),180,260+9*(i),180+8); i-=2; } else if(a==ENTER) { str[i]='\0'; break; } else { str[i]=a; str[i+1]='\0'; outtextxy(260+9*i,180,&str[i]); } } str[7]='\0'; strcpy(Player[1].name,str);
bar(72,393,132,417); outtextxy(78,400,Player[1].name); bar(142,393,212,417); itoa(Player[1].score,str,10); outtextxy(147,400,str); setcolor(YELLOW); setfillstyle(SOLID_FILL,GREEN); settextstyle(DEFAULT_FONT,HORIZ_DIR,1); outtextxy(14,10,"Now:"); outtextxy(54,10,Player[1].name); /************** Input Player 2 *******************/ if(gamemode==2) // 2 Players Mode { setfillstyle(SOLID_FILL,MAGENTA); bar(250,160,380,200); setcolor(YELLOW); settextstyle(DEFAULT_FONT,HORIZ_DIR,1); outtextxy(255,165,"Player2's name:"); for(i=0;i<8;i++) { a=bioskey(0); if(a==BACK&&i!=0) { setfillstyle(SOLID_FILL,MAGENTA); bar(260+9*(i-1),180,260+9*(i),180+8); i-=2; } else if(a==ENTER) { str[i]='\0'; break; } else { str[i]=a;
str[i+1]='\0'; outtextxy(260+9*i,180,&str[i]); } } str[7]='\0'; strcpy(Player[2].name,str); bar(72,423,132,447); outtextxy(78,430,Player[2].name); bar(142,423,212,447); itoa(Player[2].score,str,10); outtextxy(147,430,str); } /************************* ************************************/ if(gamemode==1) { setfillstyle(SOLID_FILL,MAGENTA); bar(72,423,132,447); outtextxy(78,430,Player[0].name); /// bar(142,423,212,447); itoa(Player[0].score,str,10); outtextxy(147,430,str); } // recover setfillstyle(SOLID_FILL,GREEN); bar(250,160,380,200); } MOVEBALL #include"D:\c\pool\pool.h" Single Mode: show highest void MoveBall(BALL *Ball,PLAYER *player,char *preward,char num,char gamemode) { float distance[N],dt,dl,sm,vm,s,temp; int j, k, judge1=0,judge2=0; int wall=0; vm=Max_V(Ball); sm=pow(vm,2)/(2*u*g);
for(j=0;j1) { distance[j]=(pow(sm,0.5)-pow(sm-1,0.5))/(pow(s,0.5)-pow(s-1,0.5)); } else { distance[j]=2; } } for(j=0;j=s-1) { distance[k]=temp+2; Ball[k].v=0; } if(distance[k]
judge1=judge2; } wall = In_Hole(Ball+k,player,wall,num,gamemode); // wall==1 Ball in hole! if(wall==1) { *preward=1; } if(judge2!=0||wall!=0) { if(wall!=0) { Calculate_V(Ball,distance); } vm=Max_V(Ball); sm=pow(vm,2)/(2*u*g); for(j=0;j1) { distance[j]=(pow(sm,0.5)-pow(sm-1,0.5))/(pow(s,0.5)-pow(s-1,0.5)); } else { distance[j]=2; } } j=-1; } } } My_Delay(dt); } Rules(Ball[0].status,player,judge1,preward,num,gamemode); // Rules for(j=0;j
} LOGO #include"D:\c\pool\pool.h" void Logo () { FILE *pic; unsigned char pal[256][3]; int union REGS regs; i, j; /*********** Initialize 256 colors ************/ regs.x.ax=0x13; int86 (0x10,®s,®s); /************** Open BMP file *****************/ if ((pic = fopen ("D:\\c\\pool\\POOL.bmp","rb"))==NULL) { //DIR printf ("Error on opening file!"); exit (1); } fseek (pic,54,SEEK_SET); /************ Set the palette *************/ for (i=0;i<256;i++) { //B,G,R pal[i][2] = fgetc (pic)>>2; pal[i][1] = fgetc (pic)>>2; pal[i][0] = fgetc (pic)>>2; fgetc (pic); SetPalette (i,pal[i][0],pal[i][1],pal[i][2]); } /*********** Show the picture *************/ for (i=0;i<200;i++) { for (j=0;j<320;j++)
pokeb (0xa000,i*320+j,fgetc(pic)); { } } getch(); /************ Back to 16 colors *************/ regs.x.ax=0x3; int86 (0x10,®s,®s); fclose (pic); } void SetPalette (int color,unsigned char colorr,unsigned char colorg,unsigned char colorb) { outportb (0x3c8,color); outportb (0x3c9,colorr); outportb (0x3c9,colorg); outportb (0x3c9,colorb); } SAVELOAD include"D:\c\pool\pool.h" void Save_Game(PLAYER *Player,BALL *pBall,char *pnum,char *pgamemode) { FILE *fp; char i=0,str1[20],str2[20]; if((fp=fopen("e:\\pool\\save.txt","wt"))==NULL) { printf("Error in save!!File not saved!!"); return; } rewind(fp); fprintf(fp,"%d %d\n",*pgamemode,*pnum); for(i=0;i<3;i++) { // direction!!!!!!!!!! fprintf(fp,"%s %d %d\n",Player[i].name,Player[i].score,Player[i].fault); } for(i=0;i
{ sprintf(str1,"%.6f",pBall[i].x); sprintf(str2,"%.6f",pBall[i].y); fprintf(fp,"%d %d %s %s\n",pBall[i].color,pBall[i].status,str1,str2); fprintf(fp,"%d %d %.6f %.6f\n",pBall[i].color,pBall[i].status,pBall[i].x,pBall[i].y); } fclose(fp); // } void Load_Game(PLAYER *Player,BALL *pBall,char *pnum,char *pgamemode) { FILE *fp; char i=0; char str1[20],str2[20]; if((fp=fopen("e:\\pool\\save.txt","rt"))==NULL) { printf("Load in save!!File not loaded!!"); return; } rewind(fp); fscanf(fp,"%d %d\n",pgamemode,pnum); for(i=0;i<3;i++) { // direction!!! fscanf(fp,"%s %d %d\n",Player[i].name,&(Player[i].score),&(Player[i].fault)); } for(i=0;i
分享到:
收藏