我有个网络版五子棋,一个客户端一个服务器,不过不是我写的啊,也是网络资源。发给你看看,也许对你有用。
'窗体放2个check,1个Label,1个Command,1个winsock控件,如图:
'有一人先启动wzq.exe登入,点选先入,然后等待另外一人运行wzq.exe
'填写先入一人的IP地址和接受端口号,然后连接,
'
'需要保证双方不选取相同颜色的棋子,需要实现商量好。
'然后可以下棋,没有判赢程序
Dim X1 As Integer
Dim Y1 As Integer
Dim X2 As Integer
Dim Y2 As Integer
Dim Step As Integer
Dim Waiting As Boolean
Dim Ip As String
Dim Port As Long
Private Sub Check1_Click()
Winsock1.LocalPort = Port
Winsock1.Listen
End Sub
Private Sub Command1_Click()
Winsock1.RemoteHost = Ip
Winsock1.RemotePort = Port
Winsock1.Connect
End Sub
Private Sub Form_Load()
Step = 200
X1 = 400
Y1 = 600
X2 = 400 + Step * 24
Y2 = 600 + Step * 24
Check2.BackColor = vbYellow
Ip = "127.0.0.1"
Port = 2888
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Waiting = False Then
QiZhi X, Y, True
End If
End Sub
Private Sub Form_Paint()
For i = 0 To 24
Me.Line (X1, Y1 + Step * i)-(X2, Y1 + Step * i)
Me.Line (X1 + Step * i, Y1)-(X1 + Step * i, Y2)
Next
End Sub
Private Function QiZhi(X, Y, SendData As Boolean)
Dim color As Long
Dim xx As Integer
Dim yy As Integer
xx = (((X - X1 - 100) \ (Step \ 2)) \ 2 + 1) * Step + X1
yy = (((Y - Y1 - 100) \ (Step \ 2)) \ 2 + 1) * Step + Y1
If Check2.Value = 1 Then
If SendData Then
color = vbBlue
Else
color = vbYellow
End If
Else
If SendData Then
color = vbYellow
Else
color = vbBlue
End If
End If
For i = 0 To 49
Me.Circle (xx, yy), i * 2, color
Next
If SendData Then
Winsock1.SendData Str(xx) & "| " & Str(yy)
Waiting = True
Label1.Caption = "轮到对方下棋 "
Else
Waiting = False
Label1.Caption = "轮到你了,赶快 "
End If
End Function
Private Sub Check2_Click()
If Check2.Value = 1 Then
Check2.BackColor = vbBlue
Else
Check2.BackColor = vbYellow
End If
End Sub
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
If Winsock1.State <> sckClosed Then Winsock1.Close
Winsock1.Accept requestID
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim xx As Integer
Dim yy As Integer
Dim dd As String
Winsock1.GetData dd, vbString, bytesTotal
Debug.Print dd
a = Split(dd, "| ")
QiZhi a(0), a(1), False
End Sub