-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScoreKeeper.cpp
68 lines (53 loc) · 1.63 KB
/
ScoreKeeper.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
57
58
59
60
61
62
63
64
65
66
67
#include <iostream>
#include <string>
#include <ctime>
#include <vector>
#include "Jotto_utils.h"
#include "Guesser.h"
#include "ScoreKeeper.h"
using namespace std;
/********************** CONSTRUCTORS ************************/
ScoreKeeper::ScoreKeeper(Guesser *g1, Guesser *g2)
{
string n1 = g1->get_player();
string n2 = g2->get_player();
codewords[n1] = solicit_codeword(g2); // get codeword g1 tries to guess
codewords[n2] = solicit_codeword(g1); // get codeword g2 tries to guess
}
/***************** Actions ********************/
bool ScoreKeeper::give_turn_to(Guesser *g)
{
cout << "---------- Turn: " << g->get_player() << " -----------" << endl;
return submit_score(solicit_guess(g), g);
}
string ScoreKeeper::solicit_codeword(Guesser *g) const
{
return g->submit_codeword();
}
string ScoreKeeper::solicit_guess(Guesser *g) const // ask guesser to submit a guess
{
return g->guess();
}
bool ScoreKeeper::submit_score (const string& guess, Guesser *g)// submit score of string to guesser
{
if (codewords[g->get_player()] == guess)
{
cout << endl;
cout << "!!! " << g->get_player() << " GUESSED " << guess;
cout << " AND WON !!!" << endl;
return false;
}
int s = score(guess, codewords[g->get_player()]);
g->add_guess(guess, s);
g->print_guesses();
return true;
}
/******************* Print *******************/
void ScoreKeeper::print_codewords () const
{
for (map<string, string>::const_iterator it = codewords.begin();
it != codewords.end(); ++it)
{
cout << it->first << " :: " << it->second << endl;
}
}