Poker Game

barcagirl95

Junior Member
May 9, 2015
1
0
0
For my final project I am working on a card game using c++. And I am stuck. We have to use unicode and be able to display the cards next to each other.
The cards need to be printed in the format of an actual card using lines and unicode. I am stuck on this first part of the project being able to display the cards next to each other. When this is tested it should create a card object, shuffle cards, and display 2 cards, than 3 than 5 cards. I just get a lot of errors. Please help!

my card.h class looks like this
#ifndef CARD_H
#define CARD_H

const char spade[4]="\xe2\x99\xa0";
const char club[4]="\xe2\x99\xa3";
const char heart[4]="\xe2\x99\xa5";
const char diamond[4]="\xe2\x99\xa6";

class Card{



struct ACard{
int Num;
char Pic[4];
};

private:
ACard *Cards [52];
int nextCard;

public:
Card();
void ShuffleCard();
ACard getCard();
void printCard()
//13 void functions to display cards
void CardAce(const char Pic);
void CardTwo(const char Pic);
void CardThree(const char Pic);
void CardFour(const char Pic);
void CardFive(const char Pic);
void CardSix(const char Pic);
void CardSeven(const char Pic);
void CardEight(const char Pic);
void CardNine(const char Pic);
void CardTen(const char Pic);
void CardJack(const char Pic);
void CardQueen(const char Pic);
void CardKing(const char Pic);



};

#endif

//////////////////////////////////////////////////////////////////////////////
and the card. cpp class looks like this
//Card.cpp

#include <ctime>
#include <cstdlib>
#include "Card.h"
#include <iostream>
#include <iomanip>

using namespace std;

Card::Card(){
nextCard=0;
//spade cards
for(int i=1; i<=13; i++){
Cards[i-1]-> Num= i;
Cards[i-1]-> Pic=spade;
}
//club cards
for(int i=1; i<=13; i++){
int x=13;
Cards[x]-> Num= i;
Cards[x]-> Pic= club;
x++;
}

//hearts
for(int i=1; i<=13; i++){
int x=26;
Cards[x]-> Num= i;
Cards[x]-> Pic= heart;
x++;
}

//diamond
for(int i=1; i<=13; i++){
int x=39;
Cards[x]-> Num= i;
Cards[x]-> Pic= diamond;
x++;
}



}

/////////////////////////////////////////////////////////////////
void Card::ShuffleCard(){
int rnum1;
int rnum2;
ACard temp;
srand(time(0));
srand((unsigned)time(NULL));

for(int i=0; i<52 ; i++){
rnum1=rand()%53;
rnum2=rand()%53;
temp=Cards[rnum1];
Cards[rnum1]=Cards[rnum2];
Cards[rnum2]=temp;
}

nextCard=0;

}


//////////////////////////////////////////////////////////////////
ACard Card::getCard(){

return (Cards[nextCard]);

}

///////////////////////////////////////////////////////////////////////
void Card::printCard(){
ACard card1=getCard();
if(card1->num==1)
CardAce(card1->Pic);
else if(card1->num==2)
CardTwo(card1->Pic);
else if(card1->num==3)
CardThree(card1->Pic);
else if(card1->num==4)
CardFour(card1->Pic);
else if(card1->num==5)
CardFive(card1->Pic);
else if(card1->num==6)
CardSix(card1->Pic);
else if(card1->num==7)
CardSeven(card1->Pic);
else if(card1->num==8)
CardEight(card1->Pic);
else if(card1->num==9)
CardNine(card1->Pic);
else if(card1->num==10)
CardJack(card1->Pic);
else if(card1->num==11)
CardQueen(card1->Pic);
else
CardKing(card1->Pic);
}
//All the card functions look like this one for each type
/////////////////////////////////////////////////////////////////
void Card::CardAce(const char Pic){
cout<<"---------"<<endl;
cout<<"|"<<"A"<<setw(7)<<"|"<<endl;
cout<<"|"<<setw(8)<<"|"<<endl;
cout<<"|"<<setw(8)<<"|"<<endl;
cout<<"|"<<setw(8)<<"|"<<endl;
cout<<"|"<<setw(6)<<Pic<<setw(4)<<"|"<<endl;
cout<<"|"<<setw(8)<<"|"<<endl;
cout<<"|"<<setw(8)<<"|"<<endl;
cout<<"|"<<setw(8)<<"|"<<endl;
cout<<"|"<<setw(7)<<"A"<<"|"<<endl;
cout<<"---------"<<endl;
}
/////////////////////////////////////////////////////////////////
my main function

#include <iostream>
#include "Card.h"

using namespace std;



int main(){
Card deck;
deck.shuffle();
deck.printCard();


return 0;
}
 

Merad

Platinum Member
May 31, 2010
2,586
19
81
I just get a lot of errors. Please help!

Please copy and paste the error messages from your compiler. Without them we don't even know where to start looking. Also, please put your code in [*code][/code*] tags (remove the *'s) so that the forum doesn't destroy the formatting.
 

Ken g6

Programming Moderator, Elite Member
Moderator
Dec 11, 1999
16,836
4,815
75
All the card functions look like this one for each type

If you want to display cards side-by-side, you're going to need to either completely rethink how you display each one or use something like Ncurses. Each approach has advantages and disadvantages.

I'd suggest the first approach. Maybe create a standard card display format, taking fields from an array of Objects. Then iterate over each line for each Object in the array, before outputting a endl.
 

PokerGame

Junior Member
May 11, 2015
1
0
0
I'm pretty sure I'm in your class too, Dr. P?

Anyway,

//club cards
for(int i=1; i<=13; i++){
int x=13;
Cards[x]-> Num= i;
Cards[x]-> Pic= club;
x++;
}

you're setting x back to 13 each time the loop runs, set x outside the loop.

The shuffle should be using a counter from 0-51 to move that with a random other card, instead of swapping two random cards. And I think it should be %52, to get a random between 0-51.

As for the display part, I don't know how he could have used the example display function to print them side by side. But if you break the cards down line by line you're using the same 8 or so couts to build every card. So make a function that takes in the number of cards to print and them prints them all one line at a time.
 
Last edited: