5.掷骰子游戏(随即取值)
来源:互联网 发布:win8网络共享无法访问 编辑:程序博客网 时间:2024/05/07 18:47
机会游戏(投骰子):游戏者投两枚骰子,每个骰子有六面,这些面包含1、2、3、4、5、6个点。投两枚骰子之后,计算点数之和。如果第一次投时的和为7或者11,则游戏者输,庄家赢。如果第一次投时的和为2、3或12,则游戏者获胜。如果第一投时的和为4、5、6、8、9或10,则这个和成为游戏者的点数,要想赢,就要继续投骰子,直到投出当前所拥有的点数,但如果在连投7次还没有投出该点数,则游戏者输。
#include<iostream.h>
#include<stdlib.h>
#include<time.h>
class Dice{
private:
static int count;
int a,b;
public:
void init(int x,int y)
{
a=x;
b=y;
count++;
return ;
}
int getdice1()
{
return a;
}
int getdice2()
{
return b;
}
int Getpoint()//骰子的点数
{
return a+b;
}
void print()//输出掷骰子的结果
{
cout<<"您第 "<<count<<" 次掷骰子的结果为:"<<endl
<<getdice1()<<" + "
<<getdice2()<<" = "
<<Getpoint()<<endl;
return ;
}
};
int Dice::count=0;
void Result(int a)//输出胜负结果
{
if(a==1)
cout<<"Player Wins !"<<endl;
else
cout<<"Player Loses !"<<endl;
return ;
}
void main()
{
srand( (unsigned)time( NULL ) );
int d;
Dice dice01;
dice01.init(1+rand()%6,1+rand()%6);
dice01.print();
int a=dice01.Getpoint();
if( a==4 || a==5 || a==6 || a==8 || a==9 || a==10 )
{
int i=0;
for(i=0;i<6;i++)
{
Dice dice02;
dice02.init(1+rand()%6,1+rand()%6);
dice02.print();
if(dice02.Getpoint()==a)
{
d=1;
break;
}
}
if(i==6)
d=0;
}
if(a==2 || a==3 || a==12)
{
d=1;
}
if(a==7 || a==11)
{
d=0;
}
Result(d);
return ;
}
- 5.掷骰子游戏(随即取值)
- 玩游戏(掷骰子)
- 6、掷骰子游戏(续5)
- 笔记(7)掷骰子游戏--CPrimer
- 掷骰子游戏
- 掷骰子游戏
- 掷骰子游戏
- C++掷骰子游戏
- ECHART 设置图表颜色(随即取)
- 实验作业:掷骰子游戏
- 骰子游戏
- 一个简单的掷骰子游戏
- 【HTML5/CSS3学习笔记】掷骰子游戏
- 【程序12】模拟掷骰子游戏
- 甲乙两人做游戏,掷三个骰子,比点数
- 掷骰子游戏 华为机试
- 掷骰子游戏-C语言实现
- java掷骰子游戏联机版
- JS函数集合大全
- ZIP解压
- C#下File.Copy的简单用法
- 软件人生
- 电子商务交易额2010有望达到15万亿元
- 5.掷骰子游戏(随即取值)
- 装饰模式
- JSTL 学习、应用记录
- c# 顾显清屏的类
- asp.net中的后台按钮如何先执行前台验证再执行后台代码
- 清晨第一杯水怎样喝最健康
- 近况
- [转]执子之手,方知子丑,泪流满面,子不走我走
- 虚拟妆容:化妆网站试身手 足不出户变造型