您好,欢迎访问三七文档
扑克牌游戏c++源代码/*第1题扑克牌游戏--源代码及关键源代码注解如下:*///*ThisProgramwaswrittenentirelybytheauthorFrankVokoun.//*******************preprocessordirectives***********************//#include<iostream.h>#include<string.h>#include<conio.h>#include<stdlib.h>#include<stdio.h>#include<time.h>//usedtoseedtherandomnumbergenerator////***********************************************************************classPlaying_Card//扑克类{private:intm_Value;charm_Face[3];//扑克的数字大小charm_Suit;//扑克的花色(黑、红、梅、方)public:Playing_Card();//CONSTRUCTORvoidshowcard();//DisplaysanobjectofclassPlaying_CardvoidCard_Make(int);};classDeck//一副扑克(52张){private:Playing_Cardm_cardarray[52];//ObjectarrayofclassPlaying_Cardintm_lastdelt;public:Deck();//CONSTRUCTORinitializesemptyDeckobjectvoidMakeDeck();//makesacompleteobjectofclassDeckvoidDeal_One();//DealsacardfromtopofthedeckvoidShowDeck();//DisplaysaDeckobjecttothescreenvoidDeckShuff(int);//"Shuffles"aDeckobjectforinttimesvoidRemove_Card();//RemovesusedcardfromDeckPrevents};//mistakenlyusinganonexistantcard//canbuusedtosendacard??//***************************prototypes**********************************voidProgram_Init();//Programinformationintmain();voidCenter_Text(char[]);//Centerstextintget_number();//GetsaintegerfromusercharGet_Key();//Getsacharfromuser,pausesprogramvoidDeckMakeDriver();//TestsSeveralFunctionsincludingMakedeckintgetRandInt(intmin,intmax);//Randomnumbergeneratorvoidprog_close();//pausesbeforeprogramtermination//****************************Main*************************************intmain()//**************************************************************************//*intmain:MainFunctionCallsotherfunctions//*//*expects:None.//*Returns:Integer0;//*SideeffectsNone//*//*Tasks(1)SeedstheRandomnumbergenerator//*(2)CallsProgramInitfunctionforTitleetc.//*(3)CallDeckMakeDrivertoTestMakeDeckandDeckShuff.//*//***********************************************************************{srand((unsigned)time(NULL));//SeedsGetRandIntintCard_Number=0;Program_Init();//Showdtitleetc.DeckMakeDriver();//TheMainFunctionDriverTestsDeckand//Playing_Cardclassesprog_close();//pausesscreenoutputreturn1;}Playing_Card::Playing_Card()//CONSTRUCTOR//**************************************************************************//*Playing_CardPlaying_CardCONSTRUCTORFORCLASSPlaying_Card//*//*expects:None.//*Returns:None//*SideeffectsNone//*//*TasksConstructsobjectofclassplaying_cardreplacesdefaultconstructor//*********************************************************************//Constructorreplacesdefaultconstructor{inti;for(i=1;i<=3;)//initsstringvariabletoblanks{m_Face[i]='';i++;}m_Suit='';//initscharvariabletoblankm_Value=0;}voidProgram_Init()//*************************************************************************//*voidProgram_Init():ShowsTitle//*//*expectsNone//*returns:None//*SideEffects:Textiscenteredonscreen//*//*Task(s)Outputprograminformationtoscreen.//*//***********************************************************************{Center_Text("Lab#5");cout<<endl;Center_Text("ADeckDriver");cout<<endl<<"\n";Center_Text("ByFrankVokoun");cout<<endl<<"\n";Center_Text("(C)2001,FrankVokoun");cout<<endl<<"\n";Center_Text("Hitthe<Return>keytoContinue..");cin.get();}charGet_Key()//***********************************************************************//*charGet_Key():Usesainputprompttogetachar//*//*expects:None.//*Returns:Inputchar.//*Sideeffects:PausesProgramexecution(desiredeffect).//*//*Task(s):Getsacharfromtheuser..//*//**********************************************************************{charx;x=cin.get();cout<<endl;returnx;}voidPlaying_Card::showcard()//*****************************************************************//*voidshowcard(card):DisplaysaPlayingCardsobjecttothescreen//*//*Expects:None->UsescallingmembersPlaying_Cardobject//*Returns:None//*SideEffects:Displays//*//*Task(s):DisplaystheobjectofclassPlaying_Cardtoscreen//*//***********************************************************************{cout<<"";cout<<m_Face;cout.width(1);cout<<m_Suit;cout<<"";}voidCenter_Text(charShellText[80])//**********************************************************************//*VoidCenter_Text:Displaystextcenteredonthescreen.//*//*expects:Thetexttodisplay.//*Returns:None.//*Sideeffects:OutputsCenteredtextonscreen.//*//*******************************************************************{intlength;intcenter;length=strlen(ShellText);center=(80-length)/2;for(;center!=0;center--){cputs("");}cputs(ShellText);}intget_number()//********************************************************************//*//*intget_number:Getsanintegerfromtheuser.//*expects:None.//*Returns:Integer.//*Sideeffects:None.//*Task(s):Askstheusertoenteranintegerthenreturnsthatinteger.//*.//************************************************
本文标题:扑克牌游戏c源代码
链接地址:https://www.777doc.com/doc-5618394 .html