- 最後登錄
- 2022-11-24
- 在線時間
- 271 小時
- 註冊時間
- 2008-9-2
- 閱讀權限
- 20
- 精華
- 0
- UID
- 4896884
- 帖子
- 541
- 積分
- 212 點
- 潛水值
- 13707 米
| 成為伊莉的版主,你將獲得更高級和無限的權限。把你感興趣的版面一步步地發展和豐盛,那種滿足感等著你來嚐嚐喔。 本帖最後由 rr09192084 於 2010-6-1 02:43 PM 編輯
用VB6寫的撲克牌小遊戲(4支刀)- Dim colors(8)As Variant, points(8) As Variant
- Dim mysum(2)As Variant, gsum(2) As Variant
- Dim poker_issame(5) As Boolean
- Dim win As Integer
- Private Sub Form_Load()
- Dim i As Integer Command2.Visible = False For i = 0 To 7 Picture1(i).BorderStyle = 0 Picture1(i).DragMode = 1 Picture1(i).Visible = False Next i For i = 0 To 3 Label1(i).Visible = False Label2(i).Visible = False Next i Label5.Visible = FalseEnd Sub
- Private Sub Command1_Click() Dim i As Integer Label5.Visible = False For i = 0 To 3 Label1(i).Visible = True Label2(i).Visible = True Next i Command1.Visible = False Command2.Visible = True Label2(2).Caption = "" Label2(3).Caption = "" Call showPoker Call calc_poker(0, mysum(), Label2(0), Label2(1))
- End Sub
- Private Sub Command2_Click()
- Command1.Visible = TrueCommand2.Visible = Falsewin = 0Label5.Visible = TrueLabel5.Caption = ""Dim i As IntegerFor i = 8 To 5 Step -1 Picture1(i - 1).Picture = LoadPicture(App.Path & "\Poker\" & colors(i) & "-" & points(i) & ".jpg") Call wait(0.05)Next iCall calc_poker(4, gsum(), Label2(2), Label2(3))If gsum(0) > gsum(1) Then Call swap_pic(Picture1(4), Picture1(6)) Call swap_pic(Picture1(5), Picture1(7)) Call calc_poker(4, gsum(), Label2(2), Label2(3))End IfIf mysum(0) > mysum(1) Then win = -3 Label5.Caption = Label5.Caption & "閒家烏龍,莊家贏!!"Else For i = 0 To 1 If mysum(i) > gsum(i) Then win = win + 1 Else win = win - 1 End If Next i If win > 0 Then Label5.Caption = Label5.Caption & "閒家贏!!" Else If win < 0 Then Label5.Caption = Label5.Caption & "莊家贏!!" Else Label5.Caption = Label5.Caption & "平手!!" End IfEnd If
- End Sub
- Private Sub wait(Optional ByVal sgnSecondToDelay As Single) Dim sgnThisTime As Single, sgnCount As Single If sgnSecondToDelay = 0 Then Exit Sub Else If sgnSecondToDelay < 0.01 Then sgnSecondToDelay = 0.01 End If End If sgnThisTime = Timer Do While sgnCount < sgnSecondToDelay sgnCount = Timer - sgnThisTime DoEvents LoopEnd Sub
- Private Sub showPoker()
- Dim i, j, k As Integermycelect = 0
- For i = 1 To 8 Picture1(i - 1).AutoSize = True Picture1(i - 1).Picture = LoadPicture(App.Path & "\poker\6-1.jpg") Picture1(i - 1).Visible = FalseNext i
- For i = 0 To 3 Picture1(i).Visible = True Call wait(0.2) Picture1(i + 4).Visible = True Call wait(0.2) For j = 0 To 3 Picture1(i).Left = j * 1000 Picture1(i).Top = j * 800 + 4000 Call wait(0.01) Next j Picture1(i).Left = i * 2200 + 300 Picture1(i).Top = 8500
- For k = 0 To 3 Picture1(i + 4).Left = j * 1000 Picture1(i + 4).Top = 4000 - j * 600 Call wait(0.03) Next k Picture1(i + 4).Left = i * 2200 + 300 Picture1(i + 4).Top = 300 Call wait(0.2) Next i
- Call getColorPoint(colors, points)
- For i = 1 To 8 Picture1(i - 1).Tag = CStr(colors(i) * 100 + points(i)) ' 將花色乘上100加上點數放入Tag Next i
- For i = 4 To 1 Step -1 Picture1(i - 1).Picture = LoadPicture(App.Path & "\Poker\" & colors(i) & "-" & points(i) & ".jpg") Call wait(0.1) Next i
- End Sub
- Private Sub getColorPoint(ByRef c() As Variant, ByRef p() As Variant)Dim i As Integer, j As IntegerDim check As BooleanRandomize (Timer)For i = 1 To 8 check = True While check = True check = False c(i) = Int(Rnd() * 4) + 1 p(i) = Int(Rnd() * 13) + 1 For j = 1 To i - 1 If c(j) = c(i) And p(j) = p(i) Then check = True ' 有重複的不算 Next j WendNext iEnd Sub
- Private Sub Picture1_DragDrop(Index As Integer, Source As Control, X As Single, Y As Single) If Index = Source.Index Then Exit Sub ' 只移動自己不處理 If Source.Index > 3 Or Index > 3 Then Exit Sub ' 點到對方的牌不處理 Call swap_pic(Source, Picture1(Index)) ' 換牌 Call calc_poker(0, mysum(), Label2(0), Label2(1))End Sub
- Private Sub swap_pic(ByRef p1 As PictureBox, ByRef p2 As PictureBox)
- Dim tmpPic As StdPicture Dim tmpStr As String Set tmpPic = p1.Picture ' 以下3行是圖形互換 Set p1.Picture = p2.Picture Set p2.Picture = tmpPic tmpStr = p1.Tag ' 以下3行是花色點數資料互換 p1.Tag = p2.Tag p2.Tag = tmpStr Set tmpPic = Nothing ' 釋放掉定義的物件End Sub
- Private Sub calc_poker(ByVal Index As Integer, ByRef sum() As Variant, ByRef lb1 As Label, ByRef lb2 As Label)
- Dim i As Integer Dim f As Double, g As Double poker_issame(Index) = True For i = Index + 1 To Index + 3 poker_issame(Index) = poker_issame(Index) And ((Val(Picture1(i).Tag) \ 100) = (Val(Picture1(i - 1).Tag \ 100))) Next i For i = 0 To 1 sum(i) = 0 Next i If poker_issame(0 + Index) = True Then lb1.Caption = "同花" lb2.Caption = "同花" sum(0) = sum(0) + 1000 sum(1) = sum(1) + 1000 For i = 0 To 1 sum(0) = sum(0) + (Val(Picture1(i + Index).Tag) \ 100) / 100 + (13 - Val(Picture1(i + Index).Tag) Mod 100) sum(1) = sum(1) + (Val(Picture1(i + Index + 2).Tag) \ 100) / 100 + (13 - Val(Picture1(i + Index + 2).Tag) Mod 100) Next i Exit Sub End If If Val(Picture1(0 + Index).Tag) Mod 100 = Val(Picture1(1 + Index).Tag) Mod 100 Then lb1.Caption = CStr(Val(Picture1(0 + Index).Tag) Mod 100) & " 一對" sum(0) = sum(0) + 100 For i = 0 To 1 sum(0) = sum(0) + (Val(Picture1(i + Index).Tag) \ 100) / 10 + (13 - Val(Picture1(i + Index).Tag) Mod 100) Next i Else f = (2 ^ (13 - Val(Picture1(0 + Index).Tag) Mod 100)) / 10000 + (Val(Picture1(0 + Index).Tag) \ 100) / 100000 g = (2 ^ (13 - Val(Picture1(1 + Index).Tag) Mod 100)) / 10000 + (Val(Picture1(1 + Index).Tag) \ 100) / 100000 sum(0) = sum(0) + (Val(Picture1(0 + Index).Tag) Mod 100 + Val(Picture1(1 + Index).Tag)) Mod 10 + f + g lb1.Caption = CStr((Val(Picture1(0 + Index).Tag) Mod 100 + Val(Picture1(1 + Index).Tag) Mod 100) Mod 10) End If If Val(Picture1(2 + Index).Tag) Mod 100 = Val(Picture1(3 + Index).Tag) Mod 100 Then lb2.Caption = CStr(Val(Picture1(2 + Index).Tag) Mod 100) & " 一對" sum(1) = sum(1) + 100 For i = 2 To 3 sum(1) = sum(1) + (Val(Picture1(i + Index).Tag) \ 100) / 10 + (13 - Val(Picture1(i + Index).Tag) Mod 100) Next i Else f = (2 ^ (13 - Val(Picture1(2 + Index).Tag) Mod 100)) / 10000 + (Val(Picture1(2 + Index).Tag) \ 100) / 100000 g = (2 ^ (13 - Val(Picture1(3 + Index).Tag) Mod 100)) / 10000 + (Val(Picture1(3 + Index).Tag) \ 100) / 100000 sum(1) = sum(1) + (Val(Picture1(2 + Index).Tag) Mod 100 + Val(Picture1(3 + Index).Tag)) Mod 10 + f + g lb2.Caption = CStr((Val(Picture1(2 + Index).Tag) Mod 100 + Val(Picture1(3 + Index).Tag) Mod 100) Mod 10) End IfEnd Sub
複製代碼 ... |
附件: 你需要登錄才可以下載或查看附件。沒有帳號?註冊 |