Summary Files Commits Branches @commit @diff @stats
path: root / Year 1 / Object-oriented Programming / 06-Practice-05.04.2022 / Game.cpp
diff options
context:
space:
mode:
Commite9f62e28a4de3f9051da9b437bd6130328de2d90 (patch)
Author
 Syndamia <kamen.d.mladenov@protonmail.com>
2022-04-05 21:32:06 +0300
Committer
 Syndamia <kamen.d.mladenov@protonmail.com>
2022-04-05 21:32:06 +0300
Files4a78d585bf59f69f5070a0ddd7b8d5c731982012 /Year 1/Object-oriented Programming/06-Practice-05.04.2022/Game.cpp
uni-projects-e9f62e28a4de3f9051da9b437bd6130328de2d90.tar
uni-projects-e9f62e28a4de3f9051da9b437bd6130328de2d90.tar.gz
uni-projects-e9f62e28a4de3f9051da9b437bd6130328de2d90.zip
Parent51ff352a533ff14e9961deb642d110f2d5dc843c (diff)
Added todays oop practice work
1 files changed, 37 insertions, 0 deletions
-rw-r--r--Year 1/Object-oriented Programming/06-Practice-05.04.2022/Game.cpp37
diff --git a/Year 1/Object-oriented Programming/06-Practice-05.04.2022/Game.cpp b/Year 1/Object-oriented Programming/06-Practice-05.04.2022/Game.cpp
new file mode 100644
index 0000000..ae5fcc0
--- /dev/null
+++ b/Year 1/Object-oriented Programming/06-Practice-05.04.2022/Game.cpp
@@ -0,0 +1,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];
+}
+
+