实验背景:

人:Joe、Bob和AI希望参见赛狗赌博。最初,Joe有50元,Bob有75元,AI有45元。每次比赛前,他们都会各自决定是否下注以及所押的赌金。直到比赛前,他们都可以改变赌金,但是一旦比赛开始,赌金就再不能更改了。

赌场:赌场会跟踪每个人持有的现金,以及每个人下注的对象。每次下注至少5元。一场比赛中,赌场对每个人只取一次赌金;也就是说每个人不得重复下注。赌场会检查下注的人确实有足够的现金支付他的赌金,所以如果没有钱来作赌资这个人就不能下注。

下注:每次下注都会“翻倍或全陪”,要求最低5元,而且每个人对一只狗最多下注15元。

比赛:有4只狗在直道上比赛。比赛胜者是第一只穿过终点线的狗。

书中给出的作为参考的类图:

参考别人的博客写的代码

Greyhound类

class Greyhound
{
public int Index; //狗的号码
public int StartingPosition=0;//图片起始坐标
public int RacetrackLength = 600; //路程
public PictureBox MyPictureBox = null; //图片控件
public int Location = 0;//已完成路程
public Random Randomizer;//
//构造函数
public Greyhound(PictureBox picturebox)
{
this.MyPictureBox = picturebox;
this.Index = index;
} public bool Run()
{ int speed=Randomizer.Next(1, 20);
Point p = MyPictureBox.Location;
p.X += speed;
System.Threading.Thread.Sleep(100);
MyPictureBox.Location = p;
if (p.X >= RacetrackLength)
return true;
else return false;
}
public void TakeStartingPosition()
{
this.MyPictureBox.Location = new Point(this.StartingPosition, MyPictureBox.Location.Y);
this.Location = 0;
}
}

对Grayhound初始化(学着点)

        void InitGrey()
{
grey = new Greyhound[]
{
new Greyhound(pictureBox2){Index=1,Randomizer=mainRand},
new Greyhound(pictureBox3){Index=2,Randomizer=mainRand},
new Greyhound(pictureBox4){Index=3,Randomizer=mainRand},
new Greyhound(pictureBox5){Index=4,Randomizer=mainRand},
};
}

Guy类

    public class Guy
{
public string Name;//姓名
public Bet Mybet=new Bet ();//赌注信息
public int Cash;//剩余现金 public RadioButton MyRadioButton;
public Label MyLabel; /// <summary>
/// 下注更新显示信息
/// </summary>
public void UpdateRadio()
{
MyRadioButton.Text = string.Format("{0} has {1} bucks",this.Name,this.Cash.ToString());
} /// <summary>
/// 重置赌注为0
/// </summary>
public void ClearBet()
{
MyLabel.Text=string.Format("{0} has't placed a bet",this.Name);
Mybet.Amout = 0;
} /// <summary>
/// 下注
/// </summary>
public bool PlaceBet(int Amout, int Dog)
{
if (Amout > this.Cash)
return false;
this.Mybet.Amout = Amout;
this.Mybet.Dog = Dog;
this.Mybet.Bettor = this;
MyLabel.Text= Mybet.GetDescription();
return true;
} /// <summary>
/// 清算结果
/// </summary>
public void Collect(int Winner)
{
this.Cash += this.Mybet.PayOut(Winner);
UpdateRadio();
ClearBet();
}
}

最新文章

  1. Android USB Gadget复合设备驱动(打印机)测试方法
  2. emacs不能使用中文输入法
  3. 深入浅出 nginx lua 为什么高性能
  4. 2016年12月8日 星期四 --出埃及记 Exodus 21:3
  5. Js中 关于top、clientTop、scrollTop、offsetTop的用法
  6. Android 自学之基本界面组件(下)
  7. 邮件发送小demo
  8. python 命令行参数,以及文件操作
  9. struts1吊牌&amp;lt;logic:iterate&amp;gt;
  10. js字符串操作
  11. ASP.NET没有魔法——ASP.NET MVC 模型绑定解析(上篇)
  12. 【django小练习之主机管理界面】
  13. Linux系统中查询发行版本号以及内核版本的命令总结
  14. 代码生成平台Xxl-Code-Generator
  15. spring cloud + .net core实现微服务架构
  16. C#判断远程计算机的指定端口是否打开的代码
  17. 练习题|网络编程-socket开发
  18. Linux入门命令1
  19. eclipse 配置jdk和maven
  20. 3 并发编程-(进程)-join方法

热门文章

  1. 移动支付之智能IC卡与Android手机进行NFC通信
  2. android——使用自带录屏工具进行屏幕录像
  3. web去掉浏览器自带默认样式
  4. jquery模仿css3延迟效果
  5. Python 线程(threading) 进程(multiprocessing)
  6. EasyuiCombobox三级联动
  7. OpenGL ES 2.0 shader开发
  8. (转) 学习C++ -&gt; 引用( References )
  9. Delphi线程同步
  10. 一个数n的最大质因子