我正在制作一个刽子手游戏,但其中的一部分有问题。
我从文件中选择了一个随机单词,但我想将该单词显示为一系列下划线_ _,然后将所选字母与下划线中的位置相匹配。
cout <<"1. Select to play the game\n";
cout <<"2. Ask for help\n";
cout <<"3. Select to quit the game\n";
cout << "Enter a selection: ";
int number;
cin >> number;
while(number < 1 || number > 3 || cin.fail())
{
if(cin.fail())
{
cin.sync();
cin.clear();
cout << "You have not entered a number, please enter a menu selection between 1 and 3\n";
cin >> number;
}
else
{
cout << "Your selection must be between 1 and 3!\n";
cin >> number;
}
}
switch (number)
{
case 1:
{
string word;
string name;
cout << " Whats your name? ";
cin >> name;
Player player();
ifstream FileReader;
FileReader.open("words.txt");
if(!FileReader.is_open())
cout << "Error";
//this is for the random selection of words
srand(time(0));
int randnum = rand()%10+1;
for(int counter = 0; counter < randnum; counter++)
{
getline(FileReader, word, '\n');
}
cout << "my word: " << word << "\n";
// get length of word
int length;
//create for loop
for(int i = 0; i < length; i++)
cout << "_";
//_ _ _ _ _
SetCursorPos(2,10);
FileReader.close();
break;