C语言基础 |
您所在的位置:网站首页 › 按任意键开始游戏综艺几时开播 › C语言基础 |
#include #include #include #include #include #include #define xLine 70 #define yLine 20 #define full 100 #define true 1 #define false 0 main() { voidprintScreen(int level,int right,int sum,char p[yLine][xLine]); int start(); void leave(); intlevelChoice(int level); int newWord(int sum,char p[yLine][xLine]); int moving(int miss,char p[yLine][xLine]); int wordHit(char p[yLine][xLine]); int result(intright); void clrscr(); char p[yLine] [xLine]; int i,j,level=0,right,sum,n,m,miss; srand(time(NULL)); start(); for(i=0;i0 && level0;j--) { if(p[i][j]!='') { w=p[i][j]; p[i][j]=''; p[i+1][j]=w; } } } return(miss); //返回用户打字游戏打错的字母的个数 } //主菜单 int start() { char c; while(true) { clrscr(); printf("\n\n\n\n\n欢迎来到打字游戏! \n\n\n1.开始游戏\n2.游戏说明\n0.退出游戏\n"); c=getch(); switch(c) { case '0':leave(); case '2': { clrscr(); printf("\n\n\n\n\n在字母从屏幕消失前,从键盘上输出对应字符。\n\n1.开始游戏\n2.返回菜单\n0.退出游戏\n"); while(true) { c=getch(); if(c=='0')leave(); if(c=='2')start(); if(c=='1')return(true); } } case'1' :return(true); } } } //用户输入后 与屏幕字符对比 int wordHit(char p[yLine][xLine]) { int i,j; char key; if(kbhit()) //判断用户是否从键盘输入字符。有输入kbhit返回值不为0 { key=getch(); putch(key); } if(key) { if(key=='0')leave(); if(key=='2')start(); if(key=='1') { clrscr(); printf("按任意键继续!\n"); getch(); } for(i=yLine;i>0;i--) //从最后一行的最后一个字母开始游历 { for(j=xLine;j>0;j--) { if(key-32==p[i-1][j-1]) { p[i-1][j-1]=''; //如果一输入的字符,则把对应的置空 return(true); } } } } return (false); }
//输出结果 询问用户是否继续 int result(int right) { int score; char yn; score=right*100/full; clrscr(); if(score==100) printf("非常棒!\n"); elseif(score>=85) printf("棒!\n"); elseif(score>=70) printf("继续努力!\n"); else printf("成绩不理想!\n"); printf("是否继续?Y或N\n"); for(;;) { yn=getch(); switch(yn) { case'y': { if(score>=70) { return(true); } elsereturn(false); } case'n':leave(); desault:printf("请输入一个正确的选择:"); } } }
|
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |