游戏说明
运行须知:
请将压缩文件中的list.txt englishi.txt people.txt answer.txt放入D盘中的game文件夹中才能正常运行游戏,或者更改文件途径。
输入1可以登录用户,输入2可以游客试玩,用户登录可以查看单词本,里面有本游戏所粗存的所有单词及意思,游客只能游戏,不能查看单词本,如果强行查看只有强行退出游戏重开。
目前可以登录的四个用户是:
账号 密码
2001 2001
2002 2002
2005 2005
2333 4666
(注册功能暂未开启。。。。。。。QAQ)
游戏规则:
系统会在储存的单词中随机挑选一个单词并抹去其中一个字母。你需要猜测“*”部位的字母。在生词模式下,你可以将词汇加入生词本。在怀旧模式下,你所猜测的是你加入生词本的词。玩家登陆有福利可以查看词典。
代码简介:
有一个people类,配合文件一起进行登录操作,运用了文件存储单词,学习了使用随机数,用了数组储存文件中的内容,有菜单界面函数,游戏函数,登录函数,在代码中有注释。
思路:
刚开始的时候按要求先写出了最基础的,猜单词,然后在猜单词的基础上开始回忆玩过的游戏,开始分游戏的模式,然后开始有用户登录和玩家试玩,看起来更像游戏,为了区分玩家和游客的区别又在玩家方面加了可以看单词本的功能。
-
#include <iostream>
-
#include <fstream>
-
#include <string>
-
#include<ctime>
-
#include<conio.h>
-
using
namespace
std;
-
class people
-
{
-
public:
-
int snum;
-
int spassword;
-
people * next;
-
};
-
people *head1=
NULL;
-
void menu();
//菜单函数
-
void star();
//链接游戏的函数
-
void instruction();
//游戏说明
-
void startgame1();
//生词模式函数
-
void startgame2();
//怀旧模式函数
-
void denglu();
//玩家登陆函数
-
void enter();
//没啥大用的链接其他函数的函数
-
void danci();
//登录用户查看单词本的函数
-
int main()
-
{
-
cout<<
"玩家登陆请输入1,游客试玩请输入2,退出请输入0"<<
endl;
-
int n;
-
while(n)
-
{
-
cout<<
"请选择操作"<<
endl;
-
cin>>n;
-
switch(n)
-
{
-
case
1:
-
denglu();
-
break;
-
case
2:
-
star();
-
break;
-
}
-
}
-
}
-
void star()
-
{
-
int xuanxiang;
-
menu();
//显示菜单
-
while(xuanxiang)
//选择操作
-
{
-
cout<<
"请选择操作"<<
endl;
-
cin>>xuanxiang;
-
system(
"cls");
-
switch(xuanxiang)
-
{
-
case
1:
-
instruction();
//游戏说明
-
menu() ;
-
break;
-
case
2:
-
enter();
//游戏开始
-
menu() ;
-
break;
-
-
}
-
}
-
}
-
void star2()
-
{
-
int xuanxiang;
-
menu();
//显示菜单
-
while(xuanxiang)
//选择操作
-
{
-
cout<<
"请选择操作"<<
endl;
-
cin>>xuanxiang;
-
system(
"cls");
-
switch(xuanxiang)
-
{
-
case
1:
-
instruction();
//游戏说明
-
menu() ;
-
break;
-
case
2:
-
enter();
//游戏开始
-
menu() ;
-
break;
-
case
3:
-
danci();
-
menu() ;
-
break;
-
-
}
-
}
-
}
-
-
-
-
-
void denglu()
-
{
-
int m,n;
-
int snum,spassword;
-
ifstream read("d:\\game\\people.txt",ios::in);
-
read.seekg(
0,ios::beg);
-
cout<<
"请输入账号"<<
endl;
-
cin>>m;
-
cout<<
"请输入密码"<<
endl;
-
cin>>n;
-
while(read>>snum>>spassword)
-
{
-
if(snum==m&&spassword==n)
-
star2();
-
}
-
read.close ();
-
}
-
-
-
-
void menu()
-
{
-
cout<<
"***************欢迎来到猜词游戏**************"<<
endl;
-
cout<<
endl;
-
cout<<
endl;
-
cout<<
"*****************请选择操作******************"<<
endl;
-
cout<<
endl;
-
cout<<
"*****************0.退出游戏******************"<<
endl;
-
cout<<
endl;
-
cout<<
"*****************1.游戏规则******************"<<
endl;
-
cout<<
endl;
-
cout<<
"*****************2.进入游戏******************"<<
endl;
-
cout<<
endl;
-
cout<<
"*****************3.查看词典(仅登陆用户使用)"<<
endl;
-
cout<<
endl;
-
}
-
void instruction()//等到全部做完再写游戏说明
-
{
-
cout<<
"游戏规则:"<<
endl;
-
cout<<
"系统会在储存的单词中随机挑选一个单词并抹去其中一个字母。"<<
endl;
-
cout<<
"你需要猜测“*”部位的字母。"<<
endl;
-
cout<<
"在生词模式下,你可以将词汇加入生词本。"<<
endl;
-
cout<<
"在怀旧模式下,你可以练习曾经错过的词。"<<
endl;
-
cout<<
"玩家登陆有福利可以查看词典哦。"<<
endl;
-
-
}
-
void enter()
-
{
-
cout<<
"*****************1.生词模式******************"<<
endl;
-
cout<<
endl;
-
cout<<
"*****************2.怀旧模式******************"<<
endl;
-
cout<<
endl;
-
cout<<
"*****************0.退出游戏******************"<<
endl;
-
cout<<
endl;
-
int n;
-
while(n)
-
{
-
cout<<
"请选择模式,0退出"<<
endl;
-
cin>>n;
-
system(
"cls");
-
switch(n)
-
{
-
case
1:
-
startgame1();
-
break;
-
case
2:
-
startgame2();
-
break;
-
}
-
-
}
-
-
}
-
void startgame1()
-
{
-
cout<<
"game star~~~~~~~~~~~你,准备好迎接挑战了吗?"<<
endl;
-
srand((
unsigned)time(
0));
-
ifstream in;
-
int ijudge;
-
int iline=
0,irand1,irand2,irand3,isize;
-
int i=
0;
-
char s[
100][
100],*sline,s1,s2;
-
//打开文件并将数据存到数组中
-
in.open(
"d:\\game\\answer.txt",ios::in);
-
if(in)
-
{
-
while(!in.eof())
-
{
-
in>>s[iline];
-
iline++;
-
if(iline>=
100)
-
break;
-
}
-
}
-
else
-
cout<<
"file not found!"<<
endl;
-
-
//随机选一个单词
-
irand1=rand()%iline;
//随机选一个单词
-
isize=
strlen(s[irand1]);
//得到该单词长度
-
srand(
int(time(
0)));
-
irand2=rand()%isize;
//随机选取某个字母位
-
sline=
new
char[irand2];
-
strcpy(sline,s[irand1]);
-
for( i=
0;i<=isize;i++)
-
{
-
if(i==irand2)
-
{
-
s1=s[irand1][irand2];
-
s[irand1][irand2]=
'*';
-
}
-
}
-
-
//开始游戏
-
-
while(
1)
-
{
-
if(i==
0)
-
{
-
i++;
-
}
-
cout<<
endl;
-
cout<<s[irand1]<<
endl;
-
cout<<
endl;
-
cin>>s2;
-
if(s1==s2)
-
{
-
cout<<
"答对啦~~~~"<<
endl;
-
s[irand1][irand2]=s1;
-
}
-
else
-
{
-
cout<<
"答错了,要加油哦QAQ"<<
endl;
-
s[irand1][irand2]=s1;
-
}
-
cout<<
"******是否将该单词加入生词本******"<<
endl;
-
cout<<
"*********1-是,2-否***************"<<
endl;
-
cin>>ijudge;
-
if(ijudge==
1)
-
{
-
ofstream input("d:\\game\\list.txt",ios::app);
-
input<<s[irand1]<<
endl;
-
input.close();
-
}
-
cout<<
"是否继续?1--是,2--否"<<
endl;
-
cin>>ijudge;
-
if(ijudge==
2)
-
break;
-
else
-
{
-
srand(
int(time(
0)));
-
irand1=rand()%iline;
//随机选一个单词
-
isize=
strlen(s[irand1]);
//得到该单词长度
-
srand(
int(time(
0)));
-
irand2=rand()%isize;
//随机选取某个字母位
-
sline=
new
char[irand2];
-
strcpy(sline,s[irand1]);
-
for(
int i=
0;i<=isize;i++)
-
{
-
if(i==irand2)
-
{
-
s1=s[irand1][irand2];
-
s[irand1][irand2]=
'*';
-
}
-
}
-
}
-
-
}
-
in.close();
-
}
-
void startgame2()
-
{
-
cout<<
"game star,温习巩固记忆更强"<<
endl;
-
srand((
unsigned)time(
0));
-
ifstream in;
-
int ijudge;
-
int iline=
0,irand1,irand2,irand3,isize;
-
int i=
0;
-
char s[
100][
100],*sline,s1,s2;
-
//打开文件并将数据存到数组中
-
in.open(
"d:\\game\\list.txt",ios::in);
-
if(in)
-
{
-
while(!in.eof())
-
{
-
in>>s[iline];
-
iline++;
-
if(iline>=
100)
-
break;
-
}
-
}
-
else
-
cout<<
"file not found!"<<
endl;
-
-
//随机选一个单词
-
irand1=rand()%iline;
//随机选一个单词
-
isize=
strlen(s[irand1]);
//得到该单词长度
-
srand(
int(time(
0)));
-
irand2=rand()%isize;
//随机选取某个字母位
-
sline=
new
char[irand2];
-
strcpy(sline,s[irand1]);
-
for( i=
0;i<=isize;i++)
-
{
-
if(i==irand2)
-
{
-
s1=s[irand1][irand2];
-
s[irand1][irand2]=
'*';
-
}
-
}
-
-
//开始游戏
-
-
while(
1)
-
{
-
if(i==
0)
-
{
-
i++;
-
}
-
cout<<
endl;
-
cout<<s[irand1]<<
endl;
-
cout<<
endl;
-
cin>>s2;
-
if(s1==s2)
-
{
-
cout<<
"答对啦~~~~"<<
endl;
-
s[irand1][irand2]=s1;
-
}
-
else
-
{
-
cout<<
"答错了,要加油哦QAQ"<<
endl;
-
s[irand1][irand2]=s1;
-
}
-
cout<<
"是否继续?1--是,2--否"<<
endl;
-
cin>>ijudge;
-
if(ijudge==
2)
-
break;
-
else
-
{
-
srand(
int(time(
0)));
-
irand1=rand()%iline;
//随机选一个单词
-
isize=
strlen(s[irand1]);
//得到该单词长度
-
srand(
int(time(
0)));
-
irand2=rand()%isize;
//随机选取某个字母位
-
sline=
new
char[irand2];
-
strcpy(sline,s[irand1]);
-
for(
int i=
0;i<=isize;i++)
-
{
-
if(i==irand2)
-
{
-
s1=s[irand1][irand2];
-
s[irand1][irand2]=
'*';
-
}
-
}
-
}
-
-
}
-
in.close();
-
}
-
void danci()
-
{
-
char danci[
100],zhongwen[
100];
-
ifstream instuf("d:\\game\\englishi.txt",ios::in);
-
instuf.seekg(
0,ios::beg);
-
if(!instuf)
-
{
-
cout<<
"file could not be open."<<
endl;
-
abort();
-
}
-
while(instuf>>danci>>zhongwen)
-
{
cout<<danci<<
" "<<zhongwen<<
endl;}
-
instuf.close();
-
}
请自己选择路径添加相应的txt文件