English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
所有分類

誰會用VB寫剪刀石頭布的程式?教教我吧.....急!簡易的就行了 thanks!

2006-02-25 19:23:15 · 1 個解答 · 發問者 花兒 1 in 電腦與網際網路 程式設計

1 個解答

Dim WithEvents L1 As CommandButton, WithEvents L2 As CommandButton, WithEvents L3 As CommandButton
Dim L As Label

Private Sub Form_Load()
Set L = Controls.Add("Vb.Label", "L")
L = "電腦": L.BorderStyle = 1: L.Alignment = 2: L.WordWrap = True: L.Visible = True
Set L1 = Controls.Add("Vb.CommandButton", "L1")
L1.Caption = "剪刀": L1.Top = L.Height + 30: L1.Tag = 0: L1.Visible = True
Set L2 = Controls.Add("Vb.CommandButton", "L2")
L2.Caption = "石頭": L2.Top = L1.Top: L2.Left = L1.Width + 30: L2.Tag = 1: L2.Visible = True
Set L3 = Controls.Add("Vb.CommandButton", "L3")
L3.Caption = "布": L3.Top = L1.Top: L3.Left = L2.Left + L2.Width + 30: L3.Tag = 2: L3.Visible = True
L.Width = L3.Left + L3.Width
End Sub

Sub Cal(N)
Dim I As Integer, S As String
Randomize
I = Int(Rnd * 3)
L = "電腦出 " & Switch(I = 0, "剪刀", I = 1, "石頭", I = 2, "布") & vbCrLf
If I = N Then
 L = L & "雙方平手"
ElseIf I > N Then
 If I - N = 1 Then
  L = L & "電腦贏"
 Else
  L = L & "電腦輸"
 End If
Else
 If N - I = 1 Then
  L = L & "電腦輸"
 Else
  L = L & "電腦贏"
 End If
End If
End Sub

Private Sub L1_Click()
Cal L1.Tag
End Sub

Private Sub L2_Click()
Cal L2.Tag
End Sub

Private Sub L3_Click()
Cal L3.Tag
End Sub

2006-02-28 19:12:25 · answer #1 · answered by W.J.S. 7 · 0 0

fedest.com, questions and answers