日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

C++猜单词游戏

發布時間:2025/3/11 c/c++ 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C++猜单词游戏 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

游戲說明

運行須知:

??請將壓縮文件中的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文件

    總結

    以上是生活随笔為你收集整理的C++猜单词游戏的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。