[09-24] C++模拟色盅游戏
今晚,¥兄请吃饭,朋友们教会了我玩色盅,觉得挺有意思的,并且用随机函数实现起来非常方便#include <iostream.h>
#include <stdlib.h>
#define size 6
class sezhong//色盅类
{
private:
int a;
int b;
int n,m;
int value;
int count;
public:
sezhong()
{count=0;value=0;}
void seta(sezhong &s)//初始化a玩家
{
int j;
for(int i=0;i<size-1;i++)
{
j=rand()%size;
s.a=j+1;
}
}
void setb(sezhong &s)//初始化b玩家
{
int j;
for(int i=0;i<size-1;i++)
{
j=rand()%size;
s.b=j+1;
}
}
void open(int n,int m,char ch);//开箱
void call();//
bool jya(); //检验a
bool jyb(); //检验b
};
sezhong sz;
void sezhong::pen(int n,int m,char ch)
{
if(n<=sz.count && m<=sz.value)
cout<<"错误!"<<endl;
else
{
if(ch=='a')
{ if(sz.jya()==true)
{cout<<"a玩家胜!";}
else
{cout<<"b玩家胜!";
return;}
}
if(ch=='b')
{
if(sz.jyb()==true)
{
cout<<"b玩家胜!";}
else
{cout<<"a玩家胜!";
return;}
}
}
}
bool sezhong::jya()
{
for(int i=0;i<size-1;i++)
{
if(sz.a==sz.m || sz.a==1)
sz.count++;
}
if(sz.count >= n)
return true;
else
return false;
}
bool sezhong::jyb()
{
for(int i=0;i<size-1;i++)
{
if(sz.b==sz.m || sz.b==1)
sz.count++;
}
if(sz.count >= n)
return true;
else
return false;
}
void sezhong::call()
{
cin>>sz.n>>sz.m;
}
void main()
{
cout<<"a玩家请输入要报的数量和大小:";
sz.call();
int i;
cout<<"b玩家请作选择:";
cin>>i;
if(i==1)
{
sz.open(sz.n,sz.m,'b');}
if(i==2)
{
sz.call();
cout<<"a玩家请作选择:";
cin>>i;
if(i==1)
{sz.open(sz.n,sz.m,'a');}
if(i==2)
{
sz.call();
}
}
}
这个程序不是很好,得想个办法实现无限次报数,本来想用GOTO:(
[ 本帖最后由 zkkpkk 于 2006-9-25 08:46 编辑 ] :handshake 有空偶也试试`` 我和他们玩这个总是输,要不是老师找我我恐怕又要酒精过敏了:L
页:
[1]