南京理工大学C++课程设计扑克牌游戏多文件资料_第1页
南京理工大学C++课程设计扑克牌游戏多文件资料_第2页
南京理工大学C++课程设计扑克牌游戏多文件资料_第3页
南京理工大学C++课程设计扑克牌游戏多文件资料_第4页
南京理工大学C++课程设计扑克牌游戏多文件资料_第5页
已阅读5页,还剩41页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、实用标准文案南京理工大学紫金学院 C+ 课程设计报告课程:C+ 课程设计学院:计算机学院班级:计算机大类四班学号:170310441姓名:田越选题名称:扑克牌游戏起止时间:2018.5.222018.6.1指导教师:杜兰2018 年 5 月文档大全2017 级紫金学院 C+ 课程设计1 问题描述在提供的源程序基础上 ,写一个程序 ,可以进行洗牌等操作 .2 基本要求1) 增加大小王 .2) 删去一张指定扑克牌后 ,进行余牌显示 .3) 创建一副扑克牌 ,显示一副扑克牌 ,洗牌 ,依次分发给四人并显示 .3 需求分析输入形式与范围是按照提示语句输入相应的数字或是(Y)否(N) 的英文字母输出形式

2、即为提示语句所说明的内容该程序基本任务是完成扑克洗牌 ,显示玩家手牌 ,按花色或牌面整理手牌 (排序 )测试数据为 54 张扑克牌面值以及花色 ,无需手动设置正确的输入将使得程序按说明运行 ,错误输入默认直接退出程序4 概要设计2017 级紫金学院 C+ 课程设计分为 8 个部分 ,也是八个文件头文件两个 :all.hclass.h其余 cpp 文件,共6 个,说明如下 :main 函数deckperdeckplaydeckplayingcardmain 函数调用的函数5 详细设计All.h#pragma once#include 包含主程序所需的所有头文件 包含所有的类 ,并卷入 all.h

3、主调函数包含 deck 类的函数包含 perdeck 类的函数包含 playdeck 类的函数包含 playingcard 类的函数顾名思义#include / 编译器是 VS2017#include #include #include #include Class.h2017 级紫金学院 C+ 课程设计#pragma once#include all.husing namespace std;class PerDeck ;class PlayingCardprivate :int nValue; / 扑克牌实际面值char achFace3; / 扑克牌字符串 A,2,10,J,Q,Kcha

4、r chSuit; / 扑克牌花色 public :friend class PerDeck ;PlayingCard(); / 将对象清零void ShowCard(); / 显示面值花色void CardMake( int );/ 给一张扑克牌赋值 (面值,花色 ) ;class Deckprivate :PlayingCard m_cardarray54;int nLastDelt;2017 级紫金学院 C+ 课程设计public :friend class PerDeck ;Deck();void MakeDeck(); / 将52张牌清零 (没有大 ,小王)void DealOne(

5、); / 删除开头一张牌void ShowDeck(); / 依次逐张显示这副牌void DeckShuff( int );/ 用于洗牌 , 参数是洗牌次数void RemoveCard(); / 清零删除掉的那张牌;class PerDeckprivate :PlayingCard myCard20;int nNum;public :PerDeck() void MakePerDeck( Deck &, int );void Show();void SortFace();void SortSuit();int Delete( int n);2017 级紫金学院 C+ 课程设计;class P

6、layDeckprivate :PerDeck myDeck4;public :PlayDeck() void PlayCard( Deck &);void Show();int DeleteOne( int row , int column );int DeleteAll( int, int , int ,int );void SortDeckFace( int );void SortDeckSuit( int );void s(int );void ProgramInit(); / 初始化 ,并输出信息void CenterText( char ShellText 80); / 居中显示i

7、nt GetNumber(); / 键入整数型char GetKey(); / 键入字符串型void DeckMakeDiver(); / 主要算法 (生成扑克牌 ,洗牌,删除等 )2017 级紫金学院 C+ 课程设计int GetRandInt( int min , int max );/ 在min 到max 间选随机值 void ProgClose(); / 暂停 ,供用户查看中间运行结果main 函数 .cpp#include class.husing namespace std;int main( void )srand( unsigned )time( NULL );int nCar

8、dNum = 0;ProgramInit();DeckMakeDiver();ProgClose();return 1;Playdeck.cpp#include class.h#include using namespace std;void PlayDeck :PlayCard( Deck & k)2017 级紫金学院 C+ 课程设计int a, b, c, d;char g29 = 依次输入四位玩家手里的牌数: ;CenterText(g);cout a b c d;if (a + b + c + d 54)char g = 超过牌的张数,退出游戏。 ;CenterText(g);exit

9、(0);myDeck0.MakePerDeck( k, a);myDeck1.MakePerDeck( k, b);myDeck2.MakePerDeck( k, c);myDeck3.MakePerDeck( k, d);void PlayDeck :Show()char a6 = 玩家 1 ;char b6 = 玩家2 ;char c6 = 玩家 3 ;紫金学院 C+ 课程设计2017 级char d6 = 玩家4 ;CenterText(a);cout endl;myDeck0.Show();CenterText(b);cout endl; myDeck1.Show();CenterTe

10、xt(c);cout endl; myDeck2.Show();CenterText(d);cout endl; myDeck3.Show();int PlayDeck :DeleteOne( int row , int column )myDeck row - 1.Delete( column );return 1;int PlayDeck :DeleteAll( int a, int b, int c, int d)紫金学院 C+ 课程设计2017 级myDeck0.Delete(a);myDeck1.Delete(b);myDeck2.Delete(c);myDeck3.Delete(d

11、);return 1;void PlayDeck :SortDeckFace( int b)myDeck b - 1.SortFace();void PlayDeck :SortDeckSuit( int b)myDeck b - 1.SortSuit();void PlayDeck :s(int a)myDeck a - 1.Show();紫金学院 C+ 课程设计2017 级Deck.cpp#include class.h#include using std: ostream ;using namespace std;void Deck :MakeDeck() / 对生成的 52 张牌逐个赋

12、值nLastDelt = 53; /51while (nLastDelt -1)m_cardarraynLastDelt.CardMake(nLastDelt);nLastDelt-;void Deck :ShowDeck() / 显示一副扑克牌char a13 = 完整的一副牌 ;int nIndex = nLastDelt + 1;int nNewLine = 0;CenterText(a);10cout endl;2017 级紫金学院 C+ 课程设计while (nIndex = 53) /51if (nNewLine % 11 = 0)cout endl;m_cardarraynInd

13、ex.ShowCard(); nNewLine+;nIndex+;void Deck :DeckShuff( int times )/ 洗牌算法char a11 = 洗牌 ;int x, nSplit;CenterText(a); cout endl;for (x = 0; x = times ; x+)nSplit = GetRandInt(20, 35);Deck TopDeck;Deck BottomDeck;int i;int nBottomNum = 1;112017 级紫金学院 C+ 课程设计int nTopNum = 1;for (i = 0; i m_cardarrayi; n

14、TopNum+;i+;for (i = (nSplit); i m_cardarrayi;nBottomNum+;i+;int nOutNum = 0;int nNumToTop;int nNumToBottom;int j;int h = 0;nBottomNum = 54 - nSplit;/52nTopNum = nSplit;while (nOutNum 53) /5112紫金学院 C+ 课程设计nNumToTop = GetRandInt(2, 7);nNumToBottom = GetRandInt(2, 7);for(j = 0; j 0)forthis -m_cardarray

15、nOutNum = BottomDeck.m_cardarraynBottomNum;nOutNum+;nBottomNum-;(h = 0; h 0) & (nOutNum m_cardarraynOutNum = TopDeck.m_cardarraynTopNum;nOutNum+;nTopNum-;2017 级132017 级紫金学院 C+ 课程设计this -nLastDelt = -1;void Deck :RemoveCard() / 将删除的那张牌清零m_cardarraynLastDelt = PlayingCard ();/ 清零void Deck :DealOne() /

16、 从一副扑克牌中删除一张牌if (nLastDelt != 53) /51nLastDelt+;cout.width(5);cout endl;cout 删除牌 :;m_cardarraynLastDelt.ShowCard();RemoveCard();elsecout 这副牌全部删除完了 ;14紫金学院 C+ 课程设计2017 级ProgClose();Deck :Deck() / 初始化一副扑克牌,将 52 张扑克牌均清零intlastdelt = 0;for(int i = 0; i = 53; i+) /51m_cardarrayi = PlayingCard ();Main 调用的

17、函数 .cpp#include class.h #include using namespacestd;void ProgramInit()/ 程序一开始的提示信息char a11 = 扑克牌游戏 ;char b25 = 单击 键开始 ;152017 级紫金学院 C+ 课程设计CenterText(a);cout endl n ;CenterText(b);cin.get();char GetKey() / 从键盘接收一个字符,将其作为函数返回值char x;x = cin.get();cout endl;return x;void CenterText( char ShellText 80)

18、 / 居中算法int nCenter;int nLength;nLength = strlen( ShellText );nCenter = (80 - nLength) / 2;for (; nCenter != 0; nCenter-)16紫金学院 C+ 课程设计2017 级cout ;cout ShellText ;int GetNumber() / 从键盘接收一个整数值,作为函数返回值char a40 = 请输入一个在 0到51之间的整数 ,输入52退出. ;int nInputInteger = 0;CenterText(a);cout nInputInteger;return nI

19、nputInteger;void ProgClose() / 程序暂停,按任意键继续cout endl endl;cout 单击 键继续 endl;cout endl endl;GetKey();cin.get();172017 级紫金学院 C+ 课程设计void DeckMakeDiver() / 主要程序操作部分,调用多个函数,包含完整生成一副牌,洗牌,显示,删除等操 作Deck deck_1;deck_1.MakeDeck();deck_1.ShowDeck();GetKey();deck_1.DeckShuff(250);deck_1.ShowDeck();cout endl endl

20、 endl;char y;PlayDeck F;F.PlayCard(deck_1);cout endl endl endl;F.Show();int g = 0;dochar a9 = 游戏规则 ;char b23 = 删除一位玩家的牌 输入 1 ;182017 级紫金学院 C+ 课程设计char c23 = 删除四位玩家的牌 输入 2 ; char d23 = 按牌的面值排序输入 3 ;char e23 = 按牌的花色排序输入 4 ;char f23 = 显示四位玩家手牌 输入 5 ; char q23 = 按N(n) 退出游戏 ;CenterText(a); cout endl; Cen

21、terText(b);cout endl;CenterText(c); cout endl;CenterText(d); cout endl;CenterText(e); cout endl; CenterText(f); cout endl;CenterText(q); cout g;if (g = 1)192017 级紫金学院 C+ 课程设计int j, k;char h;cout 请输入删除玩家的编号和牌号(从左往右数的第 N 张) j k;F.DeleteOne(j, k);cout endl 是( Y)否( N )显示删除后的手牌 ? h;h= toupper(h);if (h =

22、Y )F.s(j);cout endl;if (g = 2)int w, x, h, z;char y;cout 请依次输入欲删除各玩家牌的序号。 w x h z;F.DeleteAll(w, x, h, z);cout endl 是( Y)否( N )显示删除后玩家的牌? y;y = toupper(y);if (y = Y )F.Show();202017 级紫金学院 C+ 课程设计cout endl;if (g = 3)int h;char y;cout 请输入需要排序的玩家 h;F.SortDeckFace(h);cout 是( Y)否( N )显示排序后的牌? y;y = toupp

23、er(y);if (y = Y )F.s(h);if (g = 4)int x;char y;cout 请输入需要排序玩家的序号 x;F.SortDeckSuit(x);cout 是(Y)否(N) 显示排序后的牌? y;y = toupper(y);if (y = Y )F.s(x);if (g = 5)F.Show();if (g = 78 | g = 110)goto loop;cout 是(Y)否(N) 回到游戏规则菜单 ? endl;cout y;y= toupper(y); while (y = Y);loop:;s的一部分)int GetRandInt( int nMin , in

24、t nMax )/ 返回 min 至 max 之间的任意一值(实际上是“洗牌算法”222017 级紫金学院 C+ 课程设计int nNumToReturn;nNumToReturn = rand();nNumToReturn = nNumToReturn % (nMax - nMin + 1) + nMinreturn nNumToReturn;Playingcard.cpp#include class.h#include using namespace std;PlayingCard :PlayingCard() / 扑克牌对象的构造函数for (int i = 1; i = 3;)achF

25、acei = ;i+;chSuit = ;nValue = 0;void PlayingCard :ShowCard() / 在屏幕上显示一张扑克牌的面值及花色232017 级紫金学院 C+ 课程设计cout ;cout achFace;cout.width(1);cout chSuit;cout ;void PlayingCard :CardMake( int nNum )/ 根据参数 nNum 生成一张扑克牌, nNum 不同,生成的面值或花 色不同int i = 0;char j;int nFaceNum = nNum % 13;if (nNum = 52)strcpy(achFace,

26、 S);goto loop;if (nNum = 53)strcpy(achFace, B);24紫金学院 C+ 课程设计2017 级goto loop;switch (nFaceNum)case 0:strcpy(achFace,A ); break ;case 9:strcpy(achFace,10 ); breakcase 10:strcpy(achFace,J); break ;case 11:strcpy(achFace,Q ); breakcase 12:strcpy(achFace,K ); breakdefault :j = char (nFaceNum + 49);if (i

27、 3)achFacei = ; i+;achFacei = j; i+;achFacei = NULL;break ;loop:;if (nNum 12 & nNum 25 & nNum 38 & nNum = 51)chSuit = 4; / 方块if (nFaceNum = 10)nValue = 10;if (nNum = 52)nValue = 11;chSuit = 49;if (nNum = 53)nValue = 12;chSuit = 50;Perdeck.cpp#include #include class.husing namespace std;void PerDeck

28、:MakePerDeck( Deck & d, int a)26紫金学院 C+ 课程设计2017 级nNum = a;int i = 0;while (i a& d .nLastDelt != 53)d.nLastDelt;myCardi+ = d .m_cardarray+void PerDeck :Show()char a12 = 该玩家的牌 : ;int nNewLine = 0;CenterText(a);cout endl;while (nNewLine nNum)if (nNewLine % 5 = 0)cout endl;myCardnNewLine+.ShowCard();cout endl;27紫金学院 C+ 课程设计2017 级void PerDeck :SortFace() / 冒泡PlayingCard k;for (int i=0;inNum;i+)for (int j=0;

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论