Пример #1
0
/**
 * @brief promptplayerInput asks the player to type in a valid word
 * @param boggle
 */
void promptplayerInput(Boggle& boggle){
    Lexicon lex("EnglishWords.dat");
    string tempWord;

    cout << "It's your turn!" << endl;

    printGrid(boggle);

    printPlayerWords(boggle);

    cout << "Your score: " << boggle.getPlayerScore() << endl;
    cout << "Type a word (or press 1 to quit): ";

    cin >> tempWord;
    //makes the str uppercase
    transform(tempWord.begin(), tempWord.end(),tempWord.begin(), ::toupper);
    clearConsole();
    while(tempWord != "1"){

        printGrid(boggle);

        if(!lex.contains(tempWord)){
            cout << "Not a word in the dictionary" << endl;
        }
        else if (!(boggle.getPlayerWords().find(tempWord) != boggle.getPlayerWords().end())) {
            cout << "Word already used" << endl;
        }
        else if ((tempWord.size() < 4)) {
            cout << "Word is too small" << endl;
        }
        else if (!(boggle.findWordInGrid(tempWord))) {
            cout << "That word can't be formed on this board." << endl;
        }
        else {
            boggle.updateScore(tempWord);
            boggle.insertplayerWord(tempWord);
        }

        printPlayerWords(boggle);

        cout << endl;
        cout << "Your score: " << boggle.getPlayerScore() << endl;

        cout << "Type a word (or press 1 to quit): ";
        cin >> tempWord;

        clearConsole();
        //makes the str uppercase
        transform(tempWord.begin(), tempWord.end(),tempWord.begin(), ::toupper);
    }
}
Пример #2
0
/**
 * @brief printPlayerWords outputs the words that the player has found
 * @param boggle
 */
void printPlayerWords(Boggle& boggle) {
    set<string> playerWords = boggle.getPlayerWords();
    cout << "Your words (" <<  playerWords.size() << "):";

    for(set<string>::iterator it = playerWords.begin(); it != playerWords.end(); it++){
        cout << *it << " ";
    }

    cout << endl;
}