Summary Files Commits Branches @commit @diff @stats
path: root / Year 1 / Object-oriented Programming / 06-Practice-05.04.2022 / Game.cpp
blob: ae5fcc0fe51f45f128f530dfaa03a91e2d7ec2f0 (plain) (blame)
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
#include "Game.h"

/* Private */

void Game::turn(Player& player, double& bet) {
	std::cout << "Enter command: ";
	char buffer;
	std::cin >> buffer;

	bool result = false;
	for (int i = 0; i < this->caseCount; i++) {
		if (cases[i].get_comm() == buffer) {
			result = cases[i].exec(player, bet);
			break;
		}
	}

	if (result) {
		std::cout << "You win!";
		player.addToBalance("", bet);
	}
	else {
		std::cout << "You lost!";
		player.deductFromBalance("", bet);
	}
	std::cout << " Current balance: " << player.get_balance() << std::endl;
}

/* Public */

Game::Game(const GameCase* cases, unsigned casesCount) {
	this->cases = new GameCase[casesCount];
	for (int i = 0; i < casesCount; i++)
		this->cases[i] = cases[i];
}