Очень жду советов и найденных ошибок, заранее спасибо.
Код:
#include <iostream>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
class Card
{
int rank;
int suit;
public:
Card ()
{
rank = 0;
suit = 0;
}
Card (int r, int s)
{
rank = r;
suit = s;
}
int getRank ()
{
return rank;
}
int getSuit ()
{
return suit;
}
void viewCard ()
{
if (rank<=8)
cout << rank+2;
else
switch (rank)
{
case 9:
cout << "J";
break;
case 10:
cout << "Q";
break;
case 11:
cout << "K";
break;
case 12:
cout << "A";
break;
}
cout << (char)suit;
}
};
class Deck
{
vector <Card> cards;
public:
Deck ()
{
for (int i=0;i<13;i++)
{
for (int j=3;j<7;j++)
{
cards.push_back(Card(i,j));
}
}
}
Card getCard ()
{
srand (time(NULL));
int pos = rand()%cards.size();
Card temp = cards.at(pos);
cards.erase(cards.begin()+pos);
return temp;
}
};
class Hand: public Deck, public Card
{
public:
Card on_hand[5];
Hand ()
{
for (int i=0;i<5;i++)
{
on_hand[i] = getCard();
}
}
void changeCards ()
{
int n, c, temp;
int change [5] = {-1,-1,-1,-1,-1};
cout << "\nPlease specify count of cards, which you wants to change: ";
cin>>n;
if (n==5)
{
for (int i=0;i<5;i++)
{
on_hand[i] = getCard();
}
}
else
{
cout << "\nPlease choose cards which should be changed (1-5)\n:";
for (int i=0;i<n;i++)
{
temp = -1;
cin>>temp;
change [i] = temp-1;
}
srand(time(NULL));
for (int i=0; i<n; i++)
{
on_hand[change[i]] = getCard();
}
}
}
void DisplayHand ()
{
for (int i=0;i<5;i++)
{
on_hand[i].viewCard();
cout << "\t";
}
cout << "\n\n";
for (int i=0;i<5;i++)
{
cout << i+1 << "\t";
}
}
};
class Prize: public Hand
{
int Money;
int bet;
int *Combinations;
/*
0 - Pair
1 - 2 Pairs
2 - Three f a Kind
3 - Street
4 - Flash
5 - Full House
6 - Four of a Kind
7 - Street Flash
*/
public:
Prize ()
{
bet = 0;
Money = 300;
Combinations = new int [8];
for (int i=0;i<8;i++)
{
Combinations[i]=0;
}
}
void checkCombinations ()
{
bool check [5] = {0,0,0,0,0};
int a;
//Check on Pairs, 2Pairs, 3ofKind, 4ofKind
for (int i=0;i<5;i++)
{
for (int j=i+1;j<5;j++)
{
a=0;
if (check[i]!=1)
{
if (on_hand[i].getRank()==on_hand[j].getRank())
{
a++;
check[j]=1;
}
}
else
break;
}
check[i]=1;
switch (a)
{
case 1:
Combinations[0]++;
break;
case 2:
Combinations[2]+=1;
break;
case 3:
Combinations[6]+=1;
break;
default:
break;
}
}
//Check on Flash
if (on_hand[0].getSuit()==on_hand[1].getSuit()==on_hand[2].getSuit()==on_hand[3].getSuit()==on_hand[4].getSuit())
Combinations[4]+=1;
//Check on Full House
if (Combinations[0]>0 && Combinations[2]>0)
{
Combinations[5]+=1;
}
//Check 2pairs
if (Combinations[0]>1)
Combinations[1]+=1;
}
void setBet (int x)
{
bet = x;
}
int getMoney ()
{
return Money;
}
void getPrize ()
{
if (Combinations[7]==1)
{
cout << "\nYou have a Street Flash. You won "<< 100+bet <<"$\n";
Money+=(100+bet);
}
else if (Combinations[6]==1)
{
cout << "\nYou have Four of a kind. You won "<<60+bet<<"$\n";
Money+=(60+bet);
}
if (Combinations[5]==1)
{
cout << "\nYou have a Full House. You won "<<50+bet<<"$\n";
Money+=(50+bet);
}
else if (Combinations[4]==1)
{
cout << "\nYou have a Flash. You won "<<25+bet<<"$\n";
Money+=(25+bet);
}
if (Combinations[3]==1)
{
cout << "\nYou have a Street. You won "<<20+bet<<"$\n";
Money+=(20+bet);
}
else if (Combinations[2]==1)
{
cout << "\nYou have Three of a Kind. You won "<<15+bet<<"$\n";
Money+=(15+bet);
}
if (Combinations[1]==1)
{
cout << "\nYou have Two Pairs. You won "<<10+bet<<"$\n";
Money+=(10+bet);
}
else if (Combinations[0]==1)
{
cout << "\nYou have a one Pair. You won "<<5+bet<<"$\n";
Money+=(5+bet);
}
else
{
cout << "\nThere is no one matched combinations.\n";
Money-=bet;
}
}
};
void main ()
{
Card one;
Deck myDeck;
Hand player;
Prize myPrize;
int bet;
cout << "\nYour money: " << myPrize.getMoney();
cout << "\n\nEnter your bet: ";
cin >> bet;
myPrize.setBet(bet);
cout << endl;
player.DisplayHand();
player.changeCards ();
cout << endl;
player.DisplayHand();
myPrize.checkCombinations();
myPrize.getPrize();
cout << "\nYour money: " << myPrize.getMoney();
system("pause");
}