我的纸牌源代码!望各位指出其中的缺点共同学习!!!
#include <iostream.h>
#include <stdlib.h>
#include <time.h>
#define HEI '\6'
#define HONG '\3'
#define MEI '\5'
#define FANG '\4'
#define BOSS '\2'
#define XBOSS '\1'
class CPlayer //定义玩家类
{
public:
CPlayer() {};
void disp(); //显示牌的花色和数字
void send (int *);
static int status ;
private:
int arr[13];
};
int CPlayer::status = 0;
void CPlayer::disp()
{
for(int i = 0;i<13;i++)
{
if(52 == arr[i])
{
cout<<"第"<<i+1<<"张牌是: "<<XBOSS<<endl;
continue;
}
if(53 == arr[i])
{
cout<<"第"<<i+1<<"张牌是: "<<XBOSS<<endl;
continue;
}
switch(arr[i] / 13)
{
case 0:
cout<<"第"<<i+1<<"张牌是:"<<HEI<<arr[i]%13 +1 <<endl;
break;
case 1:
cout<<"第"<<i+1<<"张牌是:"<<HONG<<arr[i]%13 +1 <<endl;
break;
case 2:
cout<<"第"<<i+1<<"张牌是:"<<MEI<<arr[i]%13 +1 <<endl;
break;
case 3:
cout<<"第"<<i+1<<"张牌是:"<<FANG<<arr[i]%13 +1 <<endl;
break;
default:
cout<<"失败!!!";
}
}
}
void CPlayer::send(int *a)
{
for(int i = 0;i<13;i++)
{
arr[i] = *a;
a++;
}
}
class CPuke //定义扑克类
{
public:
CPuke(); //洗牌
void pro(CPlayer &); //发牌
private:
int puk[54];
};
}
CPuke::CPuke()
{
for(int i = 0; i <54; i++)
puk[i] = i;
srand(time(NULL));
for(int j = 0;j <100;j++)
{
int a = rand()%54;
int b = rand()%54;
int t = puk[a];
puk[a] = puk[b];
puk[b] = t;
}
}
void CPuke::pro(CPlayer& A)
{
int temp = A.status;
A.status ++;
A.send(puk + temp * 13);
}
我觉的这个源代码缺点多但是也有优点。。。。。。。缺点就是玩家类的显示牌的函数过于麻烦。。。而且无法显示A JQK。只能显示1,11,12,13;
但优点是易于排序。。。。。。。
请各位指点下哪些地方需要改进以及改进的代码。。。。。在此谢过。。。大家共同学习!!!
#include <stdlib.h>
#include <time.h>
#define HEI '\6'
#define HONG '\3'
#define MEI '\5'
#define FANG '\4'
#define BOSS '\2'
#define XBOSS '\1'
class CPlayer //定义玩家类
{
public:
CPlayer() {};
void disp(); //显示牌的花色和数字
void send (int *);
static int status ;
private:
int arr[13];
};
int CPlayer::status = 0;
void CPlayer::disp()
{
for(int i = 0;i<13;i++)
{
if(52 == arr[i])
{
cout<<"第"<<i+1<<"张牌是: "<<XBOSS<<endl;
continue;
}
if(53 == arr[i])
{
cout<<"第"<<i+1<<"张牌是: "<<XBOSS<<endl;
continue;
}
switch(arr[i] / 13)
{
case 0:
cout<<"第"<<i+1<<"张牌是:"<<HEI<<arr[i]%13 +1 <<endl;
break;
case 1:
cout<<"第"<<i+1<<"张牌是:"<<HONG<<arr[i]%13 +1 <<endl;
break;
case 2:
cout<<"第"<<i+1<<"张牌是:"<<MEI<<arr[i]%13 +1 <<endl;
break;
case 3:
cout<<"第"<<i+1<<"张牌是:"<<FANG<<arr[i]%13 +1 <<endl;
break;
default:
cout<<"失败!!!";
}
}
}
void CPlayer::send(int *a)
{
for(int i = 0;i<13;i++)
{
arr[i] = *a;
a++;
}
}
class CPuke //定义扑克类
{
public:
CPuke(); //洗牌
void pro(CPlayer &); //发牌
private:
int puk[54];
};
}
CPuke::CPuke()
{
for(int i = 0; i <54; i++)
puk[i] = i;
srand(time(NULL));
for(int j = 0;j <100;j++)
{
int a = rand()%54;
int b = rand()%54;
int t = puk[a];
puk[a] = puk[b];
puk[b] = t;
}
}
void CPuke::pro(CPlayer& A)
{
int temp = A.status;
A.status ++;
A.send(puk + temp * 13);
}
我觉的这个源代码缺点多但是也有优点。。。。。。。缺点就是玩家类的显示牌的函数过于麻烦。。。而且无法显示A JQK。只能显示1,11,12,13;
但优点是易于排序。。。。。。。
请各位指点下哪些地方需要改进以及改进的代码。。。。。在此谢过。。。大家共同学习!!!
作者: hui211314dd 发布时间: 2011-06-15
只是来看洗牌的办法的,,果然 是随机,,,随机最怕的就是最后几张牌,一直随机不到~~~~速度就这样慢在这里了,,,不只楼主有这情况么?说来听听
作者: dxy0613 发布时间: 2011-06-15