TOP10.CPP
资源名称:泡泡龙源代码.zip [点击查看]
上传用户:junwei_58
上传日期:2007-05-15
资源大小:79k
文件大小:2k
源码类别:
其他智力游戏
开发平台:
Visual C++
- #define TOP10_CPP
- #include <stdio.h>
- #include <mem.h>
- #include "game.h"
- #include "top10.h"
- #include "keyintr.h"
- #include "speceffe.h"
- int loadtop10(){
- FILE *fp;
- if((fp=fopen(HIGHSCORE,"rb"))==NULL){
- fp=fopen(HIGHSCORE,"wb");
- fwrite(&tp10[0],sizeof(TopRecd),10,fp);
- memset(&tp10[0],0,sizeof(TopRecd)*10);
- }else{
- if(fread(&tp10[0],sizeof(TopRecd),10,fp)!=10){
- printf("error reading file");
- return 0;
- }
- }
- fclose(fp);
- return 1;
- }
- void savetop10(){
- FILE *fp;
- fp=fopen(HIGHSCORE,"r+b");
- if(fwrite(&tp10[0],sizeof(TopRecd),10,fp)!=10);//message("Error write to file");
- fclose(fp);
- }
- void checktop10(unsigned long score,int ply){
- char i=ply;
- smoothout();
- for(i=0;i<10;i++)if(score>tp10[i].score)break;
- if(i<10){
- setcolor(TEXTCOLOR);
- setbkcolor(BKGROUNDCOLOR);
- textxy(200,64,"New Record! Congratulations!!!",0);
- textxy(200,80,"Type Your Name",0);
- setcolor(TEXTCOLOR2);
- textxy(199,63,"New Record! Congratulations!!!",0);
- textxy(199,79,"Type Your Name",0);
- for(int j=9;j>i;j--)memcpy(&tp10[j],&tp10[j-1],sizeof(TopRecd));
- tp10[i].score=score;
- tp10[i].time.min=0;//curTime/6000;
- tp10[i].time.sec=0;//(curTime/100)%60;
- tp10[i].time.mse=0;//curTime%100;
- top10();
- rectantB(250,i*30+140,80,16,0);
- setcolor(TEXTCOLOR2);
- setbkcolor(BKGROUNDCOLOR);
- inputString(tp10[i].name,250,i*30+140,10,SMLCHARA|CAPCHARA|NORMSYMBLES|NUMBER);
- rectantB(250,i*30+140,100,16,BKGROUNDCOLOR);
- rectantB(199,64,280,96,BKGROUNDCOLOR);
- // setcolor(BKGROUNDCOLOR);
- // textxy(200,64,"New Record! Congratulations!!!",0);
- // textxy(200,80,"Type Your Name",0);
- top10();
- getch_Key();
- smoothout();
- }
- }
- void top10(){//message(problemStr[1]);problem=1;
- char str[12];
- int i;//,c;
- setcolor(TEXTCOLOR);
- setbkcolor(BKGROUNDCOLOR);
- textxy(250,100," name ",0);
- textxy(350,100," score ",0);
- textxy(426,100," time(mm:ss.s) ",0);
- lineH(200,130,400,TEXTCOLOR2);
- lineH(201,131,400,BORDERCOLOR);
- setpixel(200,131,TEXTCOLOR2);
- setpixel(600,130,BORDERCOLOR);
- for(i=0;i<10;i++){
- sprintf(str,"%2d",i+1);
- textxy(200,i*30+140,str,0);
- textxy(250,i*30+140,tp10[i].name,0);
- sprintf(str,"%5d",tp10[i].score);
- textxy(366,i*30+140,str,0);
- sprintf(str,"%04d:%02d.%02d",tp10[i].time.min,tp10[i].time.sec,tp10[i].time.mse);
- textxy(426,i*30+140,str,0);
- }
- }