From 4d8ad3bb2ecc38e95c3b6b60972ec3c4c97629ac Mon Sep 17 00:00:00 2001 From: Relintai Date: Mon, 29 Mar 2021 11:50:44 +0200 Subject: [PATCH] Small fixes, and implemented player personalities. --- 03_monopoly/player.cpp | 21 +++++++++++++++++---- 03_monopoly/tile.cpp | 2 +- 03_monopoly/tiles.config | 8 ++++++++ 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/03_monopoly/player.cpp b/03_monopoly/player.cpp index 69814eb..d32b95c 100644 --- a/03_monopoly/player.cpp +++ b/03_monopoly/player.cpp @@ -4,6 +4,8 @@ #include "math.h" +#include + String Player::get_name() { return _name; } @@ -101,7 +103,7 @@ Player::~Player() { } bool AgressivePlayer::want_buy(const String &tile_name, int price) { - return false; + return true; } void AgressivePlayer::on_lose() { printf("Player - %s has lost the game. And he's angry.\n", _name.c_str()); @@ -114,9 +116,14 @@ AgressivePlayer::AgressivePlayer() : } bool ConservativePlayer::want_buy(const String &tile_name, int price) { + if (price < _money / 2) { + return true; + } + return false; } void ConservativePlayer::on_lose() { + printf("Player - %s has lost the game.\n", _name.c_str()); } String ConservativePlayer::get_class_name() { return "ConservativePlayer"; @@ -126,7 +133,7 @@ ConservativePlayer::ConservativePlayer() : } bool TrickyPlayer::want_buy(const String &tile_name, int price) { - return false; + return Math::rand(2) == 0 ? true : false;; } void TrickyPlayer::on_lose() { printf("Player - %s has lost the game.\n", _name.c_str()); @@ -139,7 +146,13 @@ TrickyPlayer::TrickyPlayer() : } bool HumanPlayer::want_buy(const String &tile_name, int price) { - return false; + bool w = false; + + printf("Player - %s do you want to buy %s for %d? You have %d dollars.\n", _name.c_str(), tile_name.c_str(), price, _money); + + std::cin >> w; + + return w; } void HumanPlayer::on_lose() { printf("Player - %s has lost the game. And he's really sad.\n", _name.c_str()); @@ -152,7 +165,7 @@ HumanPlayer::HumanPlayer() : } bool CheatingPlayer::want_buy(const String &tile_name, int price) { - return false; + return true; } int CheatingPlayer::throw_dice() { int t = Math::rand(3, 7); diff --git a/03_monopoly/tile.cpp b/03_monopoly/tile.cpp index 557bf92..03c1ec3 100644 --- a/03_monopoly/tile.cpp +++ b/03_monopoly/tile.cpp @@ -13,7 +13,7 @@ void Tile::set_name(const String &name) { } void Tile::on_player_arrived(Player *p) { - printf("Player %s just stepped on %s.\n", p->get_name().c_str(), _name.c_str()); + printf("Player - %s just stepped on %s.\n", p->get_name().c_str(), _name.c_str()); } void Tile::reset() { diff --git a/03_monopoly/tiles.config b/03_monopoly/tiles.config index e60d608..e2cbafc 100644 --- a/03_monopoly/tiles.config +++ b/03_monopoly/tiles.config @@ -2,6 +2,14 @@ Tile Asf TaxTile aAA 3433 TaxTile dqdq 3433 OwnableTile fqfqfdg 222 22 +OwnableTile Adad 222 22 +OwnableTile ddd 222 22 +OwnableTile eee 222 22 +OwnableTile qwe 222 22 +OwnableTile ewew 222 22 +OwnableTile ttt 222 22 +OwnableTile qtt 222 22 +OwnableTile qqq 222 22 GainTile fffqq 100 TaxTile aArrrrA 3433 LuckTile Qewew 50 100 200