-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
105 lines (95 loc) · 2.65 KB
/
main.cpp
File metadata and controls
105 lines (95 loc) · 2.65 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include <iostream>
#include <string>
#include "Game.h"
#include "Parser.h"
using namespace std;
/**
* @namespace jeopardy
* Namespace for the classes that represent clues, categories, and a
* game in jeopardy.
*
* @author Matthew Daly
*/
using namespace jeopardy;
/**
* Main program to run the jeopardy game
* @return the return status, normal is 0
*/
int main()
{
string commands = "Commands:\n b - display board \n"
" s - display score \n"
" c - choose clue \n"
" x - exit\n"
" h - show commands \n";
//take name of file containing html source and parses it into a game
string file;
cout << "Game file: ";
cin >> file;
Parser parser;
Game game = parser.buildGame(file);
cout << game.toString();
cout << commands;
for (;;)
{
//take commands
cout << "input: ";
string input;
cin >> input;
if (input == "x")
{
break;
}
else if (input == "h")
{
cout << commands;
}
else if (input == "b")
{
cout << game.toString();
}
else if (input == "s")
{
cout << game.getPlayerScore() << endl;
}
else if (input == "c")
{
//ask for the category and point value for the clue to be chosen
cout << "Which category? ";
string categoryName;
cin.ignore();
getline(cin, categoryName);
cout << "Point value: ";
string pointVal;
cin >> pointVal;
try
{
//display the clue then ask for an answer
string clue = game.getClue(categoryName, stoi(pointVal));
cout << clue << endl << "Answer: ";
string answer;
cin.ignore();
getline(cin, answer);
string correctAnswer;
if (game.answerClue(categoryName, stoi(pointVal), answer, correctAnswer))
{
cout << "Correct! \nNew Score: " << game.getPlayerScore() << endl;
}
else
{
cout << "Wrong! \nCorrect Answer: " << correctAnswer <<
"\nNew Score: " << game.getPlayerScore() << endl;
}
}
catch (exception& e)
{
cout << e.what() << endl;
}
}
else
{
cout << "Unknown command" << endl;
}
}
return 0;
}