|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 江上客-无类 于 2016-10-21 18:19 编辑
首先感谢 clb929 的分享
原文地址http://bbs.fishc.com/forum.php?mod=viewthread&tid=34808
通过他的实例 基本了解了一下 老虎机的基本构架和实现方法
代码比较简练 大多能看的懂
但对于 temp 这个值的用法存在疑虑 现将源码(考虑太长有适当删减) 贴在下方 求过路大神指点迷津
- unit tiger;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, StdCtrls, ExtCtrls;
- type
- TForm1 = class(TForm)
- Label1: TLabel;
- ...
- procedure Timer1Timer(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var //变量基础值和声明
- Form1: TForm1;
- Jifen: Integer = 100;
- Shu: Integer = 0;
- Niu: Integer = 0;
- Hu: Integer = 0;
- Tu: Integer = 0;
- Long: Integer = 0;
- She: Integer = 0;
- Ma: Integer = 0;
- Yang: Integer = 0;
- Hou: Integer = 0;
- Gou: Integer = 0;
- Ji: Integer = 0;
- Zhu: Integer = 0; //以上为十二个候选位置
- Sign: Integer = 0; //确定是否在进行中
- Result: Integer = 0; //确定结果
- [b][color=Red][size=5] Temp: Integer =0; //不明白是干什么的[/size][/color][/b]
- Time: Integer = 2;
- implementation
- {$R *.dfm}
- procedure TForm1.FormCreate(Sender: TObject); //窗口初始化积分
- begin
- Label17.Caption:= IntToStr( Jifen );
- end;
- procedure TForm1.Button2Click(Sender: TObject); //按下相关按钮开始加注 //共计12个按钮
- begin
- if ( Sign = 0 ) and ( Jifen > 0 )
- then
- begin
- Shu:= Shu + 10;
- Jifen:= Jifen - 10;
- Label31.Caption:= IntToStr( Shu );
- Label17.Caption:= IntToStr( Jifen );
- end;
- end;
- ...
- procedure TForm1.Button1Click(Sender: TObject); //按下开始摇奖按钮
- begin
- if ( Sign = 0 ) and ( ( Shu + Niu + Hu + Tu + Long + She + Ma + Yang + Hou + Gou + Ji + Zhu ) <> 0 )
- then
- begin
- Randomize;
- Sign:= 1; //进入摇奖模式
- Result:= Random( 16 ); //在十二个候选和2个特2个空总计16 个选项中计算出结果
- Timer1.Enabled:= True; //打开时间控件
- end;
- end;
- procedure TForm1.Timer1Timer(Sender: TObject);
- begin
- if ( Temp <= (Result + 16) ) //此处为疑问点,temp并未赋值 初始仅为0 Result的随机值为0~15 加16以后一定是大于Temp 这个判断究竟判断了什么?
- then
- begin
- case ( Temp ) of //这里就更迷糊了Temp只是0 如何进行case? 并没有随机赋值之类他的0以上的值从那来的呢?
- 0,16: //形成转动效果
- begin
- Label16.Color:= clAqua;
- Label1.Color:= clRed;
- end;
- ...
- 15,31:
- ..
- end;
- Temp:= Temp + 1; //这个也是一样不知道是计算了个什么?
- end
- else
- begin
- Timer1.Enabled:= False;
- case ( Result ) of
- 0: Jifen:= Jifen + Shu * 2 * Time; //根据结果计算出中奖积分 *Time 是相当于四倍么?比如押了10 中了得40?
- ..
- 15: Jifen:= Jifen + Zhu * 2 * Time;
- end;
- Label17.Caption:= IntToStr( Jifen ); //获得中奖积分
- Shu:= 0;
- ..
- Zhu:= 0;
- Sign:= 0;
- Result:= 0; //清零
- Temp:=0; //temp又变成0了。。。
- Label31.Caption:= IntToStr( Shu );
- Label32.Caption:= IntToStr( Niu );
- Label33.Caption:= IntToStr( Hu );
- Label34.Caption:= IntToStr( Tu );
- Label35.Caption:= IntToStr( Long );
- Label36.Caption:= IntToStr( She );
- Label37.Caption:= IntToStr( Ma );
- Label38.Caption:= IntToStr( Yang );
- Label39.Caption:= IntToStr( Hou );
- Label40.Caption:= IntToStr( Gou );
- Label41.Caption:= IntToStr( Ji );
- Label42.Caption:= IntToStr( Zhu );
- end;
- end;
- end.
复制代码
|
|