wuziclient.frm

来自「vb编程+从基础到实践光盘代码」· FRM 代码 · 共 2,139 行 · 第 1/5 页

FRM
2,139 行
字号
        CDate(Mytime) + MidVariant), "hh:mm:ss")
      Else
        
        TimeDisplayB.Text = Format(CDate(Time - _
        CDate(Mytime)), "hh:mm:ss")
       End If
    
End If
    
End Sub


Private Sub Timer1_Timer()
If TimeCount < 3 Then
    timecont = TimeCount + 1
Else
    TCP2.Close
    Connect.Tag = 1
    MsgBox "无法连接上服务器!", vbCritical
    TimeCount = 0
    Timer1.Enabled = False
    
End If
End Sub

Private Sub TimeWhite_Timer()
    Dim TimeUsed
    Dim TotalSecond As Integer
    Dim TotalMinuteTimeUsed As Single
    
 If Drawing Then
    
    If TimeDisplayW.Text <> "" Then
        TimeDisplayW.Text = Format(CDate(Time - CDate(Mytime) + _
        MidVariant), "hh:mm:ss")
    
    Else
        TimeDisplayW.Text = Format(CDate(Time - CDate(Mytime)), "hh:mm:ss")
    End If
    
    TotalMinuteTimeUsed = Minute(CDate(TimeDisplayW.Text))
    
    If TotalMinuteTimeUsed > CanUseTime Then
        TimeUsed = CDate(Time - CDate(Mytime))
        TotalSecond = Second(TimeUsed) + Minute(TimeUsed) * 60
        If TotalSecond > EveryStepTime Then
            TimeCanUseCount = TimeCanUseCount - CInt(TotalSecond / EveryStepTime)
            If TimeCanUseCount < 0 Then
            
                TCP2.SendData "/L"
                MsgBox "你已经超时判输", vbOKOnly
                TimeWhite.Enabled = False
                TimeBlack.Enabled = False
                Exit Sub
            End If
        End If
    End If
Else
    If TimeDisplayW.Text <> "" Then
        TimeDisplayW.Text = Format(CDate(Time - CDate(Mytime) + _
        MidVariant), "hh:mm:ss")
    Else
        TimeDisplayW.Text = Format(CDate(Time - CDate(Mytime)), "hh:mm:ss")
    End If
End If
    

End Sub

Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
Dim FileName As String
Dim FileNum
Dim StrPosition As String

Select Case Button.Index
    
    Case 1
        Buffer = ""
        IfWatching = False
        Call PlayInLocal
    
    Case 2
        
        
        CommonDialog1.Filter = "*.wxp|*.wxp"
        CommonDialog1.ShowOpen
        
        FileName = CommonDialog1.FileName
        
        
    PicQipan.Cls
    
    PicQipan.ForeColor = vbBlack
    For i = 1 To 14
        PicQipan.Line (SubWidth, SubWidth * i)-(SubWidth * 14, _
    SubWidth * i)
        PicQipan.Line (SubWidth * i, SubWidth)-(SubWidth * i, _
    SubWidth * 14)
    
    Next i
        
    Buffer = ""
    
        If FileName <> "" Then
            FileNum = FreeFile
            Open FileName For Input As FileNum
            LocalPlayColor = False
            Do While Not EOF(FileNum)
                Line Input #FileNum, StrPosition
                
                Buffer = Buffer & Format(CInt(Left$(StrPosition, 2)), "00") & "-" & Format(CInt(Right$(StrPosition, 2)), "00") & ":"
                Call DrawPill2(CInt(Left$(StrPosition, 2)), _
                CInt(Right$(StrPosition, 2)))
                
            Loop
        Close #FileNum
            
         End If
    Case 3
        
        If Buffer <> "" Then
        CommonDialog1.Filter = "*.wxp|*.wxp"
        CommonDialog1.ShowSave
        FileName = CommonDialog1.FileName
        FileNum = FreeFile
        Open FileName For Output As FileNum
        
        tempposition0 = 1
        tempposition1 = InStr(2, Buffer, ":", vbTextCompare)
        Do While tempposition1 <> 0
            str11 = Mid$(Buffer, tempposition0, tempposition1 - tempposition0)

            Print #FileNum, str11
            tempposition0 = tempposition1 + 1
            tempposition1 = InStr(tempposition1 + 1, Buffer, ":", vbTextCompare)
        Loop


        Close #FileNum
            
        Else
            MsgBox "没有信息存盘!", vbCritical
        End If
        
        Case 5
            TCP2.SendData "/H:"
            Drawing = False
        
        Case 6
            TCP2.SendData "/L:"
            IfPlaying = False
'            Drawing = False
            TimeBlack.Enabled = False
            TimeWhite.Enabled = False
        
End Select
    
End Sub

Private Sub Users_Click()
TCP2.SendData "/2"
End Sub

Private Sub NewGame()
    Dim l As Integer
    Dim j As Integer
    
    IfPlaying = True
    Buffer = ""
    
    
    
    TimeDisplayB.Text = ""
    TimeDisplayW.Text = ""
    PicQipan.Cls
    
    PicQipan.ForeColor = vbBlack
    For i = 1 To 14
    PicQipan.Line (SubWidth, SubWidth * i)-(SubWidth * 14, _
    SubWidth * i)
    PicQipan.Line (SubWidth * i, SubWidth)-(SubWidth * i, _
    SubWidth * 14)
    Next i
    
    For l = 1 To 14
        For j = 1 To 14
            DataArray(l, j) = 5
        Next j
    Next l
    
    If MyColor = 0 Then
        Drawing = True
    Else
        Drawing = False
    End If
    
    '表明不是在本地机上玩
    LocalPlay = False
    
    

    
End Sub


Private Sub PlayInLocal()
    Dim m As Integer
    Dim n As Integer
    
    LocalPlay = True
    Drawing = True
    LocalPlayColor = False
    
    TimeDisplayB.Text = ""
    TimeDisplayW.Text = ""
    Buffer = ""
    PicQipan.Cls
    
    PicQipan.ForeColor = vbBlack
    For i = 1 To 14
        PicQipan.Line (SubWidth, SubWidth * i)-(SubWidth * 14, _
    SubWidth * i)
        PicQipan.Line (SubWidth * i, SubWidth)-(SubWidth * i, _
    SubWidth * 14)
    
    Next i
    For m = 1 To 14
        For n = 1 To 14
            DataArray(m, n) = 5
        Next n
    Next m

End Sub

Private Sub LocalFunction(X As Single, Y As Single)
Dim x0 As Integer
Dim y0 As Integer

IfSucceed = False
If X < 10 Or X > 14.5 * SubWidth Or Y < SubWidth Or Y > 14.5 * SubWidth Then
    MsgBox "超出棋盘界限,请重新下"
    Exit Sub
End If

If Abs(Int(X / SubWidth) - X / SubWidth) < 0.5 Then
    x0 = Int(X / SubWidth)
Else
    x0 = Int(X / SubWidth) + 1
End If

If Abs(Int(Y / SubWidth) - Y / SubWidth) < 0.5 Then
    y0 = Int(Y / SubWidth)
Else
    y0 = Int(Y / SubWidth) + 1
End If



'X = X + SubWidth / 2
'Y = Y + SubWidth / 2
'X0 = X / SubWidth
'Y0 = Y / SubWidth

If DataArray(x0, y0) <> 5 Then
    '当前位置已经有棋子了,
    MsgBox "当前位置已经有棋子了,请重新走!", vbCritical, "NOTE!"
    Exit Sub
End If

If LocalPlayColor Then
    DataArray(x0, y0) = 1
Else
    DataArray(x0, y0) = 0
End If
Buffer = Buffer & Format(x0, "00") & "-" & Format(y0, "00") & ":"
Call DrawPill2(x0, y0)




For j = 1 To 14
    For i = 1 To 14
    
    If DataArray(i, j) = MyColor And Not IfSucceed Then
                
        'IfSucceed = IfSucceed + 1
        
        
        If (14 - i) >= 4 And (14 - j) >= 4 Then
            If DataArray(i + 1, j + 1) = MyColor Then
                If DataArray(i + 2, j + 2) = MyColor Then
                    If DataArray(i + 3, j + 3) = MyColor Then
                        If DataArray(i + 4, j + 4) = MyColor Then
                            IfSucceed = True
                            Exit For
                        Exit For
                        End If
                    End If
                End If
            End If
        End If
        
        If i > 4 And (14 - j) >= 4 Then
            If DataArray(i - 1, j + 1) = MyColor Then
                If DataArray(i - 2, j + 2) = MyColor Then
                    If DataArray(i - 3, j + 3) = MyColor Then
                        If DataArray(i - 4, j + 4) = MyColor Then
                            IfSucceed = True
                            Exit For
                        Exit For
                        End If
                    End If
                End If
            End If
        End If
        
        
        If (14 - i) >= 4 Then
        If DataArray(i + 1, j) = MyColor Then
            'IfSucceed = IfSucceed + 1
                If DataArray(i + 2, j) = MyColor Then
                    If DataArray(i + 3, j) = MyColor Then
                        If DataArray(i + 4, j) = MyColor Then
                            IfSucceed = True
                            Exit For
                        Exit For
                        End If
                    End If
                End If
        End If
        
        End If
        
        If (14 - j) >= 4 Then
        If DataArray(i, j + 1) = MyColor Then
            If DataArray(i, j + 2) = MyColor Then
                If DataArray(i, j + 3) = MyColor Then
                    If DataArray(i, j + 4) = MyColor Then
                        IfSucceed = True
                        Exit For
                    Exit For
                    End If
                End If
            End If
        End If
        End If
        
       End If
        
    Next i
Next j

If IfSucceed Then
    If Not LocalPlayColor Then
        MsgBox "白方胜!", vbOKOnly
    Else
        MsgBox "黑方胜!", vbOKOnly
    End If
    
    LocalPlay = False
    Drawing = False
    LocalPlayColor = False
End If




End Sub

Private Sub DrawPill(xx0 As Integer, yy0 As Integer)
DataArray(xx0, yy0) = OtherColor
If MyColor = 0 Then
    PicQipan.ForeColor = vbWhite
    DoEvents
    PicQipan.FillColor = vbWhite

Else
    PicQipan.ForeColor = vbBlack
    DoEvents
    PicQipan.FillColor = vbBlack

End If
PicQipan.FillStyle = 0
PicQipan.Circle (xx0 * SubWidth, yy0 * SubWidth), SubWidth / 3

End Sub

Private Sub DrawPill2(xx0 As Integer, yy0 As Integer)
If LocalPlayColor Then
    PicQipan.ForeColor = vbWhite
    DoEvents
    PicQipan.FillColor = vbWhite
    MyColor = 1
    
Else
    PicQipan.ForeColor = vbBlack
    DoEvents
    PicQipan.FillColor = vbBlack
    MyColor = 0

End If


LocalPlayColor = Not LocalPlayColor
DoEvents
PicQipan.Circle (xx0 * SubWidth, yy0 * SubWidth), SubWidth / 3

End Sub

Private Sub Watch_Click()
Frame1.Visible = False
Frame2.Visible = False
Frame5.Visible = False
Frame6.Visible = True

End Sub

Private Sub WatchRequest_Click()
On Error GoTo err:
    TCP2.SendData "/G:" & CInt(QiJuNum.Text)
    WatchQiJu = CInt(QiJuNum.Text)
    Exit Sub
err:
    MsgBox "输入有误!"

End Sub

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?