猜单词游戏c语言源程序
包括程序及txt文档,希望可以对您有所帮助
#include
#include
#include
#include
#include
#include
#include
void OpenWordFile(char string[21][11]);
void PlayGame(char wordlist[21][11]);
void Change(char wordlist[21][11],char str[21][11]);
void StartGame (char wordlist[21][11]);
int guesstime=10;
int round;
void Set()
{
printf("请输入您想猜的单词数:");
scanf("%d",&round);
}
struct Player
{
char name[20];
int right;
int wrong;
int time;
};
typedef struct Player Player;
Player p[5]={{1,"unknown",0,0,0},{2,"unknown",0,0,0},{3,"unknown",0,0,0},{4,"unknown",0,0,0},{5,"unknown",0,0,0}};
Player temp;
int right=0,wrong=0;
void OpenWordFile (char string[21][11])
{
FILE *fp;
char c;
int i=0;
int j=0;
if((fp=fopen("word.txt","r"))==NULL) //读文件
{
printf("单词库无法打开!\n");
exit(0);
}
else
{
c=fgetc(fp);
while(c!=EOF)
{
if(c!='\n')
{
string[i][j]=c;
j++;
}
else
{
i++;
j=0;
}
c=fgetc(fp);
}
}
}
void SetGame ()
{
printf("请输入你想猜的次数:");
scanf("%d",&guesstime);
}
void PlayGame (char wordlist[21][11])
{
char guess; //存用户打入的字母
char guessword[11];//存用户打入的词
int l,j,k,f;
int p=1,q=0,x=0,y=0;
char WrongGuess[11];
int t=0;
int flag=0;
int c=1; //用来查看是否猜对所有字母
srand(time(NULL));
q=rand()%21;
l=strlen(wordlist[q]); //求单词长
for(f=0;f
{
guessword[f]='-';
}
guessword[l]='\0'; //字符串结尾
printf("%s",guessword);//打印与词长相同的"-"
for(k=1;k<=guesstime && c!=0;) //判断是否猜完
{
flag = 0;
printf("你还有%d次机会!\n",guesstime-k+1);
scanf(" %c",&guess);
for(j=0;j
{
if(guessword[j]=='-' ) //判断是否猜过这个字母
{
if(wordlist[q][j]==guess||wordlist[q][j]-guess==32) //如果单词中有这个字母
{
guessword[j]=wordlist[q][j];//在空单词中打入这个字母
x++;
flag = 1;
}
}
else if(guessword[j]==guess||guessword[j]