- 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:
rintCard(){
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;
}
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:
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;
}
