#include %26lt;iostream%26gt;
#include %26lt;string%26gt;
#include %26lt;time.h%26gt;
using namespace std;
class cCard
{
public:
char face[13] = {'2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A'};
enum suit[4] = {"S", "H", "D", "C"};
int getSuit ();
int getFace();
void print();
};
int cCard::getSuit()
{
return suit;
}
int cCard::getFace()
{
return face;
}
void cCard::print()
{
std::cout%26lt;%26lt;face %26lt;%26lt;suit;
}
class cDeck
{
public:
void shuffle();
char Card[13][4];
void Deck;
};
void cDeck::shuffle()
{
int face, suit;
for(face = 2; face %26lt; 13; face++)
{
for(suit = 0; suit %26lt; 4; suit++)
Card[face][suit] = NULL;
}
}
void cDeck::Deck()
{
int card, suit, face;
int deck[deckSuit][deckFace];
card = 1 ;
for (suit = 0 ; suit %26lt;= deckSuit - 1 ; suit++ )
{
for (face = 0 ; face %26lt;= deckFace - 1 ; face++ )
{
deck[suit][face] = card ;
card++;
}
}
}
class cPlayer
{
public:
string cPlayer();
void printHand();
void print();
};
string cPlayer::cPlayer(string name, int stake)
{
playerName = name;
playerStake = stake;
}
void cPlayer::printHand()
{
std::cout%26lt;%26lt;Card%26lt;%26lt;"\tab"%26lt;%26lt;Card%26lt;%26lt;"\tab"%26lt;%26lt;C...
}
void cPlayer::print()
{
cout%26lt;%26lt;name %26lt;%26lt;" $" %26lt;%26lt;stake %26lt;%26lt;"\n";
}
class cGame
{
public:
bool addPlayer();
void play();
void deal();
void cardQuality();
void print();
};
bool cGame::addPlayer(string playerName, int playerStake)
{
std::cout %26lt;%26lt; "Enter your name: ";
std::cin %26gt;%26gt; playerName;
std::cout %26lt;%26lt; "\nHow much money you have for the game? ";
std::cin %26gt;%26gt; playerStake;
}
void cGame::play(int player[][2] , int shuffledCard[][13])
{
int sCard, sSuit, sFace, pSuit = 0 , pFace = 0;
static int cardStart = 1;
for (sCard = cardStart ; sCard %26lt;= cardStart + 4; sCard++ ) {
for (sSuit = 0 ; sSuit %26lt;= 3; sSuit++ ){
for(sFace = 0 ; sFace %26lt;= 12; sFace++ ){
if (shuffledCard[sSuit][sFace] == sCard ){
player[pSuit][pFace] = sSuit;
pFace++;
player[pSuit][pFace] = sFace;
pFace--;
pSuit++;
}
}
}
}
cardStart = sCard;
}
void cGame::deal(int playerHand[][2], const char *suit1[], const char *face1[])
{
int a , b;
for ( a = 0 ; a %26lt;= 4; a++ )
{
b = 0;
std::cout%26lt;%26lt;"%s"%26lt;%26lt;suit1[playerHand[a][b]]...
b = 1;
std::cout%26lt;%26lt;"%s "%26lt;%26lt;face1[playerHand[a][b]]);
}
}
void cGame::whatHand( int playerHand [][2] )
{
int x,y;
int positFace[5], positSuit[5];
int *fPtr = positFace, *sPtr = positSuit ;
int Facepass = 0;
int Suitpass = 0 ;
int straight = 0;
for ( x = 0 ; x %26lt;= 4 ; x++ )
{
y = 1 ;
*fPtr = playerHand[x][y];
fPtr++ ;
}
for ( x = 0 ; x %26lt;= 4 ; x++ )
{
y = 0 ;
*sPtr = playerHand[x][y];
sPtr++ ;
}
for ( x = 0 ; x %26lt;= 3 ; x++ )
{
for ( y = (x + 1); y %26lt;= 4 ; y++ )
{
if ( *(positFace + x ) == *(positFace + y ) )
{
Facepass++;
}
}
}
for ( y = 0 ; y %26lt;= 3 ; y++ )
{
for (x = 0 ; x %26lt;= 3 ; x++ )
{
if ( positFace[x] %26gt; positFace[x+1] )
{
Swap(%26amp;positFace[x],%26amp;positFace[x+1]);
}
}
}
for ( y = 0; y %26lt;= 3 ; y++ )
{
if ( positFace[y] == positFace[y + 1] - 1 )
{
straight++;
}
}
for ( y = 1; y %26lt;= 4 ; y++ )
{
if ( *positSuit == *(positSuit + y ) )
{
Suitpass++;
}
}
switch ( Facepass )
{
case 1 :
std::cout%26lt;%26lt;"This poker hand contains a pair\n";
break ;
case 2 :
std::cout%26lt;%26lt;"This poker hand contains two pairs\n";
break;
case 3 :
std::cout%26lt;%26lt;"This poker hand contains three of a kind\n";
break ;
case 4:
std::cout%26lt;%26lt;"This poker hand contains a full house\n";
break ;
case 6:
std::cout%26lt;%26lt;"This poker hand contains four of a kind\n";
break ;
default :
if ( Suitpass == 4 %26amp;%26amp; straight != 4)
{
std::cout%26lt;%26lt;"This poker hand contains a flush\n";
}
if ( straight == 4 %26amp;%26amp; Suitpass != 4)
{
std::cout%26lt;%26lt;"This poker hand contains a straight\n";
}
if ( straight == 4 %26amp;%26amp; Suitpass == 4)
{
std::cout%26lt;%26lt;"This poker hand contains a straight flush\n";
}
break;
}
}
int main()
{
cPlayer thisplayer(Play#1, 1000);
thisplayer.print();
deck[4][13];
shuffle(deck, deckFace, deckSuit);
play(Play#1, deck);
deal(Play#1, suit, face);
whatHand(Play#1);
cPlayer thisplayer(Play#2, 1000);
thisplayer.print();
deck[4][13];
shuffle(deck, deckFace, deckSuit);
play(Play#2, deck);
deal(Play#2, suit, face);
whatHand(Play#2);
cPlayer thisplayer(Play#3, 1000);
thisplayer.print();
deck[4][13];
shuffle(deck, deckFace, deckSuit);
play(Play#3, deck);
deal(Play#3, suit, face);
whatHand(Play#3);
addPlayer thisplayer();
thisplayer.print();
deck[4][13];
shuffle(deck, deckFace, deckSuit);
play(playerName, deck);
deal(playerName, suit, face);
whatHand(playerName);
return 0;
}
Can somebody please help me with this C++ code?
this is one issue
enum suit[4] = {"S", "H", "D", "C"}; %26lt;---not an int
int cCard::getSuit()
{
return suit; %26lt;--returning an int
}
******
additional
looked further down realized your next one also returned an int when what you had was a char
Reply:what's the problem?
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment