-
Notifications
You must be signed in to change notification settings - Fork 0
/
Core.cpp
89 lines (75 loc) · 1.63 KB
/
Core.cpp
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "Core.hpp"
namespace Core {
Player::Player* Core::GetPlayer()
{
return Player;
}
Croupier::Croupier* Core::GetCroupier()
{
return Croupier;
}
vector<Bet::Bet*>* Core::GetBets()
{
return Bets;
}
void Core::NewBet(float baseBet)
{
if (!CanNewBet(baseBet))
throw new runtime_error("New game can't be started!");
Hand::Hand* playerHand = Croupier->NewGame();
Player->AddHand(playerHand);
Bets->push_back(new Bet::Bet(baseBet, playerHand, Croupier->GetCroupierHand()));
Player->Withdrawal(baseBet);
}
bool Core::CanNewBet(float baseBet)
{
return Bets->size() < 1 && Player->CanWithdrawal(baseBet);
}
void Core::Hit(Bet::Bet* bet)
{
if (!bet->CanHit())
throw new runtime_error("Hit can't be used!");
bet->Hit(Croupier->DrawCard());
UpdateGame();
}
void Core::Stand(Bet::Bet* bet)
{
if (!bet->CanStand())
throw new runtime_error("Stand can't be used!");
bet->Stand();
UpdateGame();
}
void Core::Double(Bet::Bet* bet)
{
if (!bet->CanDouble(Player))
throw new runtime_error("Double can't be used!");
bet->Double(Player, Croupier->DrawCard());
UpdateGame();
}
void Core::Split(Bet::Bet* bet)
{
if (!bet->CanSplit(Player))
throw new runtime_error("Split can't be used!");
Bets->push_back(bet->Split(Player));
UpdateGame();
}
void Core::UpdateGame()
{
for (Bet::Bet* bet : *Bets)
if (!bet->IsStop())
return;
Croupier->FillCroupierHand();
for (Bet::Bet* bet : *Bets)
Player->GiveBet(bet);
Bets->clear();
Player->ClearHands();
}
Core::~Core()
{
delete Player;
delete Croupier;
for (Bet::Bet* bet : *Bets)
delete bet;
delete Bets;
}
}