#include <iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<ctime>
#include<cctype>
using namespace std;
int main()
{
//set up
const int MAX_WRONG=8;
vector<string>words;
/* words.push_back("GUESS");
words.push_back("HANGMAN");
words.push_back("DIFFICULT");*/
words.push_back("YES");
srand(static_cast<unsigned int>(time(0)));
random_shuffle(words.begin(),words.end());
const string THE_WORD=words[0];
int wrong=0;
string soFar(THE_WORD.size(),'-');
string used=" ";
cout<<"Welcone to Hangman.Good luck!\n";
//main loop
while((wrong <MAX_WRONG)&&(soFar!=THE_WORD))
{
cout<<"\n\nYou hace"<<(MAX_WRONG - wrong);
cout<<"incorrent guesses left\n";
cout<<"您使用以下字母"<<used<<endl;
cout<<"\n到目前为止,这个词是"<<soFar<<endl;
char guess;
cout<<"输入您的猜测"<<endl;
cin>>guess;
guess=toupper(guess);
while(used.find(guess)!=string::npos)
{
cout<<"您已经猜到了"<<endl;
cout<<"Enter your guess";
cin>>guess;
guess=toupper(guess);
}
used+=guess;
if(THE_WORD.find(guess)!=string::npos)
{
cout<<"That's right"<<guess<<"is in the word.\n";
for(int i=0;i<THE_WORD.length();i++)
{
if(THE_WORD[i]==guess)
{
soFar[i]=guess;
}
}
}
else
{
cout<<"Sorry,"<<guess<<"isn't in the word\n";
++wrong;
}
}
//shut down
if(wrong==MAX_WRONG)
{
cout<<"\n你是被绞死的"<<endl;
}
else
{
cout<<"\n你猜对了"<<endl;
}
cout<<"这个词是"<<THE_WORD<<endl;
return 0;
}
c++小游戏 随机选取单词,猜单词背单词
最新推荐文章于 2024-04-10 15:13:24 发布