学习用C++开发你的第一个游戏(英文)
# include <iostream>
# include <string> // 引入string 库
using namespace std; // 引入命名空间std,之后的cout 和 endl 就不用再加上std:: 了
void PrintIntro();
string GetGuessAndPrintBack();
// 程序的入口
int main()
{
PrintIntro();
// 可猜测的循环次数
constexpr int NUMBER_OF_TRUNS = 5;
for (int cout = 1; cout <= NUMBER_OF_TRUNS; ++cout)
{
GetGuessAndPrintBack();
cout << endl;
}
return 0;
}
// 介绍游戏
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 GetGuessAndPrintBack()
{
cout << "输入你猜测的结果: ";
string Guess = "";
getline(cin, Guess);
//
cout << "你猜测的是:" << Guess << endl;
return Guess;
}