-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathguess.cpp
More file actions
57 lines (39 loc) · 1.19 KB
/
Copy pathguess.cpp
File metadata and controls
57 lines (39 loc) · 1.19 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
#include "games.h"
#include "info.h"
#include "player.h"
#include "misc.h"
#include <iostream>
// Guess game loop controller
Info runGuess(const Player& firstPlayer, const Player& secondPlayer) {
Info info{ nullptr, nullptr };
header("Guess");
const int a{ inputInt("Choose 'a': ") };
const int b{ inputInt("Choose 'b': ") };
const int number{ nextInteger(a, b) };
std::cout << "\n- It was picked an integer number between " << a << " and " << b << ". Who guesses it first wins!\n\n";
const Player* turn{ &firstPlayer };
int guess{};
do {
std::cout << turn->name << ", your guess: ";
if (!isComputer(*turn)) {
guess = inputInt();
} else {
guess = nextInteger(a, b);
std::cout << guess << '\n';
}
if (guess > number) {
std::cout << "it's a bit smaller...\n\n";
} else if (guess < number) {
std::cout << "it's a bit bigger...\n\n";
} else {
std::cout << "THAT'S RIGHT! IT'S " << number << "\n";
std::cout << turn->name << " wins!\n";
bigDivision();
info.winner = turn;
info.loser = &((turn == &firstPlayer) ? secondPlayer : firstPlayer);
break;
}
turn = &((turn == &firstPlayer) ? secondPlayer : firstPlayer);
} while (true);
return info;
}