Skip to content

Commit 41625ba

Browse files
authored
Add files via upload
1 parent 43fd9f3 commit 41625ba

File tree

7 files changed

+283
-0
lines changed

7 files changed

+283
-0
lines changed

Card Game Files/Card.cpp

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#include "Card.h"
2+
3+
card::card()
4+
{
5+
value = 0;
6+
suit = 'X';
7+
}
8+
9+
card::card(int v, char s)
10+
{
11+
value = v;
12+
suit = s;
13+
}
14+
15+
int card::getValue() const
16+
{
17+
return value;
18+
}
19+
20+
char card::getSuit() const
21+
{
22+
return suit;
23+
}
24+
25+
void card::setValue(int v)
26+
{
27+
value = v;
28+
}
29+
30+
void card::setSuit(char s)
31+
{
32+
suit = s;
33+
}
34+
35+
bool card::operator>(const card & c) const
36+
{
37+
if (value > c.getValue())
38+
return true;
39+
if (value < c.getValue())
40+
return false;
41+
if (suit == 's')
42+
return true;
43+
if (suit == 'h'&& c.getSuit() != 's')
44+
return true;
45+
if (suit == 'd' && c.getSuit() != 'c')
46+
return false;
47+
if (suit == 'c')
48+
return false;
49+
if (suit == 'd' && c.getSuit() =='c')
50+
return true;
51+
if (suit == 'h' && c.getSuit() =='s')
52+
return false;
53+
54+
}

Card Game Files/Card.h

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#pragma once
2+
#include <iostream>
3+
4+
using namespace std;
5+
6+
class card {
7+
8+
private:
9+
int value;
10+
char suit;
11+
12+
public:
13+
card();
14+
card(int v, char s);
15+
int getValue()const;
16+
char getSuit()const;
17+
void setValue(int v);
18+
void setSuit(char s);
19+
bool operator>(const card & t)const;
20+
21+
friend ostream& operator<<(ostream& out, const card& c) {
22+
// if (c.getValue() > 11)
23+
out << "Value: " << c.getValue() << " " << "Suit: " << c.getSuit();
24+
// else if (c.getValue() == 11)
25+
// out << "Value: " << "Jack" << " " << "Suit: " << c.getSuit();
26+
// else if (c.getValue() == 12)
27+
// out << "Value: " << "Queen" << " " << "Suit: " << c.getSuit();
28+
// else if (c.getValue() == 13)
29+
// out << "Value: " << "King" << " " << "Suit: " << c.getSuit();
30+
// else if (c.getValue()) == 14)
31+
// out << "Value: " << "Ace" << " " << "Suit: " << c.getSuit();
32+
return out;
33+
}
34+
35+
36+
37+
};

Card Game Files/Deck.cpp

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#include "Deck.h"
2+
#include <ctime>
3+
4+
void Deck::buildDeck()
5+
{
6+
for (int i = 2; i <= 14; i++) {
7+
theDeck.push_back(card(i, 'c'));
8+
theDeck.push_back(card(i, 'h'));
9+
theDeck.push_back(card(i, 'd'));
10+
theDeck.push_back(card(i, 's'));
11+
}
12+
}
13+
14+
Deck::Deck()
15+
{
16+
buildDeck();
17+
}
18+
19+
void Deck::shuffle()
20+
{
21+
srand(time(NULL));
22+
for (int i = theDeck.size() - 1; i > 0; i--) {
23+
int j = rand() % (i + 1);
24+
//This is where we will swap the positions of the card
25+
card temp = theDeck[i];
26+
theDeck[i] = theDeck[j];
27+
theDeck[j] = temp;
28+
}
29+
}
30+
31+
card Deck::dealCard()
32+
{
33+
return theDeck[0];
34+
}
35+
36+
void Deck::burnCard()
37+
{
38+
theDeck.erase(theDeck.begin());
39+
}
40+
41+
42+
bool Deck::emptyDeck()
43+
{
44+
if (theDeck.size() == 0)
45+
return true;
46+
else
47+
return false;
48+
}

Card Game Files/Deck.h

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#pragma once
2+
#include <iostream>
3+
#include <vector>
4+
#include "Card.h"
5+
#include <ctime>
6+
7+
using namespace std;
8+
9+
class Deck {
10+
11+
private:
12+
vector<card>theDeck;
13+
void buildDeck();
14+
public:
15+
Deck();
16+
void shuffle();
17+
card dealCard();
18+
void burnCard();
19+
bool emptyDeck();
20+
21+
};

Card Game Files/Hand.cpp

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include "Hand.h"
2+
#include "Deck.h"
3+
#include "Card.h"
4+
5+
Hand::Hand()
6+
{
7+
myHand;
8+
}
9+
10+
void Hand::pickUpCard(card c)
11+
{
12+
myHand.push_back(c);
13+
}
14+
15+
card Hand::playCard()
16+
{
17+
return myHand[0];
18+
}
19+
20+
void Hand::burnMyCard()
21+
{
22+
myHand.erase(myHand.begin());
23+
}
24+
25+
bool Hand::emptyHand()
26+
{
27+
if (myHand.size() == 0)
28+
return true;
29+
else
30+
return false;
31+
}

Card Game Files/Hand.h

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#pragma once
2+
#include <iostream>
3+
#include "Card.h"
4+
#include "Deck.h"
5+
#include <vector>
6+
7+
using namespace std;
8+
9+
class Hand {
10+
11+
private:
12+
vector<card>myHand;
13+
14+
15+
public:
16+
Hand();
17+
void pickUpCard(card c);
18+
card playCard();
19+
void burnMyCard();
20+
bool emptyHand();
21+
22+
23+
24+
25+
};

Card Game Files/Source.cpp

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
//Dennis Canar
2+
//10-8-17
3+
//CST-210 Fritz
4+
//This is my work
5+
6+
#include <iostream>
7+
#include <vector>
8+
#include "Card.h"
9+
#include "Deck.h"
10+
#include "Hand.h"
11+
12+
using namespace std;
13+
14+
int main(){
15+
16+
Deck d;
17+
Hand p1, p2;
18+
card c;
19+
int p1Points = 0;
20+
int p2Points = 0;
21+
d.shuffle();
22+
d.shuffle();
23+
24+
//This is where we split the Deck to both the players hands
25+
while (d.emptyDeck() == false) {
26+
c = d.dealCard();
27+
p1.pickUpCard(c);
28+
d.burnCard();
29+
c = d.dealCard();
30+
p2.pickUpCard(c);
31+
d.burnCard();
32+
}
33+
//This is the actual game play and printing occurs
34+
while (p1.emptyHand()==false && p2.emptyHand() == false) {
35+
cout << "Player One " << p1.playCard() << " V.S. " << "Player Two " << p2.playCard() << endl;
36+
37+
//This is where we will count the points for the number of rounds won
38+
if (p1.playCard() > p2.playCard() == true) {
39+
p1Points++;
40+
cout << "Player 1 Wins Round" << endl;
41+
}
42+
43+
//Player Two Wins
44+
if (p1.playCard() > p2.playCard() == false) {
45+
p2Points++;
46+
cout << "Player 2 Wins Round" << endl;
47+
}
48+
49+
//Remove card from both hands
50+
p1.burnMyCard();
51+
p2.burnMyCard();
52+
}
53+
54+
55+
//End Game Results, who wins?
56+
if (p2.emptyHand() == true) {
57+
if (p1Points > p2Points)
58+
cout << "Player One Wins With " << p1Points << " Points" << "| Player Two Loses With " << p2Points << " Points" << endl;
59+
else if (p1Points == p2Points)
60+
cout << "It's a Tie!!!" << endl;
61+
else if (p1Points < p2Points)
62+
cout << "Player Two Wins With " << p2Points << " Points" << "| Player One Loses With "<< p1Points << " Points" <<endl;
63+
}
64+
65+
66+
67+
}

0 commit comments

Comments
 (0)