-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.cpp
More file actions
104 lines (89 loc) · 1.99 KB
/
Copy pathPlayer.cpp
File metadata and controls
104 lines (89 loc) · 1.99 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include "Player.h"
#include "Card.h"
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
Player::Player() // Default constructor, just to intialize them to something until they're assigned proper values
{
this->pl = NULL;
this->ID = -1;
};
Player::Player(Player** pl, int ID) // Give each player their pointer to the previous player and a unique ID#
{
this->pl = pl;
this ->ID = ID;
}
Player::~Player()
{
pl = NULL;
delete pl;
};
vector<Card> Player::getHand()
{
return hand;
};
void Player::initCheckPairs() // Used ONCE at the start of the game to remove any pairs they may have after being dealt their hand
{
for (int i = 0; i < hand.size(); i++)
{
for (int j = i+1; j < hand.size(); j++)
{
if (hand[i] == hand[j])
{
hand.erase(hand.begin() + j);
hand.erase(hand.begin() + i);
j--;
}
}
};
};
// What we use AFTER they have discarded all intial pairs
// Checks incoming card against the card in their hand. If the numbers match, discard the pair, if not, add the card to the hand.
void Player::checkPairs(Card& taken)
{
for (int i = 0; i < hand.size(); i++)
{
if (hand[i] == taken)
{
hand.erase(hand.begin() + i);
return;
}
}
hand.push_back(taken);
};
void Player::giveCard(Card& card)
{
hand.push_back(card);
};
ostream& operator<<(ostream& out, Player& players) // Prints out each players hand, what kind of player they are, and their unique ID
{
out << "Player ID: " << players.ID << endl;
out << players.type() << endl;
auto printHand = [&out](Card& card1) { out << card1.getType() << card1.getNumber() << " "; };
for_each(players.hand.begin(), players.hand.end(), printHand);
if (players.hand.size() == 0)
{
out << "empty";
}
out << endl;
return out;
};
void Player::cardRemove(Card& card)
{
checkPairs(card);
};
void Player::shuffleHand()
{
random_shuffle(hand.begin(), hand.end());
};
Card& Player::getCard(int cdNum)
{
Card temp = hand[cdNum];
cardRemove(temp);
return temp;
};
int Player::getID()
{
return ID;
};