当前位置:文档之家› 打字游戏完整功能

打字游戏完整功能

#include
#include
#include
#include

#define N 61
#define UIC 55

char ch[62]=
{
'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
'0','1','2','3','4','5','6','7','8','9'
};

void gotoxy(int x, int y)//x为列坐标,y为行坐标(VC下用,TC下可以省略,而需导入bios.h头文件)
{
COORD pos = {x,y};
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hOut, pos);
}

int InitMenu()
{
int grade,gTime;

system("CLS");
gotoxy(15,10);
printf("1.入门选手 2.初级选手 3.中级选手 4.高级选手\n");
gotoxy(15,12);
printf("请输入游戏级别:");
scanf("%d",&grade);
switch(grade)
{
case 1:
gTime=2000;break;
case 2:
gTime=1000;break;
case 3:
gTime=500;break;
case 4:
gTime=200;break;
}
return gTime;
}

void WinMenu()//游戏窗口菜单
{
int i;
gotoxy(20,2);
printf("************* 游戏开始!************\n");
for(i=0;i<80;i++)
{
gotoxy(i,3);
printf("_");
gotoxy(i,20);
printf("_");
gotoxy(20,21);
printf("************** 按ESC退出 **************\n");
gotoxy(65,23);
printf("作者:尹江山");
}
}

void ExitMenu()
{
int x=18;
gotoxy(x,9);
printf("---------------------------------------\n");
gotoxy(x,10);
printf("| |\n");
gotoxy(x,11);
printf("| 按任意键退出!! |\n");
gotoxy(x,12);
printf("| |\n");
gotoxy(x,13);
printf("---------------------------------------\n");
}

void cls() //清除固定区域
{
int y;
for(y=4;y<20;y++)
{
gotoxy(0,y);
printf("\t\t\t\t\t\t\t\t\t\t");
}
}

int PlayGame(int g)
{
int num=50;//初始化分数
int i,j,x;
char c,cKey;
x=rand()%80; //随机生成x坐标
while(1)
{
i=rand()%N; //随机生成0-61之间的索引。
c=ch[i];
for(j=4;j<20;j++)
{
if(cKey=='\033')//如果按了ESC键
{
system("CLS");
goto e;
}
cls(); //清屏
gotoxy(x,j);
printf("%c\n",ch[i]);
if(num==UIC&&g==2000)//如果分数满55分
{
cls();
gotoxy(20,2);
printf("**** 分数满,自动进入第二关! ****\n");//跳到提示
num=50;
g=1000;
}
else if(num==UIC&&g==1000)
{
cls();
gotoxy(20,2);
printf("**** 分数满,自动进入第三关! ****\n");//跳到提示
num=50;
g=500;
}
else if(num==UIC&&g==500)
{
cls();
gotoxy(20,2);
printf("**** 分数满,自动进入第四关! ****\n");//跳到提示
num=50;
g=200;
}
else if(num==UIC&&g==200)
{
system("cls");
printf("通关!游戏结束!\n");
goto e;
}
Sleep(g);
if

(kbhit()) //如果有键被按下
{
cKey=getch();
cls();
gotoxy(35,21);
if(c==cKey)
{
printf("正 确\n");
num++;

}
else
{
printf("错 误\n");
num--;
}
gotoxy(20,2);
printf("********** 当前分数:%d **********\n",num);
break;
}
else
{
cls();
continue;
}
}
}
e:ExitMenu();
getch();
}

void main()
{
int grade; //游戏级别
grade=InitMenu();
WinMenu(); //显示菜单
PlayGame(grade);
}

相关主题
文本预览
相关文档 最新文档