📄 form1.frm
字号:
VERSION 5.00
Begin VB.Form Form1
Caption = "押大小"
ClientHeight = 4455
ClientLeft = 60
ClientTop = 345
ClientWidth = 8265
LinkTopic = "Form1"
ScaleHeight = 4455
ScaleWidth = 8265
StartUpPosition = 2 '屏幕中心
Begin VB.PictureBox picValue
BorderStyle = 0 'None
Height = 480
Index = 2
Left = 2520
Picture = "Form1.frx":0000
ScaleHeight = 480
ScaleWidth = 480
TabIndex = 14
Top = 1560
Width = 480
End
Begin VB.PictureBox picValue
BorderStyle = 0 'None
Height = 480
Index = 1
Left = 1080
Picture = "Form1.frx":4842
ScaleHeight = 480
ScaleWidth = 480
TabIndex = 13
Top = 1560
Width = 480
End
Begin VB.PictureBox picValue
BorderStyle = 0 'None
Height = 480
Index = 0
Left = 1800
Picture = "Form1.frx":9084
ScaleHeight = 480
ScaleWidth = 480
TabIndex = 12
Top = 720
Width = 480
End
Begin VB.OptionButton Option2
Caption = "小"
Height = 495
Left = 5640
Style = 1 'Graphical
TabIndex = 9
Top = 3240
Width = 1215
End
Begin VB.OptionButton Option1
Caption = "大"
Height = 495
Left = 4320
Style = 1 'Graphical
TabIndex = 8
Top = 3240
Value = -1 'True
Width = 1215
End
Begin VB.Timer Timer1
Interval = 50
Left = 0
Top = 0
End
Begin VB.CommandButton Command3
Caption = "金盆洗手"
Height = 495
Left = 6960
TabIndex = 7
Top = 3840
Width = 1215
End
Begin VB.CommandButton Command2
Caption = "开始"
Height = 495
Left = 5640
TabIndex = 6
Top = 3840
Width = 1215
End
Begin VB.CommandButton Command1
Caption = "押注"
Height = 495
Left = 4320
TabIndex = 5
Top = 3840
Width = 1215
End
Begin VB.PictureBox Picture1
AutoRedraw = -1 'True
AutoSize = -1 'True
BorderStyle = 0 'None
Height = 480
Left = 0
Picture = "Form1.frx":D8C6
ScaleHeight = 480
ScaleWidth = 2880
TabIndex = 11
Top = 0
Visible = 0 'False
Width = 2880
End
Begin VB.Label Label6
Alignment = 2 'Center
BorderStyle = 1 'Fixed Single
BeginProperty Font
Name = "楷体_GB2312"
Size = 42
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H000080FF&
Height = 945
Left = 1545
TabIndex = 4
Top = 3240
Width = 1005
End
Begin VB.Label Label5
Alignment = 2 'Center
BeginProperty Font
Name = "楷体_GB2312"
Size = 24
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00C00000&
Height = 645
Left = 4320
TabIndex = 10
Top = 2160
Width = 3735
End
Begin VB.Label Label4
AutoSize = -1 'True
Caption = "Label4"
BeginProperty Font
Name = "楷体_GB2312"
Size = 21.75
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 435
Left = 6480
TabIndex = 3
Top = 1200
Width = 1350
End
Begin VB.Label Label3
Alignment = 1 'Right Justify
AutoSize = -1 'True
Caption = "押注:"
BeginProperty Font
Name = "楷体_GB2312"
Size = 21.75
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 435
Left = 4920
TabIndex = 2
Top = 1200
Width = 1350
End
Begin VB.Label Label2
AutoSize = -1 'True
Caption = "Label2"
BeginProperty Font
Name = "楷体_GB2312"
Size = 21.75
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 435
Left = 6480
TabIndex = 1
Top = 360
Width = 1350
End
Begin VB.Label Label1
Alignment = 1 'Right Justify
AutoSize = -1 'True
Caption = "你的现金:"
BeginProperty Font
Name = "楷体_GB2312"
Size = 21.75
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 435
Left = 4080
TabIndex = 0
Top = 360
Width = 2250
End
Begin VB.Shape Shape1
BackColor = &H00C0FFC0&
BackStyle = 1 'Opaque
BorderColor = &H0080C0FF&
BorderWidth = 2
FillColor = &H0080FF80&
FillStyle = 7 'Diagonal Cross
Height = 2775
Left = 240
Shape = 2 'Oval
Top = 240
Width = 3615
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
' 显示图像的API函数声明
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
' 全局变量
Private Money As Long ' 你的现金
Private Bet As Long ' 你本轮押注的钱数
Private Value(2) As Integer ' 骰子面值 1~6,一共3个骰子
Private Betting As Boolean ' 骰子是否正在滚动(若是,则现在不能押注)
' 程序从这里开始(加载窗体)
Private Sub Form_Load()
' 各变量赋初值
Betting = False ' 骰子还没滚动
Money = 1000 ' 现金等,各变量的意义见上
Bet = 0
Label2.Caption = Money ' 显示现金及押注
Label4.Caption = Bet
' 接下来:
' 当按“押注”按钮时,系统自动调用 Command1_Click() 函数
' 骰子没滚动时,若按“开始”按钮,则调用 Command2_Click()
' 骰子滚动时,“开始”按钮已变成“停!”按钮(参见 Command2_Click())
' 若按“停!”按钮,则调用 Command2_Click()
' 当按“金盆洗手”按钮时,调用 Command3_Click()
' 每隔 0.05 秒时,系统调用 Timer1_Timer()
' 请分别参考下面的函数实现
End Sub
' 当有“押注”按钮被按下的事件发生时,系统自动调用该函数
Private Sub Command1_Click()
' 如果骰子没有滚动并且现金有10元以上,则押注10元
If Not Betting And Money >= 10 Then
Bet = Bet + 10
Money = Money - 10
' 因为现金和押注金额已经变化,所以要更新显示
Label2.Caption = Money
Label4.Caption = Bet
Label5.Caption = ""
Label6.Caption = ""
End If
End Sub
' Command2 按钮按下(“开始”按钮或“停!”按钮)
Private Sub Command2_Click()
' 分析该函数请结合运行效果
' 首先,要有押注这个按钮才有效(想想实际情况)
If Bet > 0 Then
' 如果骰子滚动,则停止,反之亦然
Betting = Not Betting
If Betting Then
' 如果刚才没有滚动,则按按钮后骰子滚动(Betting = True)
' 按钮文字变成“停!”,表示再按一下就停
Command2.Caption = "停!"
Label5.Caption = ""
Else
' 这是刚才按钮滚动,现在已经停止的情况
' 按钮文字变成“开始”,表示再按一下就开始
Command2.Caption = "开始"
' 显示结果
If Value(0) + Value(1) + Value(2) > 6 Then
Label6.Caption = "大"
Else
Label6.Caption = "小"
End If
' 如果骰子值为大(小),并且“大(小)”按钮被按下……
If (Value(0) + Value(1) + Value(2) > 6 And Option1.Value) Or (Value(0) + Value(1) + Value(2) < 7 And Option2.Value) Then
' 则赢钱
Money = Money + Bet * 2
Label5.Caption = "你赢了" & Bet & "元!"
Else
' 否则输钱
Label5.Caption = "你输了" & Bet & "元!"
If Money = 0 Then
MsgBox "请重新来过!", , "你输光了!"
End
End If
End If
Bet = 0
Label2.Caption = Money
Label4.Caption = "0"
End If
End If
End Sub
' “金盆洗手”按钮按下
Private Sub Command3_Click()
Unload Me ' 从内存中卸载窗体(程序退出)
End Sub
' Timer1 控件每一时钟周期(已设为 0.05 秒)
Private Sub Timer1_Timer()
' 如果骰子在滚动则面值变化
Dim i As Long
If Betting Then
For i = 0 To 2
Value(i) = Int(Rnd * 6)
BitBlt picValue(i).hDC, 0, 0, 32, 32, Picture1.hDC, Value(i) * 32, 0, vbSrcCopy
Next
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -