功能:(1)三种LEVEL;(2)根据LEVEL选择计时;(3)随机选择文章;(4)显示打字能力,并判断是否通关
待解决问题:提前打完了怎么办?
//打字游戏
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
int choose(char passage[][1000]);//随机选文函数
int counttime(int t);//计时函数
int piont(char *passage,char *answer,int t,int *letter,int *speed,int *correct,int *total);//统分函数
int main(void)
{
char passage[3][1000]={" Once when I was six years old I saw a magnificent picture in a book, called True Stories from Nature, about the primeval forest. It was a picture of a boa constrictor in the act of swallowing an animal. Here is a copy of the drawing. In the book it said, Boa constrictors swallow their prey whole, without chewing it.",
" My drawing was not a picture of a hat. It was a picture of a boa constrictor digesting an elephant. But since the grown-ups were not able to understand it, I made another drawing: I drew the inside of the boa constrictor, so that the grown-ups could see it clearly. They always need to have things explained. My Drawing Number Two looked like this: The grown-ups response, this time was to advise me to lay aside my drawings of boa constrictors, whether from the inside or the outside, and devote myself instead to geography, history, arithmetic and grammar.",
" That is why, at the age of six, I gave up what might have been a magnificent career as a painter. I had been disheartened by the failure of my Drawing Number One and my Drawing Number Two. Grown-ups never understand anything by themselves, and it is tiresome for children to be always and forever explaining things to them."
};
char answer[500];
int total,letter,speed,correct,level,which,t[3]={180,120,60};
// total文章总字数,letter输入的总字数,speed输词速度(只计算准确的量),correct正确字数,level选择级别,which抽中文章,t总计时
printf("Easy1, Medium2, Hard3?\n");
scanf("%d",&level);
which = choose(passage);
counttime(t[level-1]);
gets(answer);
piont(passage[which],answer,t[level-1],&letter,&speed,&correct,&total);
printf("Level %d\n\
In %d seconds, you had printed %d letters, in which %d one are correct.\nYour speed is %d letter/min.\n",level,t[level-1],letter,correct,speed);
if (correct > total*8/10)
{
printf("You passed level %d!\n",level);
}
else
printf("Fail the challenge!\n");
return 0;
}
int choose(char passage[][1000])
{
int i;
srand((unsigned)time(NULL));
i = rand()%3;
printf("%s\n",passage[i]);
printf("\n");
return i;
}
int counttime(int t)
{
long a,b;
printf("Start now?\n");
getchar();
getchar();
printf("Start!\n");
a = time(NULL);
while (1)
{
b = time(NULL);
if ((b-a)>=t)
{
printf("\n%d seconds off!\n",t);
break;
}
}
return 0;
}
int piont(char *passage,char *answer,int t,int *letter,int *speed,int *correct,int *total)
{
int i;
*correct = 0;
for (i=0; passage[i] != '\0'; i++)
{
;
}
*total = i;
for (i=0; answer[i] != 0; i++)
{
if (passage[i] == answer[i])
{
(*correct)++;
}
}
*letter = i;
*speed = (*correct)*60/t;
return 0;
}
选文摘自The Little Prince