s + 1, tempij, ";")
'对方下子的位置(i,j)
i = Mid(tempij, 1, pos - 1)
j = Mid(tempij, pos + 1, pos2 - pos - 1)
mColor1 = Mid(tempij, pos2 + 1)
mGrid(i, j).mPill = 1
If mColor1 = "White" Then
Call Drawpill(i, j, "White")
Else
Call Drawpill(i, j, "Black")
End If
If cmdLook.Caption <> "退出观战" Then
Label5.Caption = "该你走了......" & MyColor
Go = True
End If
Case "/LgOn"
'接收注册玩家姓名后服务器返回的信息
Text1.Text = Text1.Text & Mid(Information, 6) & vbCrLf
Case "/User"
'向服务器请求列出所有玩家,服务器返回的数据处理
tempstr = Mid(Information, 6)
mArray = Split(tempstr, ";")
userList.Clear
For i = 1 To UBound(mArray)
pos = InStr(1, mArray(i), ":")
userList.AddItem Left$(mArray(i), pos - 1)
Text1.Text = Text1.Text & mArray(i) & vbCrLf
Next i
Case "/Call"
'处理玩家呼叫对方下棋
pos = InStr(6, Information, ";")
tempstr = Mid(Information, 6)
Dim answer
answer = MsgBox(tempstr & "想与你下一局,可以吗?", vbYesNo)
If answer = vbYes Then
cmdCall.Caption = "退出棋局"
Winsock.SendData "/Play" & "OK" & CInt(Mid(Information, pos + 1)) & ";" & "对手答应和你下几把"
Label5.Caption = "对方走......" & MyColor
'被呼叫者用黑棋
MyColor = "Black"
Else
Winsock.SendData "/Play" & "NO" & CInt(Mid(Information, pos + 1)) & ";" & "对手不想和你下"
End If
Case "/Play"
'呼叫者得到被呼叫者的回答处理
pos = InStr(7, Information, ";")
tempstr = Mid(Information, 6, 2)
Dim mIndex As Integer
mIndex = CInt(Mid(Information, 8, pos - 8))
If tempstr = "OK" Then
cmdCall.Enabled = True
cmdCall.Caption = "退出棋局"
Go = True
'呼叫者用白棋
MyColor = "White"
'Form1.Caption = Username & "与" & userList.Text & "大战五子棋!!"
Text1.Text = Text1.Text & Mid(Information, pos + 1) & vbCrLf
Label5.Caption = "该你走......" & MyColor
Else
cmdCall.Enabled = True
Text1.Text = Text1.Text & Mid(Information, pos + 1) & vbCrLf
'MsgBox "对方不想与你下棋"
End If
Case "/Regi"
'玩家注册后,处理服务器返回的信息
Username = txtName.Text
cmdCall.Enabled = True
txtName.Locked = True
txtSend.Enabled = True
Text1.Text = Text1.Text & Mid(Information, 6) & vbCrLf
Case "/Quit"
'对手退出棋局后,处理服务器发送过来的消息
cmdCall.Caption = "呼叫"
Text1.Text = Text1.Text & "你的对手已经退出棋局了" & vbCrLf
'不能下棋了
Go = False
'初始化棋格
Call IniGrid
Case "/AllP"
'向服务器请求返回所有棋局信息后,服务器返回的所有棋局玩家的姓名和棋局索引
tempstr = Mid(Information, 6)
mArray = Split(tempstr, ";")
AllFight.Clear
'将棋局的信息和索引加入到列表框allfight中
For i = 0 To UBound(mArray) - 1
pos = InStr(1, mArray(i), ":")
AllFight.Tag = CInt(Mid(mArray(i), 1, pos - 1))
AllFight.AddItem Mid(mArray(i), pos + 1)
Next i
Case "/Grid"
'向服务器发送棋局信息
tempstr = ""
For i = 1 To 15
For j = 1 To 15
tempstr = tempstr & mGrid(i, j).mPill & ";" & mGrid(i, j).mColor & ";"
Next j
Next i
Dim tempIndex As Integer
Winsock.SendData "/Grid" & Mid(Information, 6) & ";" & tempstr
Case "/GetG"
'参加观看的玩家向服务器请求返回棋局的信息后
'从服务器取得棋局信息
tempstr = ""
tempstr = Mid(Information, 6)
mArray = Split(tempstr, ";")
Call IniGrid
Dim kkk
kkk = UBound(mArray)
For i = 1 To 15
For j = 1 To 15
mGrid(i, j).mPill = CInt(mArray(2 * (i - 1) * 15 + 2 * j - 2))
mGrid(i, j).mColor = mArray(2 * (i - 1) * 15 + 2 * j - 1)
Next j
Next i
'根据返回的棋局信息绘制正在对奕的棋局
Call FillPill
cmdLook.Caption = "退出观战"
Case Else
Text1.Text = Text1.Text & Information & vbCrLf
End Select
End Sub
Private Sub DrawGrid()
'绘制棋格15x15
Dim i, j As Integer
For i = 1 To 15
Pic1.Line (i * Gridwidth, 0)-(i * Gridwidth, Pic1.Height)
Next i
For j = 1 To 15
Pic1.Line (0, j * Gridwidth)-(Pic1.Width, j * Gridwidth)
Next j
End Sub
Private Sub Drawpill(ByVal i As Integer, ByVal j As Integer, ByVal mColor As String)
'根据参数以一定的颜色绘制棋子
If mColor = "Black" Then
Pic1.ForeColor = vbBlack
Pic1.FillColor = vbBlack
mGrid(i, j).mColor = "Black"
Else
Pic1.ForeColor = vbWhite
Pic1.FillColor = vbWhite
mGrid(i, j).mColor = "White"
End If
'绘制棋子
Pic1.Circle (i * Gridwidth, j * Gridwidth), 120
End Sub
Private Sub Winsock_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
'出错提示及处理
Command1.Enabled = True
cmdDiscont.Enabled = False
userList.Enabled = False
cmdCall.Enabled = False
AllFight.Enabled = False
txtName.Locked = False
Text1.Text = "与服务器的连接断开了......"
Winsock.Close
MsgBox "与服务器的连接失败,请重试......"
End Sub
Private Sub JudgeWin()
'判断输赢的算法,请读者完善该算法
End Sub
Private Sub IniGrid()
'初始化存放棋子信息的数组及重新绘制棋格
Dim i, j As Integer
For i = 1 To 15
For j = 1 To 15
mGrid(i, j).mPill = 0
mGrid(i, j).mColor = ""
Next j
Next i
Pic1.Cls
Call DrawGrid
End Sub
Private Sub FillPill()
'根据存储棋子信息的数组mgrid绘制棋子
Dim i, j As Integer
For i = 1 To 15
For j = 1 To 15
If mGrid(i, j).mPill = 1 Then
Call Drawpill(i, j, mGrid(i, j).mColor)
End If
Next j
Next i
End Sub
'对方下子的位置(i,j)
i = Mid(tempij, 1, pos - 1)
j = Mid(tempij, pos + 1, pos2 - pos - 1)
mColor1 = Mid(tempij, pos2 + 1)
mGrid(i, j).mPill = 1
If mColor1 = "White" Then
Call Drawpill(i, j, "White")
Else
Call Drawpill(i, j, "Black")
End If
If cmdLook.Caption <> "退出观战" Then
Label5.Caption = "该你走了......" & MyColor
Go = True
End If
Case "/LgOn"
'接收注册玩家姓名后服务器返回的信息
Text1.Text = Text1.Text & Mid(Information, 6) & vbCrLf
Case "/User"
'向服务器请求列出所有玩家,服务器返回的数据处理
tempstr = Mid(Information, 6)
mArray = Split(tempstr, ";")
userList.Clear
For i = 1 To UBound(mArray)
pos = InStr(1, mArray(i), ":")
userList.AddItem Left$(mArray(i), pos - 1)
Text1.Text = Text1.Text & mArray(i) & vbCrLf
Next i
Case "/Call"
'处理玩家呼叫对方下棋
pos = InStr(6, Information, ";")
tempstr = Mid(Information, 6)
Dim answer
answer = MsgBox(tempstr & "想与你下一局,可以吗?", vbYesNo)
If answer = vbYes Then
cmdCall.Caption = "退出棋局"
Winsock.SendData "/Play" & "OK" & CInt(Mid(Information, pos + 1)) & ";" & "对手答应和你下几把"
Label5.Caption = "对方走......" & MyColor
'被呼叫者用黑棋
MyColor = "Black"
Else
Winsock.SendData "/Play" & "NO" & CInt(Mid(Information, pos + 1)) & ";" & "对手不想和你下"
End If
Case "/Play"
'呼叫者得到被呼叫者的回答处理
pos = InStr(7, Information, ";")
tempstr = Mid(Information, 6, 2)
Dim mIndex As Integer
mIndex = CInt(Mid(Information, 8, pos - 8))
If tempstr = "OK" Then
cmdCall.Enabled = True
cmdCall.Caption = "退出棋局"
Go = True
'呼叫者用白棋
MyColor = "White"
'Form1.Caption = Username & "与" & userList.Text & "大战五子棋!!"
Text1.Text = Text1.Text & Mid(Information, pos + 1) & vbCrLf
Label5.Caption = "该你走......" & MyColor
Else
cmdCall.Enabled = True
Text1.Text = Text1.Text & Mid(Information, pos + 1) & vbCrLf
'MsgBox "对方不想与你下棋"
End If
Case "/Regi"
'玩家注册后,处理服务器返回的信息
Username = txtName.Text
cmdCall.Enabled = True
txtName.Locked = True
txtSend.Enabled = True
Text1.Text = Text1.Text & Mid(Information, 6) & vbCrLf
Case "/Quit"
'对手退出棋局后,处理服务器发送过来的消息
cmdCall.Caption = "呼叫"
Text1.Text = Text1.Text & "你的对手已经退出棋局了" & vbCrLf
'不能下棋了
Go = False
'初始化棋格
Call IniGrid
Case "/AllP"
'向服务器请求返回所有棋局信息后,服务器返回的所有棋局玩家的姓名和棋局索引
tempstr = Mid(Information, 6)
mArray = Split(tempstr, ";")
AllFight.Clear
'将棋局的信息和索引加入到列表框allfight中
For i = 0 To UBound(mArray) - 1
pos = InStr(1, mArray(i), ":")
AllFight.Tag = CInt(Mid(mArray(i), 1, pos - 1))
AllFight.AddItem Mid(mArray(i), pos + 1)
Next i
Case "/Grid"
'向服务器发送棋局信息
tempstr = ""
For i = 1 To 15
For j = 1 To 15
tempstr = tempstr & mGrid(i, j).mPill & ";" & mGrid(i, j).mColor & ";"
Next j
Next i
Dim tempIndex As Integer
Winsock.SendData "/Grid" & Mid(Information, 6) & ";" & tempstr
Case "/GetG"
'参加观看的玩家向服务器请求返回棋局的信息后
'从服务器取得棋局信息
tempstr = ""
tempstr = Mid(Information, 6)
mArray = Split(tempstr, ";")
Call IniGrid
Dim kkk
kkk = UBound(mArray)
For i = 1 To 15
For j = 1 To 15
mGrid(i, j).mPill = CInt(mArray(2 * (i - 1) * 15 + 2 * j - 2))
mGrid(i, j).mColor = mArray(2 * (i - 1) * 15 + 2 * j - 1)
Next j
Next i
'根据返回的棋局信息绘制正在对奕的棋局
Call FillPill
cmdLook.Caption = "退出观战"
Case Else
Text1.Text = Text1.Text & Information & vbCrLf
End Select
End Sub
Private Sub DrawGrid()
'绘制棋格15x15
Dim i, j As Integer
For i = 1 To 15
Pic1.Line (i * Gridwidth, 0)-(i * Gridwidth, Pic1.Height)
Next i
For j = 1 To 15
Pic1.Line (0, j * Gridwidth)-(Pic1.Width, j * Gridwidth)
Next j
End Sub
Private Sub Drawpill(ByVal i As Integer, ByVal j As Integer, ByVal mColor As String)
'根据参数以一定的颜色绘制棋子
If mColor = "Black" Then
Pic1.ForeColor = vbBlack
Pic1.FillColor = vbBlack
mGrid(i, j).mColor = "Black"
Else
Pic1.ForeColor = vbWhite
Pic1.FillColor = vbWhite
mGrid(i, j).mColor = "White"
End If
'绘制棋子
Pic1.Circle (i * Gridwidth, j * Gridwidth), 120
End Sub
Private Sub Winsock_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
'出错提示及处理
Command1.Enabled = True
cmdDiscont.Enabled = False
userList.Enabled = False
cmdCall.Enabled = False
AllFight.Enabled = False
txtName.Locked = False
Text1.Text = "与服务器的连接断开了......"
Winsock.Close
MsgBox "与服务器的连接失败,请重试......"
End Sub
Private Sub JudgeWin()
'判断输赢的算法,请读者完善该算法
End Sub
Private Sub IniGrid()
'初始化存放棋子信息的数组及重新绘制棋格
Dim i, j As Integer
For i = 1 To 15
For j = 1 To 15
mGrid(i, j).mPill = 0
mGrid(i, j).mColor = ""
Next j
Next i
Pic1.Cls
Call DrawGrid
End Sub
Private Sub FillPill()
'根据存储棋子信息的数组mgrid绘制棋子
Dim i, j As Integer
For i = 1 To 15
For j = 1 To 15
If mGrid(i, j).mPill = 1 Then
Call Drawpill(i, j, mGrid(i, j).mColor)
End If
Next j
Next i
End Sub

















