问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501
你好,欢迎来到懂视!登录注册
当前位置: 首页 - 正文

...扑克牌,并实现对这副扑克牌洗牌、整牌和发牌三个功能

发布网友 发布时间:2024-10-24 01:17

我来回答

2个回答

热心网友 时间:2024-11-04 20:59

#include <iostream>
#include <ctime>

using namespace std;

//全局变量,一副牌
//*****************************************************************************************
int g_cards[54] = {

0, 1, 2, 3, // 3
10, 11, 12, 13, // 4
20, 21, 22, 23, // 5
30, 31, 32, 33, // 6
40, 41, 42, 43, // 7
50, 51, 52, 53, // 8
60, 61, 62, 63, // 9
70, 71, 72, 73, // 10
80, 81, 82, 83, // J
90, 91, 92, 93, // Q
100, 101, 102, 103, // K
110, 111, 112, 113, // A
120, 121, 122, 123, // 2
130, //小王
140 //大王

};

void xipai() //洗牌全局函数
{
srand( time(NULL) ); //设置种子
for(int i=0; i<54 ; i++)
{
int position = rand()%54;
int temp = g_cards[i]; //与牌的下标进行互换
g_cards[i] = g_cards[position];
g_cards[position] = temp;
}
}
void showCards() //显示全局函数
{
for(int i=0; i<54 ; i++)
{
if( g_cards[i] != 130 && g_cards[i] !=140 )
{
switch(g_cards[i]%10)
{
case 0:
cout<<"黑桃:";
break;
case 1:
cout<<"红桃:";
break;
case 2:
cout<<"梅花:";
break;
case 3:
cout<<"方片:";
break;
}
}
switch(g_cards[i]/10)
{
case 0:
cout<<"3:"<<endl;
break;
case 1:
cout<<"4:"<<endl;
break;
case 2:
cout<<"5:"<<endl;
break;
case 3:
cout<<"6:"<<endl;
break;
case 4:
cout<<"7:"<<endl;
break;
case 5:
cout<<"8:"<<endl;
break;
case 6:
cout<<"9:"<<endl;
break;
case 7:
cout<<"10:"<<endl;
break;
case 8:
cout<<"J:"<<endl;
break;
case 9:
cout<<"Q:"<<endl;
break;
case 10:
cout<<"K:"<<endl;
break;
case 11:
cout<<"A:"<<endl;
break;
case 12:
cout<<"2:"<<endl;
break;
case 13:
cout<<"小王:"<<endl;
break;
case 14:
cout<<"大王:"<<endl;
break;
}
}
}
//******************************************************************************************
struct CARDMESSAGE
{

//牌型, 牌的信息
int cardType; //牌型 0 单牌 1 双牌 2 三带一/二 3 四带一/二 4 顺子 5 连对 6 飞机 7 炸弹
int size; //牌的张数
int value; //牌值
int num; //连对或者飞机的顺数, -1为无限制
bool isLord; //是否是地主出的牌

void show()
{
switch(cardType)
{
case 0:
cout<<"单张:"<<endl;
break;

case 1:
cout<<"两张:"<<endl;
break;
case 2:
{
if(size==4)
cout<<"三带一:"<<endl;
else
cout<<"三带二:"<<endl;
}
case 3:
{
if(size == 5)
cout<<"四带一"<<endl;
else
cout<<"四带二"<<endl;
}
case 4:
{
cout<<"顺子"<<endl;
}
case 5:
{
cout<<"连对"<<endl;
}
case 6:
{
cout<<"飞机"<<endl;
}
case 7:
{
cout<<"炸弹"<<endl;
}

}
break;
}
switch(value%10)
{
case 0:
cout<<"黑桃:"<<endl;
break;
case 1:
cout<<"红桃:"<<endl;
break;
case 2:
cout<<"梅花:"<<endl;
break;
case 3:
cout<<"方片:"<<endl;
break;
}
switch(value/10)
{
case 0:
cout<<"3:"<<endl;
break;
case 1:
cout<<"4:"<<endl;
break;
case 2:
cout<<"5:"<<endl;
break;
case 3:
cout<<"6:"<<endl;
break;
case 4:
cout<<"7:"<<endl;
break;
case 5:
cout<<"8:"<<endl;
break;
case 6:
cout<<"9:"<<endl;
break;
case 7:
cout<<"10:"<<endl;
break;
case 8:
cout<<"J:"<<endl;
break;
case 9:
cout<<"Q:"<<endl;
break;
case 10:
cout<<"K:"<<endl;
break;
case 11:
cout<<"A:"<<endl;
break;
case 12:
cout<<"2:"<<endl;
break;
case 13:
cout<<"小王:"<<endl;
break;
case 14:
cout<<"大王:"<<endl;
break;
}
}
};
//******************************************************************************************
class Ccard
{
public:
int cardArray[20]; //保存所有牌的信息
int cardNum; //有效牌的张数
public:
Ccard();
~Ccard();
void sortCard();
void getCards(); //获得多张牌
void getOneCard(int card , int index ); //在发牌过程中获得一张牌
void show();
};
void Ccard::getOneCard(int card , int index )
{
cardArray[index] = card;
}
void Ccard::show()
{
for(int i=0; i<cardNum ; i++)
{
if( cardArray[i] != 130 && cardArray[i] !=140 )
{
switch(cardArray[i]%10)
{
case 0:
cout<<"黑桃:";
break;
case 1:
cout<<"红桃:";
break;
case 2:
cout<<"梅花:";
break;
case 3:
cout<<"方片:";
break;
}
}
switch(cardArray[i]/10)
{
case 0:
cout<<"3:" ;
break;
case 1:
cout<<"4:" ;
break;
case 2:
cout<<"5:" ;
break;
case 3:
cout<<"6:" ;
break;
case 4:
cout<<"7:" ;
break;
case 5:
cout<<"8:" ;
break;
case 6:
cout<<"9:" ;
break;
case 7:
cout<<"10:" ;
break;
case 8:
cout<<"J:" ;
break;
case 9:
cout<<"Q:" ;
break;
case 10:
cout<<"K:" ;
break;
case 11:
cout<<"A:" ;
break;
case 12:
cout<<"2:" ;
break;
case 13:
cout<<"小王:" ;
break;
case 14:
cout<<"大王:" ;
break;
}
}
}
Ccard::Ccard()
{
for( int j = 0; j<20 ;j++)
{
cardArray[j] = -1;
}
}
Ccard::~Ccard()
{
}
void Ccard::getCards()
{
for(int i=0; i<17 ; i++)
{
cardArray[i] = g_cards[i];
}
cardNum = 17;
}
void Ccard::sortCard()
{
for( int j = 0; j<cardNum-1 ;j++)
{
for(int i = 0; i<cardNum-1-j ;i++)
{
if( cardArray[i]<cardArray[i+1] )
{
int temp ;
temp = cardArray[i];
cardArray[i] = cardArray[i+1];
cardArray[i+1] = temp;
}
}
}
}
//******************************************************************************************
void fapai(Ccard& player1,Ccard& player2,Ccard& player3)
{
for(int i=0;i<17;i++)
{
player1.getOneCard( g_cards[i*3] , i);
player2.getOneCard( g_cards[i*3 + 1] , i);
player3.getOneCard( g_cards[i*3 + 2] , i);
player1.cardNum = 17;
player2.cardNum = 17;
player3.cardNum = 17;
}
}

int main()
{
Ccard a;
Ccard b;
Ccard c;
xipai(); //第一步 洗牌
fapai(a,b,c); //第二步 发牌
//第三步 发地主牌
a.show();
cout<<"******************************************************"<<endl;
b.show();
cout<<"******************************************************"<<endl;
c.show();
return 0;
}

以前学的时候写的不知道有没有用

热心网友 时间:2024-11-04 21:00

哎。。。。。貌似是作业题吧!哈哈。。。。楼上的哥们貌似是用c++做的吧,class都出来了!

热心网友 时间:2024-11-04 20:59

#include <iostream>
#include <ctime>

using namespace std;

//全局变量,一副牌
//*****************************************************************************************
int g_cards[54] = {

0, 1, 2, 3, // 3
10, 11, 12, 13, // 4
20, 21, 22, 23, // 5
30, 31, 32, 33, // 6
40, 41, 42, 43, // 7
50, 51, 52, 53, // 8
60, 61, 62, 63, // 9
70, 71, 72, 73, // 10
80, 81, 82, 83, // J
90, 91, 92, 93, // Q
100, 101, 102, 103, // K
110, 111, 112, 113, // A
120, 121, 122, 123, // 2
130, //小王
140 //大王

};

void xipai() //洗牌全局函数
{
srand( time(NULL) ); //设置种子
for(int i=0; i<54 ; i++)
{
int position = rand()%54;
int temp = g_cards[i]; //与牌的下标进行互换
g_cards[i] = g_cards[position];
g_cards[position] = temp;
}
}
void showCards() //显示全局函数
{
for(int i=0; i<54 ; i++)
{
if( g_cards[i] != 130 && g_cards[i] !=140 )
{
switch(g_cards[i]%10)
{
case 0:
cout<<"黑桃:";
break;
case 1:
cout<<"红桃:";
break;
case 2:
cout<<"梅花:";
break;
case 3:
cout<<"方片:";
break;
}
}
switch(g_cards[i]/10)
{
case 0:
cout<<"3:"<<endl;
break;
case 1:
cout<<"4:"<<endl;
break;
case 2:
cout<<"5:"<<endl;
break;
case 3:
cout<<"6:"<<endl;
break;
case 4:
cout<<"7:"<<endl;
break;
case 5:
cout<<"8:"<<endl;
break;
case 6:
cout<<"9:"<<endl;
break;
case 7:
cout<<"10:"<<endl;
break;
case 8:
cout<<"J:"<<endl;
break;
case 9:
cout<<"Q:"<<endl;
break;
case 10:
cout<<"K:"<<endl;
break;
case 11:
cout<<"A:"<<endl;
break;
case 12:
cout<<"2:"<<endl;
break;
case 13:
cout<<"小王:"<<endl;
break;
case 14:
cout<<"大王:"<<endl;
break;
}
}
}
//******************************************************************************************
struct CARDMESSAGE
{

//牌型, 牌的信息
int cardType; //牌型 0 单牌 1 双牌 2 三带一/二 3 四带一/二 4 顺子 5 连对 6 飞机 7 炸弹
int size; //牌的张数
int value; //牌值
int num; //连对或者飞机的顺数, -1为无限制
bool isLord; //是否是地主出的牌

void show()
{
switch(cardType)
{
case 0:
cout<<"单张:"<<endl;
break;

case 1:
cout<<"两张:"<<endl;
break;
case 2:
{
if(size==4)
cout<<"三带一:"<<endl;
else
cout<<"三带二:"<<endl;
}
case 3:
{
if(size == 5)
cout<<"四带一"<<endl;
else
cout<<"四带二"<<endl;
}
case 4:
{
cout<<"顺子"<<endl;
}
case 5:
{
cout<<"连对"<<endl;
}
case 6:
{
cout<<"飞机"<<endl;
}
case 7:
{
cout<<"炸弹"<<endl;
}

}
break;
}
switch(value%10)
{
case 0:
cout<<"黑桃:"<<endl;
break;
case 1:
cout<<"红桃:"<<endl;
break;
case 2:
cout<<"梅花:"<<endl;
break;
case 3:
cout<<"方片:"<<endl;
break;
}
switch(value/10)
{
case 0:
cout<<"3:"<<endl;
break;
case 1:
cout<<"4:"<<endl;
break;
case 2:
cout<<"5:"<<endl;
break;
case 3:
cout<<"6:"<<endl;
break;
case 4:
cout<<"7:"<<endl;
break;
case 5:
cout<<"8:"<<endl;
break;
case 6:
cout<<"9:"<<endl;
break;
case 7:
cout<<"10:"<<endl;
break;
case 8:
cout<<"J:"<<endl;
break;
case 9:
cout<<"Q:"<<endl;
break;
case 10:
cout<<"K:"<<endl;
break;
case 11:
cout<<"A:"<<endl;
break;
case 12:
cout<<"2:"<<endl;
break;
case 13:
cout<<"小王:"<<endl;
break;
case 14:
cout<<"大王:"<<endl;
break;
}
}
};
//******************************************************************************************
class Ccard
{
public:
int cardArray[20]; //保存所有牌的信息
int cardNum; //有效牌的张数
public:
Ccard();
~Ccard();
void sortCard();
void getCards(); //获得多张牌
void getOneCard(int card , int index ); //在发牌过程中获得一张牌
void show();
};
void Ccard::getOneCard(int card , int index )
{
cardArray[index] = card;
}
void Ccard::show()
{
for(int i=0; i<cardNum ; i++)
{
if( cardArray[i] != 130 && cardArray[i] !=140 )
{
switch(cardArray[i]%10)
{
case 0:
cout<<"黑桃:";
break;
case 1:
cout<<"红桃:";
break;
case 2:
cout<<"梅花:";
break;
case 3:
cout<<"方片:";
break;
}
}
switch(cardArray[i]/10)
{
case 0:
cout<<"3:" ;
break;
case 1:
cout<<"4:" ;
break;
case 2:
cout<<"5:" ;
break;
case 3:
cout<<"6:" ;
break;
case 4:
cout<<"7:" ;
break;
case 5:
cout<<"8:" ;
break;
case 6:
cout<<"9:" ;
break;
case 7:
cout<<"10:" ;
break;
case 8:
cout<<"J:" ;
break;
case 9:
cout<<"Q:" ;
break;
case 10:
cout<<"K:" ;
break;
case 11:
cout<<"A:" ;
break;
case 12:
cout<<"2:" ;
break;
case 13:
cout<<"小王:" ;
break;
case 14:
cout<<"大王:" ;
break;
}
}
}
Ccard::Ccard()
{
for( int j = 0; j<20 ;j++)
{
cardArray[j] = -1;
}
}
Ccard::~Ccard()
{
}
void Ccard::getCards()
{
for(int i=0; i<17 ; i++)
{
cardArray[i] = g_cards[i];
}
cardNum = 17;
}
void Ccard::sortCard()
{
for( int j = 0; j<cardNum-1 ;j++)
{
for(int i = 0; i<cardNum-1-j ;i++)
{
if( cardArray[i]<cardArray[i+1] )
{
int temp ;
temp = cardArray[i];
cardArray[i] = cardArray[i+1];
cardArray[i+1] = temp;
}
}
}
}
//******************************************************************************************
void fapai(Ccard& player1,Ccard& player2,Ccard& player3)
{
for(int i=0;i<17;i++)
{
player1.getOneCard( g_cards[i*3] , i);
player2.getOneCard( g_cards[i*3 + 1] , i);
player3.getOneCard( g_cards[i*3 + 2] , i);
player1.cardNum = 17;
player2.cardNum = 17;
player3.cardNum = 17;
}
}

int main()
{
Ccard a;
Ccard b;
Ccard c;
xipai(); //第一步 洗牌
fapai(a,b,c); //第二步 发牌
//第三步 发地主牌
a.show();
cout<<"******************************************************"<<endl;
b.show();
cout<<"******************************************************"<<endl;
c.show();
return 0;
}

以前学的时候写的不知道有没有用

热心网友 时间:2024-11-04 20:59

哎。。。。。貌似是作业题吧!哈哈。。。。楼上的哥们貌似是用c++做的吧,class都出来了!
声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。
E-MAIL:11247931@qq.com
九牧王淋浴花洒如何拆 卫浴知识:花洒套装价格参考 花洒花洒安装注意事项 九牧36190淋浴花洒套装-详细介绍 衡阳天气什么时候变冷 衡阳盆地地理 如何下载软件安装包 按照常规做法三金是男朋友买还是他父母买 从习俗角度讲三金是男朋友买还是他父母买 德国欧洲杯夺冠几次 欧洲杯各届夺冠的球队? 梅毒试验trust阴性trust阴性tppa阳性滴度1:160还有传染性吗?还需要治... ...TRUST) 阴性。梅毒抗体特异性实验(TPPA)1:5120。还有一 温控仪怎么调温度上下限? ...在山脚下做托里拆利实验时,管内外水银面的高度差为h1,如图所示,将... ...不准确的是( )A.往水银槽中多加些水银B.从山脚移到山顶 ...山顶,玻璃管中的水银柱会___.(填“上升”,“下降” 血管堵塞多少需要做支架 2022年跨年短信祝福语 造梦西游3去水下迷宫打第二波,人物怎么会动不了? 就被杀了 ...长2米,横截面是边长为5厘米的正方形,每立方分米钢重7.8千克,这根方... 老百姓安个卫星接收器看电视防碍了谁的利益?凭什么我非要看你的漫天广 ... 惠普m1005怎样换墨盒? 2022虎年元旦经典祝福语 2022元旦家长给老师的祝福短信温馨 ...米横截面是边长为五厘米的正方形它的表面积和体积各是多 2022年跨年短信祝福语 惠普m1005打印机出现Noprintcartridge 一、加拿大食品专业哪些大学好? 2022吉祥元旦祝福语短信 2022整点跨年祝福 2022跨年祝福短信[1] ...请设计一个程序完成自动发牌工作.要求不能有重复牌, 我有一个洗牌发牌的程序,但不知道哪错了。请高手帮忙看看 ...每张上分别写着一个整数P,Q,R,并且0&lt;P&lt;Q&lt;R.洗牌后 跨年祝福语大全2022年 有关2023跨年句子简短说说的短句(2023跨年——美丽新年的开始) 从马鞍山去张家港,没有直达的火车该怎么办?还有一切的具体价格。 从安徽马鞍山到江苏江阴或无锡,怎么坐车方便,最好下午 请问谁知道马鞍山到张家港的汽车每天几班,都是几点,哪个车站上车啊? ...宽是5分米,高是5分米.这个长方体有___个面是正方形,每个面的面积... 一个长方体的长是1米4分米,宽是5分米,高是5分米,这个长方体有___个面... 一个长方体的长是1米4分米,宽是5分米,高5分米,这个长方体有()个面是... 卡巴斯基6.0授权文件KEY 求卡巴6.0网络安全套装的KEY 从番禺市桥到广州南站近还是从番禺客运站去近??? 一个长方体的长是1m4dm,宽是5dm,高是5dm,这个长方体有()个面是正方形... ...上静止,左边紧靠竖直墙壁,试画出图1物体A所受力的示意 ...斜靠在光滑的竖直墙面上,另一端搁置在水平地面上静止,请画出... 蝶衣晒粉花枝午是指什么生肖,原文已解落实 父母离婚孩子怎么判 离婚孩子一般判给谁 东莞虎门这里的电信能拉包月的网线吗?
  • 焦点

最新推荐

猜你喜欢

热门推荐