-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame.cpp
More file actions
85 lines (73 loc) · 1.81 KB
/
Copy pathGame.cpp
File metadata and controls
85 lines (73 loc) · 1.81 KB
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
#include <iostream>
#include "Game.h"
#include <vector>
using namespace std;
void Game::play()
{
//dealing initial cards
for (int turn{0}; turn < turns; turn++)
{
pile.deal(players[turn]);
pile.deal(players[turn]);
}
pile.deal(host);
pile.deal(host);
host.flipFirstCard();
//displaying initial cards
displayPlayers();
//hitting
for (int turn{0}; turn < turns; turn++)
pile.additionalCards(players[turn]);
host.flipFirstCard();
host.display();
if (!host.isBusted())
pile.additionalCards(host);
//change winning announcements
if (host.isBusted())
{
for (int turn{0}; turn < turns; turn++)
{
if (!players[turn].isBusted())
players[turn].win();
}
cout << endl;
} else {
for (int turn{0}; turn < turns; turn++)
{
if (!players[turn].isBusted())
{
if (players[turn].getTotal() > host.getTotal())
players[turn].win();
else if (players[turn].getTotal() < host.getTotal()){
players[turn].lose();
} else
players[turn].push();
}
}
}
for (int i{0}; i < players.size(); i++)
players[i].clear();
pile.setLoc(0);
pile.shuffle();
}
Game::Game(int n, House h, Deck p)
{
host = h;
turns = n;
pile = p;
}
void Game::addPlayer(Player person)
{
players.push_back(person);
}
void Game::printPlayers()
{
for (auto elem: players)
cout << elem.name << endl;
}
void Game::displayPlayers() const
{
for (int turn{0}; turn < turns; turn++)
players[turn].display();
host.display();
}