forked from trinhvua1/AdvProg_L3-HangMan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
56 lines (43 loc) · 1.56 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
#include <string>
#include <vector>
#include <ctime>
#include <stdexcept>
#include <algorithm>
#include "hangman.h"
#include "draw.h"
int main()
{
srand((int)time(0));
string vocabularyFile = "data/Ogden_Picturable_200.txt";
//string vocabularyFile = "data/ErrorOpenFileTest.txt";
//string vocabularyFile = "data/EmptyTest.txt";
vector<string> wordList;
try {
wordList = readWordListFromFile(vocabularyFile);
} catch (domain_error) {
cout << endl << "Error: in reading vocabulary file: " << vocabularyFile << endl;
return 1;
}
int index = generateRandomNumber(0, wordList.size()-1);
string word = chooseWordFromList(wordList, index);
if (word.empty()) {
cout << "Error: Coud not choose a random word." << endl;
return 1;
}
//cout << "Chosen word: " << word << endl;
// string secretWord(word.length(), '-');
string secretWord = generateHiddenCharacters(word);
int incorrectGuess = 0;
string correctChars = "";
string incorrectChars = "";
printScreen(word, secretWord, correctChars, incorrectGuess, incorrectChars);
do {
char ch = getInputCharacter();
processData(ch, word, secretWord,
correctChars, incorrectGuess, incorrectChars);
printScreen(word, secretWord, correctChars, incorrectGuess, incorrectChars);
} while (secretWord != word && incorrectGuess != MAX_MISTAKES-1);
playAnimation(word, secretWord, correctChars, incorrectGuess, incorrectChars);
return 0;
}