MFC 扑克编程思路

MFC 扑克编程思路,第1张

还是挺麻烦的。先要SOCKET通信底子打好。然后研究出牌,发牌的逻辑。局掘就是对照现实。不一样的就是,服务器端激腊逗到底该做什么事情,需要好好思考。另外,图像方面还是有一定要求的。你得知道什么时候更新,怎么贴图。呵呵明卖。得花不少时间吧。就算做个简化版,一个人完成的话还是很困难的。

/*

*我不能给出完整程序,只能提供一个框架,首先每一张牌都是相异的,对于一副牌的存储,不

*妨用数组或者链表。对于花色和牌面属性,用数字和字串来存都行。

*对于发牌函数,就是一个随机数加链表或数组的查找 *** 作

*/

#ifndef card_h

#define card_h

#include "unit.h" //这个里面可以写描述牌的类,包括每一张牌属性

//和函数,属性包括牌面、花色,函数可以有显示本张拍信息show()

//,还应该穗答有获得各个属性的get或set函数

#include <iostream>

#include <cstdlib>

#include <ctime>

using namespace std

class A_Set_Card //描述一副牌

{

private:

unit *top//表头

int n//当前这副牌中有多少张牌

public:

card()//构造函数

~card() //析构,这个别忘了

unit* outputone() //随机派一张牌

void creat() //产生不含大小王的一副牌

}

/*

*构造,刚开始时这幅牌为空,(也可以把create函数写到构造函数里边)

*/

A_Set_Card::A_Set_Card()

{

top = NULL

n = 0

}

A_Set_Card::~A_Set_Card() //析构函数

{

unit *tem = top//从表头开始

top = NULL

while (tem) //如果null != tem

{

unit *pp = tem //用指针pp接住tem所指向的单元

tem = tem->nextp//tem后移

delete pp //析构掉刚才tem所指的单元

}

n = 0 //这幅牌中牌数归零

cout<<"。。。洗完牌。。。"<<endl

}

/*

*创建一副牌,不含大小王

*/

void A_Set_Card::create()

{

for(int j=1j<5j++) //j的取值{1、2、3、4}代表四猜让慧种花色

{

for(int i=1i<14i++) //i的取值{1...13}代表A到K,13种牌面,共13*4 = 52张

{

unit *newp = new unit//生成一张牌

n++

newp->inputnum(i) //inputnum()函数用来设置牌面,具体到unit.h里描述单张牌的类中去写

if(j == 1)

{

newp->inputname("黑桃")//inputname()函数用来设置花色

}

else if (j == 2)

{

newp->inputname("红桃")

}

else if (j == 3)

{

newp->inputname("梅花")

}

else

{

newp->inputname("方块")

}

if (top == NULL) //第一张

{

top = newp

top->nextp = NULL

}

else //非第一张

{

unit *tem = top

top = newp

top->nextp = tem

}

}

}

}

/*

* 随机滑磨发一张牌,返回那张牌的对象,我觉得稍微有点难的就在这个函数

*/

unit* A_Set_Card::outputone()

{

unit *tem = top//接过头

srand(time(0)) //设置随机种子

int nn = rand()%n//在这副牌中剩余的所有牌里随机选一张

if (nn == 0)//恰好是第一张

{

if(tem==NULL)//若空

{

cout<<"空链表"<<endl

return NULL

}

top = tem->nextp

n--

return tem

}

else//非第一张

{

for (int i=0i<nn-1i++) //tem往下移nn次

{

tem = tem->nextp

}

if(tem==NULL)//若空

{

cout<<"空链表"<<endl

return NULL

}

else

{

unit *pp = tem->nextp//删除这一张

tem->nextp = tem->nextp->nextp

n--//记住牌数自减

return pp

}

}

}

/*

*然后是排序函数,其实都挺简单,我就写到这吧,希望对你有所帮助

*/

void A_Set_Card::sort()

{}

#endif


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/8259875.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-14
下一篇2023-04-14

发表评论

登录后才能评论

评论列表(0条)

    保存