Game Series ~ Blackjack Poker (1)

#include<ctime>
//#include<stdio>
#include<iostream>
//#include<stdlib>
#include<conio.h>
#include <bits/stdc++.h>
using namespace std;
//Define poker
class game
{
private:
int wins,lose,draw,money;
int bet,playerturns,cputurns;
float player,cpu,card;//There will be a warning when CARD exchanges data with BET, you can define an INT type to avoid .
char flag;
public:
game();
void results(float player,float cpu,int bet,int &money,int &draw,int &wins,int &lose);
void wait(int milli);
void sign();
void special(float &player,float &cpu);
void rules();
void pause();
float random(long hign,long low);
void print(int wins,int lose,int draw,int money);
void replay(char &flag);
void hit(float &total);
void results(float player,int cpu,int bet,int &money,int &draw,int &win,int &lose);
void BET(int &bet,int &money);
void deal(float &player,float &cpu,int &playerturns,int &cputurns);
void deal2(float &player,float &cpu,int &playerturns,int &cputurns);
void ask();
};
//---------------------------------------------------------------------
//完成虚构函数
game::game()
{
wins=0;
lose=0;
draw=0;
money=0;
player=0.0;
cpu=0.0;
bet=0;
playerturns=0;
cputurns=0;
card=0;
flag='a';
}
//--------------------------------------------------------- ----------------------
void game::rules()
{
cout<<"\t************** ********************************************"<<endl;
cout< <"\t*\t\tWelcome to this poker blackjack game\t\t\t*"<<endl;
cout<<"\t*\t\t\tThe rules are as follows\t\t\t* "<<endl;
cout<<"\t*\t\tOne: You can't have more than 5 cards.\t\t\t*"<<endl;
cout<<"\t*\t\tTwo: You can add bets.\t\t\t*"<<endl;
cout<<"\t*\t\tThird: agree to press y.\t\t\t\t\*"<<endl;
cout< <"\t************************************************ **********"<<endl;
cout<<"\t\t\t";
pause();//pause here for a few seconds
ask();
}
//---------------------------------------------------------------------
void game::ask()
{
cout<<endl<<endl;
cout<<"\t\t\tDo you want to play this game?"<<endl;
cin>>flag;
if((flag=='y')||(flag=='Y')) // Determine whether to enter the game
{
cout<<"\t\t\tYou will have 100 yuan to start this game"<<endl;
money=100;//Set the initial bet
cout<<"\t\t\t";
pause ();
}
else exit(1);
BET(bet,money);
deal(player,cpu,playerturns,cputurns);//Start processing
}
//--------------- -------------------------------------------------- ----
void game::BET(int &bet,int &money)
{
int sign;
system("cls");
if(money<=0)
{
cout<<"\t\t\tYou have no more bets , please close and start again"<<endl;
exit(1);
}
cout<<"\t\t\tYou now have:"<<money<<"$bet"<<endl;
cout<<"\t\t\tHow much do you want to bet:";
do{ //Determine whether the input bet is correct
sign=0;
cin>>bet;
if((bet<0)&&(bet*-1<=money))
{
bet=bet*-1;
break;
}
else if((bet>0)&&(bet<=money))
break;
else
{
cout<<"Incorrect input, please re-enter: ";
sign=1;
}
}while(sign=1);
money=money-bet;
}
//----------- -------------------------------------------------- --------
void game::deal(float &player,float &cpu,int &playerturns,int &cputurns)
{
float playercard1,playercard2,cpucard1,cpucard2;
playerturns=2;
cputurns=2;
playercard1=random(13, 1); //Start using random numbers to divide cards
cout<<"\n\t\t\tProcessing"<<endl;
wait(350);
playercard2=random(13,1);
wait(150);
cpucard1=random(13,1);
wait(350);
cpucard2=random(13,1);
if(playercard1>=10)
{
playercard1=0.5;
}
if(playercard2>=10)
{
playercard2=0.5;
}
if(cpucard1>=10)
{
cpucard1=0.5;
}
if(cpucard2>=10)
{
cpucard2=0.5;
}
player=playercard1+playercard2;
cpu=cpucard1+cpucard2;
cout<<"\t\t\t你的点数为:"<<player<<endl<<endl;
cout<<"你的两张牌是:";
cout<<"["<<playercard1<<"]";
cout<<"["<<playercard2<<"]";
cout<<endl;
cout<<"\t\t\t电脑有一张"<<cpucard1<<"Display"<<endl; cout<<"The computer's card is:";
cout<<endl;

cout<<"[*]"<<"["<<cpucard1<<"]"<<endl;
deal2(player,cpu,playerturns,cputurns);//Call the card deal function
}
//----- -------------------------------------------------- --------------
void game::deal2(float &player,float &cpu,int &playerturns,int &cputurns)
{
do{
cout<<"\t\t\tYou want to continue to ask for cards What?";
cin>>flag;
if(((flag=='o')||(flag=='O'))&&(playerturns<5)) //Determine whether the advanced player is
{
do
{
card=random (13,1);
if(card>10)
{
card=0.5;
}
cout<<"\t\t\tThe next card is: "<<card<<endl; //Display the next card
cout<< "\t\t\tDo you want this card? (Enter p to continue asking for the card)"<<endl;
cin>>flag;
if((flag=='p')||(flag=='P'))
{
playerturns++;
player=player+card;
cout<<"\t\t\tYour current point is: "<<player<<endl;
}
if(playerturns>=5)
{
cout<<"\t\t\t\nYour card has arrived Five cards, no more cards"<<endl;break;
}
}while(flag=='p');
}
else if((flag=='y')||(flag=='Y')) //Set the normal player here
{
playerturns++;
if(player>21)
{
cout<<"\t\t\tYou're a loser, you lose";
lose++;
replay(flag);
}
if(playerturns>5 )
{
cout<<"\t\t\tYou have five cards, you can't ask for more cards"<<endl;break;
}
else if((playerturns<6)&&((flag=='y' )||(flag=='Y')))
{
cout<<endl;
hit(player);
}
}
}while((flag=='y')||(flag=='Y'));
cout<<"\t\t\tDo you want to add a bet?"<<endl; //Ask if Need to add bet
cin>>flag;
if((flag=='y')||(flag=='Y'))
{
cout<<"\t\t\tPlease enter the bet you want to add:";
do{
cin>>card;
if (money==0) //Determine whether the bet can be added
{
cout<<"\t\t\tYou have no more bets, the computer starts to ask for cards."<<endl;
break;
}
if((card)>money )
{
cout<<"\t\t\tYou don't have enough bets."<<endl;
cout<<"\t\t\tPlease enter a number between 0 and "<<money<<":"< <endl;
}
}while((card)>money);
bet=bet+card;
money=money-card;
}
for(;(cpu<16)&&(cputurns<5);cputurns++) //Deal card to the computer
{
cout<<endl;
cout<<"\t\t\tThe computer asked for a card"<<endl;
hit(cpu);
if(cpu>21)
{
cpu=cpu-card;
break;
}
}
cout<<endl;
cout<<endl;
cout<<"\t\t\t电脑的牌点数为:"<<cpu<<endl;
cout<<"\t\t\t你的点数为:"<<player<<endl;
cout<<endl;
if(((player<=21)&&(cpu<=21))||(playerturns==6)||(cputurns==5)) //特殊判断
{
special(player,cpu);
}
results(player,cpu,bet,money,draw,wins,lose);
replay(flag);
print(wins,lose,draw,money);
cout<<endl;
}
//---------------------------------------------------------------------
void game::hit(float &total) //分牌函数
{
float card;
card=random(13,1);
if(card>=10)
{
card=0.5;
}
total=total+card;
cout<<"\t\t\t要的牌是:"<<card<<endl;}
cout<<"\t\t\tThe total number of points is:"<<total<<endl;

//------------------------------------------------ ---------------------
void game::pause()
{
cout<<"Press any key to continue"<<endl;
getch();
}
//- -------------------------------------------------- ------------------
void game::wait(int milli)
{
clock_t start; //call TIME.H internal function
start=clock();
while((clock( )-start)<milli)
;
}
//-------------------------------------------------- ------------------------------
float game::random(long high,long low) //Get random numbers
{
float ran ;
srand((unsigned)time(NULL));
ran= rand()%(high-(low-1))+low;
return(ran);
}
//------------ -------------------------------------------------- -------
void game::replay(char &flag)
{
cout<<"\n\t\t\tDo you want to continue playing this game:";
cin>>flag;
while((flag=='y')||( flag=='Y')) //Set the game loop here
{
BET(bet,money);
deal(player,cpu,playerturns,cputurns);
}
print(wins,lose,draw,money);
}
//- -------------------------------------------------- ------------------
void game::print(int wins,int lose,int draw,int money) //output result
{
cout<<"\t\t\ t win: "<<wins<<endl;
cout<<"\t\t\t lose: "<<lose<<endl;
cout<<"\t\t\t and: "<<draw<<endl ;
cout<<"\t\t\tRemaining money:"<<money<<endl;
sign();
}
//---------------------------------------------------------------------
void game::results(float player,float cpu,int bet,int &money,int &draw,int &wins,int &lose)
{
if(cpu==player) //output result
{
cout<<"\t\t\t If the number of points is the same, the dealer wins"<<endl;
draw++;
}
if(player>21)
{
cout<<"\t\t\tYou are overwhelmed, come on"<<endl;
lose++;
}
else
{
if(cpu< player)
{
cout<<"\n\t\t\tCongratulations, you won";
money=money+(bet*2);
wins++;
}
}
if(cpu>21)
{
cout<<"\t\t \tBanker cheers"<<endl;
if(player<21)
{
cout<<"\n\t\t\tYou won";
wins++;
money=money+(bet*2);
}
}
else
{
if(cpu>player)
{
cout<<"\t\t\tYou lost"<<endl;
lose++;
}
}
}
//------------------------- --------------------------------------------
void game::sign( )
{
cout<<"\n\n\n\n\t\t\tThe first time a novice writes, please advise"<<endl;
exit(1);
}
//--------- -------------------------------------------------- ----------
void game::special(float &player,float &cpu)
/*If the five cards are not more than 21 and the opponent does not have five cards, then it is a win. If both players Five cards and
no more than 21 points, the smaller one wins.*/
{
if((player<=21)&&(cpu<=21)&&(playerturns==6)&&(cputurns<5))
{
cout<<"\n\t\t\tCongratulations, you won";
money=money+(bet*2);
wins++;
}
if((player<=21)&&(cpu<=21)&&(playerturns<6)&&(cputurns==5))
{
cout<<"\t\t\t你输了"<<endl;
lose++;
}
if((player<=21)&&(cpu<=21)&&(playerturns==6)&&(cputurns==5))
{
if(player<cpu)
{
cout<<"\n\t\t\t恭喜,你赢了";
money=money+(bet*2);
wins++;
}
else
{
cout<<"\t\t\t你输了"<<endl;
lose++;
}
}
replay(flag);
}
//---------------------------------------------------------------------
int main()
{
game deck;
deck.rules();
}
//---------------------------------------------------------------------

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325044930&siteId=291194637