资源描述:
《21点游戏编程》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、/*Filename:BLAKJACK.CThisprogramplaysagameofBlackjackwithyou.Thecomputeristhedealerandyouarethevictim-er,Imeanplayer.Thedealergetsacardthatyoucansee.Thedealerthenasksifyouwantanothercardbyasking“Hit”or“Stand.”Ifyouchoosetohit,thedealergivesyouanothercard.I
2、fyouchoosetostand,thedealerdrawsorstands,andthegameisplayedoutaccordingtothecardsyouandthedealerhave.AswithrealBlackjack,thedealerstandson17.Thewinnerisannouncedonlyafterboththeplayer’sandthedealer’shandsarefinished.*//*************************************
3、*****************ANSICstandardheaderfilesappearnext*/#include#include#include#include/******************************************************Definedconstantsappearnext*/#defineBELL‘a’#defineDEALER0#definePLAYER1/*Mustkee
4、ptwosetsoftotalsfordealerandforplayer.ThefirstsetcountsAcesas1andthesecondcountsAcesas11.Unlike“realworld”Blackjack,thisprogramdoesn’tallowsomeAcestobe1whileothersAcesare11inthesamehand.*/#defineACELOW0#defineACEHIGH1/*Onlyoneglobalvariableisusedinthisenti
5、reprogram.Thevariableholds0,whichmeansfalseinitially.OncetheuserentershisorhernameininitCardsScreen(),thisvariableissetto1(fortrue),sothenameisneveraskedforagaintherestoftheprogram.*//******************************************************Thisprogram’sspeci
6、ficprototypes*/voiddispTitle(void);voidinitCardsScreen(intcards[52],intplayerPoints[2],intdealerPoints[2],inttotal[2],int*numCards);intdealCard(int*numCards,intcards[52]);voiddispCard(intcardDrawn,intpoints[2]);voidtotalIt(intpoints[2],inttotal[2],intwho);
7、voiddealerGetsCard(int*numCards,intcards[52],intdealerPoints[2]);chargetans(charmesg[]);voidfindWinner(inttotal[2]);/******************************************************C’sprogramexecutionalwaysbeginsatmain()here*/Main(){intnumCards;/*Equals52atbeginning
8、ofeachgame*/intcards[52],playerPoints[2],dealerPoints[2],total[2];charans;/*Foruser’sHit/StandorYes/Noresponse*/do{initCardsScreen(cards,playerPoints,dealerPoints,total,&numCards);dealerGetsCard(&numCards,car