L5A/GuessTheNumberRoom.cpp

45 lines
1.1 KiB
C++
Raw Permalink Normal View History

2024-11-06 17:02:03 -07:00
#include "GuessTheNumberRoom.h"
#include <iostream>
#include <random>
using namespace std;
// I modified this constructor to take in a mersenne twister as it
// by default was using rand(), and that was always returning 4.s
GuessTheNumberRoom::GuessTheNumberRoom(mt19937& mt) {
cout << "GuessTheNumberRoom() called" << endl;
mRoomName = "Guess The Number Room";
uniform_int_distribution<int> numberDist(0, 20);
_secretNumber = numberDist(mt);
}
GuessTheNumberRoom::~GuessTheNumberRoom() {
cout << "~GuessTheNumberRoom() called" << endl;
}
bool GuessTheNumberRoom::escapeTheRoom() {
int guess;
uint8_t guesses_used = 0;
while (guesses_used < 5) {
cout << "Please enter a guess for the number: ";
cin >> guess;
guesses_used++;
if (guess == _secretNumber) {
cout << "That number was correct!" << endl;
return true;
}
if (guess < _secretNumber) {
cout << "That guess was too low." << endl;
} else {
cout << "That guess was too high." << endl;
}
}
return false;
}