⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.frm

📁 双合棋,这个游戏是本人用一周多的时间编写的。已基本成形
💻 FRM
📖 第 1 页 / 共 2 页
字号:
End Sub

Private Sub Command3_Click()
If Text2.Text = "" Then
    MsgBox "不能发送空信息!"
    Exit Sub
End If
If Form1.Winsock1.State = sckConnected Then
Text1.Text = Text1.Text + Chr(13) + Chr(10) + "自己说:" + Text2.Text
Send "9" + "对方说:" + Text2.Text
Else: MsgBox "尚未连接!"
End If
End Sub

Private Sub Form_Load()
Reset '清空棋局
If Server = 1 Then
    Picture1.Enabled = True
    Picture1.MousePointer = 2
Else
    Picture1.Enabled = False
    Picture1.MousePointer = 12
    
End If
Command1.Enabled = False '不能重开

End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Picture1.Enabled = False Then
    Picture1.MousePointer = 12
    Exit Sub
End If
Select Case GState
Case 1 '下子
    Picture1.MousePointer = 2
Case 2 '提子
    Picture1.MousePointer = 5
Case 3 '落子
    Picture1.MousePointer = 99
Case Else '杀子
    Picture1.MousePointer = 10
End Select
End Sub

Private Sub Form_Unload(Cancel As Integer)
If Winsock1.State = sckConnected Then
    Send "4"
    DoEvents
End If
Winsock1.Close
Unload FrmLaw
Unload FrmAbout
End

End Sub
'拖动

Private Sub huiqi_Click() '悔棋
If Form1.Picture1.Enabled = False Then
 MsgBox "还没轮到你,稍等!"
 Exit Sub
End If

Dim temp As Integer
temp = MsgBox("你真的要悔棋?", vbYesNo)
If temp = 6 Then
    Send "h" '认输
    Form1.Picture1.Enabled = False
    Form1.Picture1.MousePointer = 12
End If
End Sub

Private Sub Label2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
DragW = True
Label2.MousePointer = 5
CX = X
CY = Y
End Sub

Private Sub Label2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If DragW = True Then
Form1.Left = (Form1.Left + (X)) - CX
Form1.Top = (Form1.Top + (Y)) - CY
End If
End Sub

Private Sub Label2_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
DragW = False
Label2.MousePointer = 1
End Sub

Private Sub Law_Click()
FrmLaw.Show
End Sub

Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
'操作********************************************************************************
Dim i As Integer, j As Integer
Dim S As Integer
Dim sx As Integer, sy As Integer
sx = Fix(X / 910) + 1: sy = Fix(Y / 910) + 1 '求位置
If sx > 6 Or sy > 60 Then Exit Sub
If Server = 1 Then S = 2 Else S = 1
Select Case GState
Case 1 '前期下子
    If Board(sx, sy) <> 0 Then Exit Sub
    '存储己方上一棋局
    For i = 1 To 6
        For j = 1 To 6
        BoardLocal(i, j) = Board(i, j)
        Next j
    Next i
    LGState = 1
    Form1.huiqi.Enabled = True
    
    Board(sx, sy) = Server '储存棋子数据
    LocalAddL(sx + sy) = LocalAddL(sx + sy) + 1
    LocalSubR(sy - sx + 7) = LocalSubR(sy - sx + 7) + 1
    DrawBoard
    
    If LocalAddNum < Examine(Server, sx, sy) Then
    LocalAddNum = Examine(Server, sx, sy)
    End If
    If LocalAddNum > 0 Then
        Send "5" + Chr(sx) + Chr(sy)
        LocalAddNum = LocalAddNum - 1
    Else: Send "1" + Chr(sx) + Chr(sy)
        Form1.Picture1.Enabled = False
        Form1.Picture1.MousePointer = 12
        
    End If
    
    LocalTotal = LocalTotal + 1
    '判断是否该转棋。
        If RemoteTotal + LocalTotal = 36 Then
            GameTurn
        End If
    Exit Sub
Case 2 '后期提子
    If Board(sx, sy) <> Server Then Exit Sub
    '存储己方上一棋局
    For i = 1 To 6
        For j = 1 To 6
        BoardLocal(i, j) = Board(i, j)
        Next j
    Next i
    LGState = 2
    Form1.huiqi.Enabled = True
    Tsx = sx
    Tsy = sy
    Board(sx, sy) = 0
    DrawBoard
    GState = 3
    Picture1.MousePointer = 99
    Exit Sub
Case 3 '提后落子
    If Board(sx, sy) <> 0 Then Exit Sub
    If (Abs(sx - Tsx) + Abs(sy - Tsy)) > 1 Then Exit Sub
    Board(sx, sy) = Server
    DrawBoard
    If sx = Tsx And sy = Tsy Then '误提,放下重提
              
        GState = 2
         Picture1.MousePointer = 5
    Else
        LocalAddL(Tsx + Tsy) = LocalAddL(Tsx + Tsy) - 1  '左倾减
        LocalSubR(Tsy - Tsx + 7) = LocalSubR(Tsy - Tsx + 7) - 1 '右倾减
        LocalAddL(sx + sy) = LocalAddL(sx + sy) + 1  '左倾减
        LocalSubR(sy - sx + 7) = LocalSubR(sy - sx + 7) + 1 '右倾减
        LocalAddNum = Examine(Server, sx, sy)
        If LocalAddNum > 0 Then
            GState = 4
            Picture1.MousePointer = 10
            Send "6" + Chr(Tsx) + Chr(Tsy) + Chr(sx) + Chr(sy) + Chr(LocalAddNum)
        Else
            GState = 2
            Send "6" + Chr(Tsx) + Chr(Tsy) + Chr(sx) + Chr(sy) + Chr(0)
            Form1.Picture1.Enabled = False
            Picture1.MousePointer = 12
        End If
    End If
    
    Exit Sub
Case 4 '杀子
    If LocalAddNum <= 0 Then
        Form1.Picture1.Enabled = False
        Picture1.MousePointer = 12
        Exit Sub
    End If
    If Board(sx, sy) <> S Then Exit Sub
    If Examine(S, sx, sy) <> 0 And FreeH(S) = True Then Exit Sub
        Board(sx, sy) = 0
        DrawBoard '刷新
    
    RemoteAddL(sx + sy) = RemoteAddL(sx + sy) - 1  '左倾减
    RemoteSubR(sy - sx + 7) = RemoteSubR(sy - sx + 7) - 1 '右倾减
    RemoteTotal = RemoteTotal - 1
    
    Send "7" + Chr(sx) + Chr(sy) '发送杀子信息
    If GameUnResult() = 1 Then
            LocalAddNum = LocalAddNum - 1
            If LocalAddNum = 0 Then
                Form1.Picture1.Enabled = False '己方杀毕,对方走子。
                GState = 2
                Picture1.MousePointer = 12
            Else
                Form1.Picture1.Enabled = True
                GState = 4
                Picture1.MousePointer = 10
            End If
                
    End If
   
    Exit Sub
    
        
Case 5 '初始杀子
    
    If Board(sx, sy) <> S Then Exit Sub
    If Examine(S, sx, sy) <> 0 And FreeH(S) = True Then Exit Sub
    '存储己方上一棋局
    For i = 1 To 6
        For j = 1 To 6
        BoardLocal(i, j) = Board(i, j)
        Next j
    Next i
    LGState = 5
    Form1.huiqi.Enabled = True
    Board(sx, sy) = 0
    
    DrawBoard '刷新
    RemoteAddL(sx + sy) = RemoteAddL(sx + sy) - 1  '左倾减
    RemoteSubR(sy - sx + 7) = RemoteSubR(sy - sx + 7) - 1 '右倾减
    RemoteTotal = RemoteTotal - 1
    GState = 2
    
    Form1.Picture1.Enabled = False
    Picture1.MousePointer = 12
    Send "8" + Chr(sx) + Chr(sy)
    LocalAddNum = 0
    
    Exit Sub
Case Else
    Exit Sub
End Select
End Sub



Private Sub qiuhe_Click()
Dim temp As Integer
temp = MsgBox("你真的要求和?", vbYesNo)
If temp = 6 Then
    Send "q" '认输
    Form1.Picture1.Enabled = False
    Form1.Picture1.MousePointer = 12
End If
End Sub

Private Sub renshu_Click()
Dim S As Integer
Dim temp As Integer
temp = MsgBox("你真的要认输?", vbYesNo)
If Server = 1 Then S = 2 Else S = 1
If temp = 6 Then
    Reset
    lost(Server) = lost(Server) + 1
    win(S) = win(S) + 1
    Form1.lblBlackScore.Caption = "战绩: " + Str(win(1)) + "胜 " + Str(win(2)) + "败"
    Form1.lblWhiteScore.Caption = "战绩: " + Str(win(2)) + "胜 " + Str(win(1)) + "败"
    Form1.Command1.Enabled = True '允许重开
    Form1.Picture1.Enabled = False
    Send "r" '认输
End If
End Sub


Private Sub Winsock1_Connect()
lblInfo.Caption = "已连接"
Send "2" + Mid(Form1.lblWhiteName.Caption, 4, Len(Form1.lblWhiteName.Caption) - 1)
End Sub

Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
If Winsock1.State <> sckClosed Then Winsock1.Close
Winsock1.Accept requestID
lblInfo.Caption = "已连接"
Picture1.Enabled = True
Picture1.MousePointer = 2
End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
ProcessData bytesTotal
End Sub

⌨️ 快捷键说明

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