This repository was archived by the owner on May 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHand.cpp
More file actions
50 lines (43 loc) · 1.22 KB
/
Hand.cpp
File metadata and controls
50 lines (43 loc) · 1.22 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
#include "Hand.h"
/* Constructor which accepts an istream and reconstruct the Hand from file.*/
Hand::Hand(istream& in, const CardFactory* set) {
}
/* Adds the card to the rear of the hand.*/
Hand& Hand::operator+=(Card* c) {
hand.push_back(c);
return *this;
}
/* Returns and removes the top card from the player's hand.*/
Card* Hand::play() {
Card* tmp = nullptr;
if (!hand.empty()) {
tmp = hand.front();
hand.pop_front();
}
return tmp;
}
/* Returns but does not remove the top card from the player's hand.*/
Card* Hand::top() {
return hand.front();
}
/* Returns and removes the Card at a given index.*/
Card* Hand::operator[](int index) {
// Creates a record of the Card at the given index.
Card* tmp = hand.front() + index;
if (!hand.empty() && hand.size() >= unsigned(index)) {
list<Card*>::iterator it = hand.begin();
advance(it, index);
// Erases the Card at the given index.
hand.erase(it);
}
return tmp;
}
/* To insert all the cards in the Hand to an ostream.*/
void print(ostream& out, Hand& h) {
out << "Current Hand: ";
for (auto& card : h.getHand()) {
card->print(out);
cout << " ";
}
out << "" << endl;
}