1 #include<graphics.h> 2 #include<conio.h> 3 #include<stdio.h> 4 #include<time.h> 5 #pragma comment(lib,"Winmm.lib") 6 7 void First(); 8 void Second(); 9 void GameStart(); 10 void GameOver(); 11 12 char s1[10],s[10]; 13 int total/*点击次数*/,Right/*正确个数*/,num/*字母总个数*/,Rank/*等级*/; 14 int flag=0;//标记是否按了esc; 15 double TotalRank;//正确率,正确数与点击总数之比; 16 17 int main() 18 { 19 initgraph(750,550); 20 setbkcolor(CYAN); 21 cleardevice(); 22 23 First(); 24 getch(); 25 Second(); 26 char ch; 27 ch=getch(); 28 outtextxy(240,380,ch); 29 getchar(); 30 Rank=ch-'0'; 31 GameStart(); 32 GameOver(); 33 closegraph(); 34 return 0; 35 } 36 void First() 37 { 38 mciSendString("play 开场.mp3",NULL,0,NULL); 39 setfont(50,0,"楷体"); 40 outtextxy(50,100,"没错,就是很传统的那个掉字"); 41 outtextxy(50,200,"母然后按相应键就消失的游戏"); 42 setcolor(RGB(246,105,251)); 43 setfont(60,0,"MV Boli"); 44 outtextxy(100,300,"have a try!!!"); 45 setfont(40,0,"楷体"); 46 setcolor(RED); 47 outtextxy(400, 500, "请按任意键继续"); 48 } 49 void Second() 50 { 51 cleardevice(); 52 setcolor(YELLOW); 53 setfont(50,0,"楷体"); 54 outtextxy(200,20,"打字母游戏"); 55 setcolor(RGB(25,25,35)); 56 setfont(40,0,"新宋体"); 57 outtextxy(0,70,"游戏说明"); 58 setcolor(WHITE); 59 setfont(30,0,"宋体"); 60 outtextxy(0,130,"一、每次下落若干个字母,字母个数当然要看级别咯"); 61 outtextxy(0,180,"二、被点中字母个数与你的点击数之比为您的正确率"); 62 outtextxy(0,230,"三、小编语是要看正确率的哦"); 63 outtextxy(0,280,"四、按键1--5选择不同游戏的级别"); 64 outtextxy(0,330,"五、5级最高,1级最低"); 65 setfont(30,0,"黑体"); 66 int c=255; 67 while(!kbhit()) 68 { 69 setcolor(RGB(c,82,208)); 70 outtextxy(0,380,"请输入游戏级别:"); 71 c-=25; 72 if(c<0) c=255; 73 Sleep(100); 74 } 75 } 76 void GameStart() 77 { 78 mciSendString("close all",NULL,0,NULL); 79 mciSendString("play abc.mp3",NULL,0,NULL); 80 cleardevice(); 81 num=15*Rank; 82 Right=0; 83 srand(time(NULL));//设置随机种子; 84 setfillstyle(CYAN); 85 setcolor(BLACK); 86 line(0,510,749,510); 87 line(0,50,749,50); 88 setcolor(RGB(255,0,0)); 89 setfont(40,0,"MV Boli"); 90 outtextxy(0,0,"SCORE:"); 91 sprintf(s,"%d",Right); 92 outtextxy(150,0,s); 93 int x,y; 94 char target,key; 95 int m=0; 96 while(flag==0&&num>0) 97 { 98 m++; 99 setfont(60,0,"BIG");/*设置字母的字体和大小*/ 100 target=97+rand()%26;/*产生的任意小写字母*/ 101 x=rand()%700; /*产生的任意下落位置*/ 102 for(y=60;y<436;) 103 { 104 y+=m/10+1; 105 setcolor(RGB(255,150,255)); 106 outtextxy(x,y,target); 107 if(kbhit())//检查当前是否有键盘输入 108 { 109 key=getch(); 110 total++; 111 if(key==target||key==target-32) 112 { 113 mciSendString("play 正确.mp3",NULL,0,NULL); 114 Right++; 115 sprintf(s,"%d",Right); 116 setcolor(RGB(255,0,0)); 117 setfont(40,0,"MV Boli"); 118 outtextxy(0,0,"SCORE:"); 119 outtextxy(150,0,s); 120 bar(x-60,y-60,x+60,y+60); 121 break; 122 } 123 else if(key==27) 124 { 125 flag=1; 126 break; 127 } 128 } 129 Sleep(10); 130 bar(x,y,x+55,y+65); 131 } 132 num--; 133 TotalRank=Right*1.0/total*100; 134 sprintf(s1,"%.2lf",TotalRank);/*把double型换成字符型*/ 135 } 136 } 137 void GameOver() 138 { 139 mciSendString("close all",NULL,0,NULL); 140 mciSendString("play 搞笑.mp3",NULL,0,NULL); 141 cleardevice(); 142 setcolor(RGB(246,105,251)); 143 setfont(100,0,"MV Boli"); 144 outtextxy(200,300,"Game Over"); 145 setcolor(RED); 146 setfont(30,0,"黑体"); 147 outtextxy(180,80,"共有字母数:"); 148 sprintf(s,"%d",Rank*15); 149 outtextxy(350,80,s); 150 outtextxy(420,80,"您对的个数:"); 151 sprintf(s,"%d",Right); 152 outtextxy(600,80,s); 153 setcolor(YELLOW); 154 setfont(50,0,"黑体"); 155 if(total==0) 156 outtextxy(200,230,"发什么呆啊"); 157 else 158 { 159 outtextxy(200,130,"您的正确率:"); 160 outtextxy(480,130,s1); 161 outtextxy(605,130,"%"); 162 setcolor(RGB(255,25,140)); 163 if(TotalRank==100 && Right==Rank*15 && Rank<9) 164 outtextxy(100,230,"你可以挑战下个级别了哦"); 165 else if(TotalRank==100 && Right==Rank*15 && Rank==9) 166 outtextxy(100,230,"你真是健步如飞哦"); 167 else if(TotalRank==100 && Right!=Rank*15 ) 168 outtextxy(100,230,"离成功仅有一步了,唉!"); 169 else if(TotalRank!=130 && Right==0 ) 170 outtextxy(250,230,"你又O啦"); 171 else if(95<=TotalRank&&TotalRank<100) 172 outtextxy(220,230,"哎呦,不错嘛"); 173 else if(90<=TotalRank&&TotalRank<95) 174 outtextxy(200,230,"有点玩家的意思了"); 175 else if(85<=TotalRank&&TotalRank<90) 176 outtextxy(200,230,"你开始找到感觉了"); 177 else if(80<=TotalRank&&TotalRank<85) 178 outtextxy(220,200,"好好练习吧"); 179 else if(70<=TotalRank&&TotalRank<80) 180 outtextxy(200,200,"很佩服你那么坚持"); 181 else if(60<=TotalRank&&TotalRank<70) 182 outtextxy(200,200,"还是接着看电视吧"); 183 else if(50<=TotalRank&&TotalRank<60) 184 outtextxy(300,200,"无语"); 185 else if(40<=TotalRank&&TotalRank<50) 186 outtextxy(210,200,"到底行不行啊"); 187 else if(TotalRank<40) 188 outtextxy(220,200,"开玩笑啊"); 189 } 190 setfont(40,0,"楷体"); 191 setcolor(WHITE); 192 outtextxy(400, 500, "请按任意键退出"); 193 getch(); 194 }