撲克牌游戲C++程序?qū)崿F(xiàn)_第1頁
撲克牌游戲C++程序?qū)崿F(xiàn)_第2頁
撲克牌游戲C++程序?qū)崿F(xiàn)_第3頁
撲克牌游戲C++程序?qū)崿F(xiàn)_第4頁
撲克牌游戲C++程序?qū)崿F(xiàn)_第5頁
已閱讀5頁,還剩7頁未讀 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

1、本文想詳細給出了撲克牌的C+程序并實現(xiàn)我們常玩的就是沒人三張牌比大小,規(guī)則是同花順最大,一次是炸彈、順子、同花、對子、單張。單張A最大,以下是C+程序:/ DeckOfCards.h#ifndef DECKOFCARDS_H#define DECKOFCARDS_Hclass DeckOfCardspublic:DeckOfCards();void deal();void shullfe();void getValue(); / 計算得分int getsameColour();/ 同花int getStraigh(); / 順子 int getStraightAndColoursOrNot()

2、; / 同花順 或非同花 非順子int getPairOrsameValue(); / 對子 或炸彈void output();private:int Deck413;int colourA;int colourB;int colourC;int colourD;#endif/ DeckOfCards.cpp / ½Ìѵ Ö»Òª²»ÊÇvoidÀàÐͺ¯Êý±ØÐ

3、;ëÓзµ»ØÖµ£¬×¢Ò⣺intÀàÐÍ Ä¬ÈÏ·µ»ØֵΪ1#include<iostream>using std:cout;using std:endl;using std:left;using std:right;#include<

4、;iomanip>using std:setw;#include<cstdlib>/ using std:rand;/ using std:srand; #include<ctime>/ using std:time;#include"DeckOfCards.h"static int get23=0;static int number=0;static int straigh=0;static int sameColour=0;static int getScore2=0,0;static int sameValue=0;DeckOfCards

5、:DeckOfCards()for(int row=0;row<4;row+)for(int column=0;column<13;column+)Deckrowcolumn=0;/*static int get23;for(int i=0;i<2;i+)for(int j=0;j<3;j+)getij=0;*/for(int j=0;j<=1;j+)getScorej=0;srand(time(0); void DeckOfCards:shullfe()int row;int column;for(int card=1;card<=52;card+)dor

6、ow=rand() %4 ;column=rand() % 13;while(Deckrowcolumn !=0);Deckrowcolumn=card;void DeckOfCards:deal()static const int face13=1,2,3,4,5,6,7,8,9,10,11,12,13;static const char *suit4="A","B","C","D"number=0;for(int i=0;i<=1;i+)int count=0; colourA=0; colourB=0;

7、 colourC=0; colourD=0;if(i=0)cout<<" Player A:"<<endl;elsecout<<" Player B:"<<endl;for(int card=1+i*3;card<=3+i*3;card+)for(int row=0;row<4;row+)for(int column=0;column<13;column+)if(Deckrowcolumn=card)cout<<" "cout<<setw(3)&

8、lt;<right<<suitrow<<setw(3)<<right<<facecolumn <<(card %3=0)? 'n':'t');geticount=facecolumn;count+;switch(*suitrow)case 'A':colourA+;break;case 'B':colourB+;break;case 'C':colourC+;break;case 'D':colourD+;break; cout<

9、;<endl;cout<<" "<<"colourA="<<colourA<<endl;cout<<" "<<"colourB="<<colourB<<endl;cout<<" "<<"colourC="<<colourC<<endl;cout<<" "<<"colourD=

10、"<<colourD<<endl;cout<<endl;getValue();number+;/ cout<<endl;output(); void DeckOfCards:getValue() / ¼ÆËãµÃ·ÖgetScorenumber+=getStraigh(); / ˳×ÓgetScorenumber+=getsameColour();/ ͬ»¨getScoren

11、umber+=getStraightAndColoursOrNot(); / ͬ»¨Ë³ »ò·Çͬ»¨ ·Ç˳×ÓgetScorenumber+=getPairOrsameValue(); / ¶Ô×Ó »òÕ¨µ¯cout<<" "<<"

12、;getScore "<<getScorenumber<<endl<<endl;cout<<"getStraigh()="<<getStraigh()<<endl;cout<<"getsameColour()="<<getsameColour()<<endl;cout<<"getStraightAndColoursOrNot()="<<getStraightAndColoursOrNot()&l

13、t;<endl;cout<<"getPairOrsameValue()="<<getPairOrsameValue()<<endl;int DeckOfCards:getStraigh() / ÊÇ·ñΪ˳×Óint t;for(int i=0;i<=1;i+)for(int j=0;j<=1-i;j+)if(getnumberj>getnumberj+1) / t=getnumberj;getnumberj=g

14、etnumberj+1; getnumberj+1=t;for(int m=0;m<=2;m+)cout<<" "<<getnumberm<<" "cout<<endl;if(getnumber2-getnumber1)=1 && (getnumber1-getnumber0)=1) straigh=1;cout<<"straigh="<<straigh<<endl;return 0;else if(getnumber0=1 &a

15、mp;& getnumber1=12 && getnumber2=13)straigh=1;cout<<"straigh"<<straigh<<endl;return 0;elsereturn 0;int DeckOfCards:getsameColour() / ÊÇ·ñΪͬ»¨int a=colourA+1;int b=colourB+1;int c=colourC+1;int d=colourD+1;if(

16、a*b*c*d)=4 && getnumber0=1)sameColour=1; cout<<"sameColour="<<sameColour<<endl; return 0;else if(a*b*c*d)=4 && getnumber0!=1) sameColour=1; cout<<"sameColour"<<sameColour<<endl; return 0; elsereturn 0;int DeckOfCards:getStraight

17、AndColoursOrNot() / ͬ»¨Ë³ »òͬ»¨ »ò˳×Óif(sameColour+straigh=2) && (getnumber0=1 && getnumber1=12 && getnumber2=13) / ×î´óµÄͬ»¨Ë&

18、#179; 12·Öcout<<"The largest StraightAndColours sameColour straigh "<<endl;return 12;else if(sameColour+straigh=2) && (getnumber2-getnumber0=2 ) )/ ͬ»¨Ë³ 11·Öcout<<"StraightAndColours,not the largest one same

19、Colour straigh"<<endl;return 11;else if(sameColour=1)&&getnumber0=1) / ͬ»¨ ÓÐA ²»Ë³ 6·Öcout<<"Only have the same colour sameColour"<<endl;return 6;else if(sameColour=1)&&getnumber0!=1) / 

20、05;¬»¨ ÎÞA ²»Ë³ 5·Öcout<<"Only have the same colour sameColour NO A"<<endl;return 5;else if(straigh=1)&&(getnumber0=1 && getnumber1=12 && getnumber2=13) / ×î´óµÄË&#

21、179;×Ó ·Çͬ»¨ 8·Öcout<<"The largest straigh,not have the same colour straigh "<<endl;return 8;else if(straigh=1)&&(getnumber2-getnumber0=2) / ÆÕͨµÄ˳×Ó ·ÇÍ

22、;¬»¨ 7·Öcout<<"The usually straigh,not have the same colour straigh NOT 1 12 13 "<<endl;return 7;else return 0;int DeckOfCards:getPairOrsameValue() / ¶Ô×Ó »òÕ¨µ¯if (getnumber0=getnumber1 && getnu

23、mber0=getnumber2 && getnumber1=1) / ÈýÕÅA AAA µÄ10·Öcout<<"The three cards have the same value "<<endl;sameValue=1;return 10;else if(getnumber0=getnumber1 && getnumber0=getnumber2 && getnumber1!=1) / Èý&#

24、213;ÅÏàͬ ²»ÊÇAAA 9·Öcout<<"The three cards have the same value,not A A A"<<endl;sameValue=1;return 9;else if(getnumber0=getnumber1 | getnumber1=getnumber2 )&& getnumber1=1) / ×î´óµÄ

25、82;Ô×Ó AA 4·Öcout<<"The largest pair:A A"<<endl;return 4;else if(getnumber0=getnumber1 | getnumber1=getnumber2) && getnumber1!=1) / ÆÕͨµÄ¶Ô×Ó ·ÇAA 3·Öcout<<"Pair,n

26、ot the largest ,NOT A A"<<endl;return 3;else if(sameColour+straigh=0)&&getnumber0=1) / Ö»ÓÐÒ»¸öA 2·Öcout<<"Bad,not the worest,only have a A"<<endl;return 2;else if(sameColour+straigh=0)&&getnumber0!=1)

27、 / ûÓÐA 1·Öcout<<"Bad,maybe the worest,not have A"<<endl;return 1;elsereturn 0;void DeckOfCards:output()if( getScore0>getScore1)cout<<"Player A Win the game"<<endl;else if(getScore0<getScore1)cout<<"Player B

28、Win the game"<<endl; / ÔÚ µÃ·ÖÏàͬµÄÇé¿öÏ ²»¿ÉÄܶ¼µÃ10·Ö else if(getScore0=getScore1 && (getScore0=1 | getScore0=5) / ͬ

29、»¨»ò·Çͬ»¨ ×î´óµÄ¶¼²»ÊÇAif(get02>get12)cout<<"Player A Win the game"<<endl;else if(get02<get12)cout<<"Player B Win the game"<<endl;else if(g

30、et01>get11) cout<<"Player A Win the game"<<endl;else if(get01<get11)cout<<"Player B Win the game"<<endl;else if(get00>get10) cout<<"Player A Win the game"<<endl;else if(get00<get10)cout<<"Player B Win the game&q

31、uot;<<endl;elsecout<<"A and B are EQUAL"<<endl;else if(getScore0=getScore1 && (getScore0=2 | getScore0=6) / ͬ»¨»ò·Çͬ»¨ ¶¼ÓÐÒ»ÕÅAif(get01>get11)cout<<&quo

32、t;Player A Win the game"<<endl;else if(get01<get11)cout<<"Player B Win the game"<<endl;else if(get00>get10) cout<<"Player A Win the game"<<endl;else if(get00<get10)cout<<"Player B Win the game"<<endl;elsecout<&l

33、t;"A and B are EQUAL"<<endl;else if(getScore0=getScore1 && getScore0=3) / ¶¼ÓÐÒ»¶Ô µ«²»ÊÇAAif(get01>get11)cout<<"Player A Win the game"<<endl;else if(get01<get11) cout<<&qu

34、ot;Player B Win the game"<<endl;else if(get00+get01+get02) >( get10+get11+get12)cout<<"Player A Win the game"<<endl;else if(get00+get01+get02) <( get10+get11+get12)cout<<"Player B Win the game"<<endl;elsecout<<"A and B are EQUAL

35、"<<endl;else if(getScore0=getScore1 && getScore0=4) / ¶¼ÓÐÒ»¶ÔAA if(get00+get01+get02) >( get10+get11+get12)cout<<"Player A Win the game"<<endl;else if(get00+get01+get02) <( get10+get11+get12)cout<<"Player B Win the game"<<endl;elsecout<<"A and B are EQUAL"<<endl;else if(getScore0=getScore1 && (getScore0=7 | getScore0=8 / 

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論