TOP10.CPP
上传用户:junwei_58
上传日期:2007-05-15
资源大小:79k
文件大小:2k
源码类别:

其他智力游戏

开发平台:

Visual C++

  1. #define TOP10_CPP
  2. #include <stdio.h>
  3. #include <mem.h>
  4. #include "game.h"
  5. #include "top10.h"
  6. #include "keyintr.h"
  7. #include "speceffe.h"
  8. int loadtop10(){
  9. FILE *fp;
  10. if((fp=fopen(HIGHSCORE,"rb"))==NULL){
  11. fp=fopen(HIGHSCORE,"wb");
  12. fwrite(&tp10[0],sizeof(TopRecd),10,fp);
  13. memset(&tp10[0],0,sizeof(TopRecd)*10);
  14. }else{
  15. if(fread(&tp10[0],sizeof(TopRecd),10,fp)!=10){
  16. printf("error reading file");
  17. return 0;
  18. }
  19. }
  20. fclose(fp);
  21. return 1;
  22. }
  23. void savetop10(){
  24. FILE *fp;
  25. fp=fopen(HIGHSCORE,"r+b");
  26. if(fwrite(&tp10[0],sizeof(TopRecd),10,fp)!=10);//message("Error write to file");
  27. fclose(fp);
  28. }
  29. void checktop10(unsigned long score,int ply){
  30. char i=ply;
  31. smoothout();
  32. for(i=0;i<10;i++)if(score>tp10[i].score)break;
  33. if(i<10){
  34. setcolor(TEXTCOLOR);
  35. setbkcolor(BKGROUNDCOLOR);
  36. textxy(200,64,"New Record! Congratulations!!!",0);
  37. textxy(200,80,"Type Your Name",0);
  38. setcolor(TEXTCOLOR2);
  39. textxy(199,63,"New Record! Congratulations!!!",0);
  40. textxy(199,79,"Type Your Name",0);
  41. for(int j=9;j>i;j--)memcpy(&tp10[j],&tp10[j-1],sizeof(TopRecd));
  42. tp10[i].score=score;
  43. tp10[i].time.min=0;//curTime/6000;
  44. tp10[i].time.sec=0;//(curTime/100)%60;
  45. tp10[i].time.mse=0;//curTime%100;
  46. top10();
  47. rectantB(250,i*30+140,80,16,0);
  48. setcolor(TEXTCOLOR2);
  49. setbkcolor(BKGROUNDCOLOR);
  50. inputString(tp10[i].name,250,i*30+140,10,SMLCHARA|CAPCHARA|NORMSYMBLES|NUMBER);
  51. rectantB(250,i*30+140,100,16,BKGROUNDCOLOR);
  52. rectantB(199,64,280,96,BKGROUNDCOLOR);
  53. // setcolor(BKGROUNDCOLOR);
  54. // textxy(200,64,"New Record! Congratulations!!!",0);
  55. // textxy(200,80,"Type Your Name",0);
  56. top10();
  57. getch_Key();
  58. smoothout();
  59. }
  60. }
  61. void top10(){//message(problemStr[1]);problem=1;
  62. char str[12];
  63. int i;//,c;
  64. setcolor(TEXTCOLOR);
  65. setbkcolor(BKGROUNDCOLOR);
  66. textxy(250,100,"   name   ",0);
  67. textxy(350,100," score ",0);
  68. textxy(426,100," time(mm:ss.s) ",0);
  69. lineH(200,130,400,TEXTCOLOR2);
  70. lineH(201,131,400,BORDERCOLOR);
  71. setpixel(200,131,TEXTCOLOR2);
  72. setpixel(600,130,BORDERCOLOR);
  73. for(i=0;i<10;i++){
  74. sprintf(str,"%2d",i+1);
  75. textxy(200,i*30+140,str,0);
  76. textxy(250,i*30+140,tp10[i].name,0);
  77. sprintf(str,"%5d",tp10[i].score);
  78. textxy(366,i*30+140,str,0);
  79. sprintf(str,"%04d:%02d.%02d",tp10[i].time.min,tp10[i].time.sec,tp10[i].time.mse);
  80. textxy(426,i*30+140,str,0);
  81. }
  82. }