//------------------------------------------------------------------- // File :getWords.C // Author :Alicia Thorsen // Course :CS1129 // // Functions which handle getting the words from the user. //------------------------------------------------------------------- #include "getWords.h" #include "strCaseConvert.h" #include "dictionary.h" #include #include #include using namespace std; //------------------------------------------------------------------- // Precondition :The board was loaded // Postcondition :Returns the words entered by the user //------------------------------------------------------------------- string* getWords(char board[][SIZE], int & wordCt) { //An initial estimation for # of words a user might find int capacity = 10; string input, blank; int i = 0; int endTime, timeLeft = 180; bool done = false; string* words = new string[capacity]; showTimeLeft(timeLeft); displayBoard(board); cout << "\nEnter your words here. Press enter after each word."; cout << "\n>> "; //Give user 3 mins endTime = time(0) + timeLeft; cin >> input; while (!done) { //Update time timeLeft = endTime - time(0); if (timeLeft > 0) { if (i == capacity) words = resize(words, capacity); words[i] = toLowerCase(input); i++; } else { timeLeft = 0; done = true; } system("clear"); showTimeLeft(timeLeft); displayBoard(board); cout << "\nEnter your words here. Press enter after each word. "; //Display all previously entered words for (int k = 0; k < i; k++) cout << "\n>> " << words[k]; cout << "\n>> "; //If time has not run out get another word //Otherwise display the last word entered if (timeLeft > 0) cin >> input; else cout << input; } cout << "\n\nTIME UP!" << endl; cout << "\nPress enter to see your score ..."; //Discard newline left by >> getline(cin, blank); //Read in newline entered by user getline(cin, blank); wordCt = i; return words; }//getWords() //------------------------------------------------------------------- // Precondition :None // Postcondition :Shows the time left in the game //------------------------------------------------------------------- void showTimeLeft(int timeLeft) { cout << "TIME LEFT: " << timeLeft/60 << ":"; if ((timeLeft % 60) < 10) cout << "0"; cout << timeLeft % 60 << endl; }