-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTable.cpp
More file actions
executable file
·45 lines (34 loc) · 914 Bytes
/
Table.cpp
File metadata and controls
executable file
·45 lines (34 loc) · 914 Bytes
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
#include <iostream>
#include "Table.h"
Table::Table() {
}
bool Table::win(const Card &card) {
/* Puts the card on the table and checks if it wins */
cards.push_back(card);
for (int i = 0; i < (cards.size() - 1); i++)
if (card.getRank() == cards[i].getRank())
return true;
return false;
}
vector<Card> Table::getCards() {
/* Returns the cards, including the winning one */
vector<Card> result;
for (int i = 0; i < cards.size(); i++) {
if (cards[i].getRank() == cards.back().getRank()) {
result.assign(cards.begin() + i, cards.end());
cards.erase(cards.begin() + i, cards.end());
break;
}
}
return result;
}
void Table::show() {
/* Displays the cards on table */
cout << "TABLE: ";
if (!cards.size()) cout << "EMPTY";
for (int i = 0; i < cards.size(); i++) {
if (i) cout << '|';
cout << cards[i].asString();
}
cout << endl;
}