学习用C++开发你的第一个游戏(英文)
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200609122627573.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NDEwMzIyMA==,size_16,color_FFFFFF,t_70#pic_center)
# include <iostream>
# include <string> // 引入string 库
using namespace std; // 引入命名空间std,之后的cout 和 endl 就不用再加上std:: 了
void PrintIntro();
void PlayGame();
string GetGuess();
// 程序的入口
int main()
{
PrintIntro();
PlayGame();
return 0;
}
void PlayGame()
{
// 可猜测的循环次数
constexpr int NUMBER_OF_TRUNS = 5;
for (int cout = 1; cout <= NUMBER_OF_TRUNS; ++cout)
{
GetGuess();
}
}
// 介绍游戏
void PrintIntro()
{
constexpr int WORLD_LENGTH = 9; // 定义一个变量让单词的长度可变
cout << "Welocm to Bulls and Cows, a fun word game." << endl;
cout << "Can you guess the " << WORLD_LENGTH;
cout << " letter isogram I'm thinking of?\n";
cout << endl;
return;
}
// 让玩家猜一个
string GetGuess()
{
cout << "输入你猜测的结果: ";
string Guess = "";
getline(cin, Guess);
cout << "你猜测的是:" << Guess << endl;
cout << endl;
return Guess;
}