?? dice.frm
字號:
VERSION 5.00
Begin VB.Form Form1
Appearance = 0 'Flat
BackColor = &H80000005&
BorderStyle = 1 'Fixed Single
Caption = "Beat The House"
ClientHeight = 3195
ClientLeft = 3540
ClientTop = 2745
ClientWidth = 4680
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
Picture = "Dice.frx":0000
ScaleHeight = 3195
ScaleWidth = 4680
Begin VB.CommandButton cmdQuit
Appearance = 0 'Flat
BackColor = &H000000C0&
Caption = "Quit"
Height = 375
Left = 480
Style = 1 'Graphical
TabIndex = 4
Top = 2400
Width = 1335
End
Begin VB.CommandButton cmdRollIt
Appearance = 0 'Flat
BackColor = &H000000C0&
Caption = "Roll It!"
Height = 375
Left = 480
Style = 1 'Graphical
TabIndex = 3
Top = 1920
Width = 1335
End
Begin VB.Label lblMessage
BackStyle = 0 'Transparent
Caption = "You Lose!!!"
BeginProperty Font
Name = "MS Sans Serif"
Size = 18
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H000000C0&
Height = 375
Left = 2280
TabIndex = 5
Top = 2400
Width = 2295
End
Begin VB.Label lblHouseRoll
Alignment = 2 'Center
Appearance = 0 'Flat
BackColor = &H80000005&
BackStyle = 0 'Transparent
Caption = "0"
BeginProperty Font
Name = "MS Sans Serif"
Size = 24
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00FFFFFF&
Height = 615
Left = 2760
TabIndex = 2
Top = 1080
Width = 615
End
Begin VB.Label lblMyRoll2
Alignment = 2 'Center
Appearance = 0 'Flat
BackColor = &H80000005&
BorderStyle = 1 'Fixed Single
Caption = "0"
BeginProperty Font
Name = "MS Sans Serif"
Size = 24
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H80000008&
Height = 615
Left = 1200
TabIndex = 1
Top = 1080
Width = 615
End
Begin VB.Label lblMyRoll1
Alignment = 2 'Center
Appearance = 0 'Flat
BackColor = &H80000005&
BorderStyle = 1 'Fixed Single
Caption = "0"
BeginProperty Font
Name = "MS Sans Serif"
Size = 24
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H80000008&
Height = 615
Left = 480
TabIndex = 0
Top = 1080
Width = 615
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'用“隨機數”模擬的擲篩子
'我們可以看到在VB中怎么取得隨機數
'--------------------------------------
'DICE.VBP 12/31/97
'Author: Burt Abreu
'E-Mail: habreu@bellsouth.net
'URL: http://www.vbexplorer.com
'
'Beginners program that shows an example
'how to use random number generator to
'simulate dice rolls. You should be able
'to use the function in your own games
'that need simulated dice rolls. Those
'with more experience will forgive the
'heavy commenting, this is for beginners.
'Enjoy!
'
'Feel free to use this program however you
'wish. All I ask is that if you post it you
'give me proper credit.
'---------------------------------------
Option Explicit 'Forces variable declarations
Option Base 1 'Sets the array start subscript to 1
'rather than default 0
Function RollDice(intNumOfSides, intNumOfDice) As Variant
Dim intIndex As Integer 'an index to point to array elements
Dim MyRoll() As Variant 'a dynamic array to hold each rolls dice totals
Dim intTotal As Integer 'variable that accumulates total
ReDim MyRoll(intNumOfDice)
'Redimensions the MyRoll array to the size indicated
'by the passed NumOfDice each time it is called. Then
'the For..Next..Loop loops once for each die, and
'accumulates a total using intTotal to allow for mult
'-iple rolls to be returned as a total rather than
'individual amounts as in the case of the lblHouseRoll.
For intIndex = 1 To intNumOfDice
Randomize
MyRoll(intIndex) = Fix(intNumOfSides * Rnd) + 1
intTotal = intTotal + MyRoll(intIndex)
RollDice = intTotal
Next intIndex
End Function
Private Sub cmdQuit_Click()
Unload Me
End Sub
Private Sub cmdRollIt_Click()
lblMyRoll1.Caption = RollDice(6, 1)
lblMyRoll2.Caption = RollDice(6, 1)
lblHouseRoll.Caption = RollDice(6, 2)
If lblMyRoll1.Caption + lblMyRoll2.Caption _
> lblHouseRoll.Caption Then
lblMessage.Caption = "You Win!!!"
ElseIf lblMyRoll1.Caption + lblMyRoll2.Caption _
< lblHouseRoll.Caption Then
lblMessage.Caption = "You Lose!!!"
Else
lblMessage.Caption = "You Tied!!!"
End If
End Sub
Private Sub Form_Load()
Dim intNumOfSides As Integer
Dim intNumOfDice As Integer
End Sub
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -