📄 wuziserver.frm
字号:
Winsocks(Index).SendData "/N:" & "对不起,对方已经参加了一个棋局!"
MessageBox.Text = MessageBox.Text & UserInformation(Index).NickName & "找" & _
UserInformation(opponentnum).NickName & "对局!(对方已经参加一个棋局)" & "------" & _
Chr(10) & Chr(13)
End If
Else
Winsocks(Index).SendData "/N:对方不在网上!"
MessageBox.Text = MessageBox.Text & UserInformation(Index).NickName & "找" & _
UserInformation(opponentnum).NickName & "对局!(对方不在)" & "------" & _
Chr(10) & Chr(13)
End If
'对方对你请战的态度
Case "A"
Onename = Mid$(Information, 4, InStr(4, Information, _
":", vbTextCompare) - 4)
num1 = InStr(4, Information, ":", vbTextCompare)
Anothername = Mid$(Information, num1 + 1, InStr(num1 + 1, Information, ":", vbTextCompare) - num1 - 1)
num1 = InStr(num1 + 1, Information, ":", vbTextCompare)
answernum = CInt(Mid$(Information, num1 + 1))
'找到对手的用户代号
For i = 1 To MaxConnect
If UsersConnect(i) Then
If UserInformation(i).NickName = Onename Then
opponentnum = UserInformation(i).UserNumber
Exit For
End If
End If
Next
'表示同意
If answernum = 1 Then
TotalQiJuShu = TotalQiJuShu + 1
UserInformation(Index).QiJuNum = TotalQiJuShu
UserInformation(OpponentPlayNum(Index)).QiJuNum = TotalQiJuShu
EveryOnePlaying(Index) = True
EveryOnePlaying(OpponentPlayNum(Index)) = True
'Buffer数组来存放某一局的信息,在开始几个字节中存放该局的
'棋局数,同时PlayInfoNum数组来记录对弈双方所对应的棋局棋局
'信息索引
For i = 1 To MaxConnect
If Buffer(i) = "" Then
Buffer(i) = Format(TotalQiJuShu, "000") & ":"
PlayInfoNum(Index) = i
PlayInfoNum(OpponentPlayNum(Index)) = i
Exit For
End If
Next i
If CInt(UserInformation(OpponentPlayNum(Index)).PlayColor) = 0 Then
UserInformation(Index).PlayColor = "1"
Else
UserInformation(Index).PlayColor = "0"
End If
MessageBox.Text = MessageBox.Text & UserInformation(Index).NickName & _
"接受" & UserInformation(OpponentPlayNum(Index)).NickName & _
"的挑战" & "------" & Format(Time, "hh:mm:ss") & Chr(10) & Chr(13)
Else
UserInformation(OpponentPlayNum(Index)).PlayColor = ""
OpponentPlayNum(Index) = 0
OpponentPlayNum(opponentnum) = 0
MessageBox.Text = MessageBox.Text & UserInformation(Index).NickName & _
"不接受" & UserInformation(OpponentPlayNum(Index)).NickName & _
"的挑战" & "------" & Format(Time, "hh:mm:ss") & Chr(10) & Chr(13)
End If
Winsocks(opponentnum).SendData "/A:" & answernum & ":" & Anothername
'对局双方的棋子坐标信息和时间,通过服务器互相传递
Case "D"
Dim X As Integer
Dim Y As Integer
Dim TempNum5 As Integer
Dim TempNum6 As Integer
X = CInt(Mid$(Information, 4, InStr(4, _
Information, ":", vbTextCompare) - 4))
TempNum5 = InStr(4, Information, ":", vbTextCompare)
TempNum6 = InStr(TempNum5 + 1, Information, ":", vbTextCompare)
Y = CInt(Mid$(Information, TempNum5 + 1, TempNum6 - TempNum5 - 1))
Buffer(PlayInfoNum(Index)) = Buffer(PlayInfoNum(Index)) & _
Format(Str(X), "00") & "-" & Format(Str(Y), "00") & ":"
Histime = Mid$(Information, TempNum6 + 1)
Winsocks(OpponentPlayNum(Index)).SendData _
"/D:" & Str(X) & ":" & Str(Y) & ":" & Histime
DoEvents
'如果有观战的人,同时还需要将棋子数据传递到观战的棋友
For i = 1 To MaxConnect
If Watchers(Index, i) <> 0 Then
Winsocks(Watchers(Index, i)).SendData _
"/S:" & Format(Str(X), "00") & ":" & Format(Str(Y), "00")
DoEvents
End If
Next i
'当某一方认输的时候,发送"/L"
Case "L"
EveryOnePlaying(Index) = False
EveryOnePlaying(OpponentPlayNum(Index)) = False
'将一些数据恢复到原来状态
For i = 1 To MaxConnect
Watchers(Index, i) = 0
Watchers(OpponentPlayNum(Index), i) = 0
Next
UserInformation(Index).QiJuNum = 0
UserInformation(OpponentPlayNum(Index)).UserNumber = 0
Buffer(PlayInfoNum(Index)) = ""
PlayInfoNum(Index) = 0
PlayInfoNum(OpponentPlayNum(Index)) = 0
MessageBox.Text = MessageBox.Text & UserInformation(Index).NickName & _
"输给了" & UserInformation(OpponentPlayNum(Index)).NickName & _
"------" & Format(Time, "hh:mm:ss") & Chr(10) & Chr(13)
OpponentPlayNum(Index) = 0
OpponentPlayNum(OpponentPlayNum(Index)) = 0
Winsocks(OpponentPlayNum(Index)).SendData "/L"
'表示某一方赢了这盘棋
Case "W"
EveryOnePlaying(Index) = False
EveryOnePlaying(OpponentPlayNum(Index)) = False
'注意,用户在开发完整的系统的时候应该考虑向每一个观棋的用户
'发送信息,在这里并没有考虑
Winsocks(OpponentPlayNum(Index)).SendData "/W"
For i = 1 To MaxConnect
Watchers(Index, i) = 0
Watchers(OpponentPlayNum(Index), i) = 0
Next
UserInformation(Index).QiJuNum = 0
UserInformation(OpponentPlayNum(Index)).UserNumber = 0
Buffer(PlayInfoNum(Index)) = ""
PlayInfoNum(Index) = 0
PlayInfoNum(OpponentPlayNum(Index)) = 0
MessageBox.Text = MessageBox.Text & UserInformation(Index).NickName & _
"战胜了" & UserInformation(OpponentPlayNum(Index)).NickName & _
"------" & Format(Time, "hh:mm:ss") & Chr(10) & Chr(13)
OpponentPlayNum(Index) = 0
OpponentPlayNum(OpponentPlayNum(Index)) = 0
'表示有人请求观战
Case "G"
Dim TempIndex As Boolean
Dim ColorJudge As Integer
Dim WatchNum As Integer
WatchNum = CInt(Mid$(Information, 4))
For i = 1 To MaxConnect
If Buffer(i) <> "" And Not TempIndex Then
If CInt(Left$(Buffer(i), 3)) = WatchNum Then
For j = 1 To MaxConnect
If UserInformation(j).QiJuNum = WatchNum And Not TempIndex Then
'将观战用户代号加入该棋局的观战信息中,其中利用数组Watchers来
'实现,watchers(ij)中的I表示对局双方中得一方当号,j来区分不同的
'观战者
For k = 1 To MaxConnect
If Watchers(j, k) = 0 Then
Watchers(j, k) = Index
Watchers(OpponentPlayNum(j), k) = Index
ColorJudge = j
TempIndex = True
Exit For
End If
Next k
End If
Next j
'根据发送方的棋局颜色来向不同的观战的人发送相应的棋子颜色
If CInt(UserInformation(ColorJudge).PlayColor) = 0 Then
Winsocks(Index).SendData "/G:" & Mid$(Buffer(i), 5) & ":" & _
UserInformation(ColorJudge).NickName & "|" & _
UserInformation(OpponentPlayNum(ColorJudge)).NickName
Else
Winsocks(Index).SendData "/G:" & Mid$(Buffer(i), 5) & ":" & _
UserInformation(OpponentPlayNum(ColorJudge)).NickName & "|" & _
UserInformation(ColorJudge).NickName
End If
End If
End If
Next i
If Not TempIndex Then
MessageBox.Text = MessageBox.Text & UserInformation(Index).NickName & _
"想观看第" & WatchNum & "局的比赛(暂时没有此局)" & "------" & Format(Time, "hh:mm:ss") & _
Chr(10) & Chr(13)
Winsocks(Index).SendData "/g:"
Else
MessageBox.Text = MessageBox.Text & UserInformation(Index).NickName & _
"想观看第" & WatchNum & "局的比赛(暂时没有此局)" & "------" & Format(Time, "hh:mm:ss") & _
Chr(10) & Chr(13)
End If
'表示想悔棋
Case "H"
Winsocks(Index).SendData "/H:"
'表示对方同意悔棋
Case "T"
Dim AnswerNumber As Integer
AnswerNumber = Mid$(Information, 4)
If AnswerNumber = vbYes Then
'将存储在buffer中的棋局信息去掉一步
Buffer(PlayInfoNum(Index)) = Mid$(Buffer(PlayInfoNum(Index)), _
Len(Buffer(PlayInfoNum(Index))) - 6)
Winsocks(OpponentPlayNum(Index)).SendData "/T:" & AnswerNumber
Else
Winsocks(OpponentPlayNum(Index)).SendData "/T:" & AnswerNumber
End If
End Select
Else
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -