📄 form2.frm
字号:
Begin VB.Label Label3
AutoSize = -1 'True
BackColor = &H00008000&
BeginProperty Font
Name = "宋体"
Size = 15
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 300
Left = 3840
TabIndex = 0
Top = 4200
Width = 150
End
Begin VB.Image Image3
Height = 1380
Left = 7080
Picture = "Form2.frx":0442
Top = 1560
Width = 840
End
Begin VB.Image Image1
Height = 1530
Left = 3960
Picture = "Form2.frx":40E4
Top = 1920
Width = 3225
End
Begin VB.Image Image2
Height = 1275
Left = 5040
Picture = "Form2.frx":14356
Top = 720
Width = 900
End
Begin VB.Image Image4
Height = 1380
Left = 3000
Picture = "Form2.frx":17F5C
Top = 1560
Width = 975
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Public a As Integer
Public b As Integer
Public mes As String
Public nn As Integer
Private Sub Command2_Click()
Text4.Text = 1
Label7.Caption = Winsock1.LocalIP
Command3.Enabled = False
Text2.Enabled = False
Label8.Caption = "请输入您的大名:"
Text3.SetFocus
Image2.Visible = True
Image3.Visible = False
Image4.Visible = False
End Sub
Private Sub Command3_Click()
Text4.Text = 0
Command2.Enabled = False
Label2.Caption = "请输入对方IP"
Label8.Caption = "请输入您的大名:"
Text2.SetFocus
Image2.Visible = True
Image3.Visible = False
Image4.Visible = False
End Sub
Private Sub Form_Load()
Label1.ForeColor = RGB(250, 0, 0)
Label2.ForeColor = RGB(250, 0, 0)
Label3.ForeColor = RGB(250, 0, 0)
Winsock1.Protocol = sckUDPProtocol
Winsock1.LocalPort = 5000
Winsock1.RemotePort = 5000
Winsock1.RemoteHost = Winsock1.LocalIP
Winsock1.SendData ""
Winsock2.Protocol = sckUDPProtocol
Winsock2.LocalPort = 5001
Winsock2.RemotePort = 5001
Winsock2.RemoteHost = Winsock1.LocalIP
Winsock2.SendData ""
End Sub
Private Sub Form_Unload(Cancel As Integer)
Unload Form2
Winsock1.Close
Winsock2.Close
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Text3.SetFocus
End If
End Sub
Private Sub Text3_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
If Text4.Text = 0 Then
Winsock1.RemoteHost = Text2.Text
Winsock1.SendData Winsock1.LocalIP
Winsock1.SendData Text3.Text
Label4.Caption = Text3.Text
Label4.Visible = True
Else
Label4.Caption = Text3.Text
Label4.Visible = True
mes = "等待对手加入中"
Timer2_Timer
End If
End If
End Sub
Private Sub Text3_LostFocus()
Winsock1.RemoteHost = Text2.Text
Label4.Caption = Text3.Text
Label4.Visible = True
End Sub
Private Sub Timer1_Timer()
Timer1.Interval = 20
a = a + 1
If a <= 16 Then
If a Mod 3 = 1 Then
Label3.Caption = ""
Image2.Left = Image2.Left - 50
Image2.Top = Image2.Top - 50
Image3.Left = Image3.Left + 50
Image3.Top = Image3.Top + 50
End If
If a Mod 3 = 2 Then
Label3.Caption = mes
Image2.Left = Image2.Left + 50
Image2.Top = Image2.Top + 50
Image4.Left = Image4.Left - 50
Image4.Top = Image4.Top - 50
End If
If a Mod 3 = 0 Then
Label3.Caption = mes
Image3.Left = Image3.Left - 50
Image3.Top = Image3.Top - 50
Image4.Left = Image4.Left + 50
Image4.Top = Image4.Top + 50
End If
End If
If a = 16 Then
Image2.Visible = False
Image3.Visible = False
Image4.Visible = False
Randomize
Tt = Rnd * 3
If Tt <= 1 Then
ren = 1
Label4.Visible = True
Image2.Visible = True
Text1.Text = 0
End If
If Tt > 1 And Tt <= 2 Then
ren = 2
Label5.Visible = True
Image3.Visible = True
Text1.Text = -1
End If
If Tt > 2 And Tt <= 3 Then
ren = 3
Label6.Visible = True
Image4.Visible = True
Text1.Text = 1
End If
Label3.Caption = "地主已选定!"
End If
If a = 70 Then
Me.Visible = False
Form2.Visible = True
Load Form2
Exit Sub
End If
End Sub
Private Sub Timer2_Timer()
If nn >= 0 Then
Timer2.Interval = 500
nn = nn + 1
If nn Mod 2 = 1 Then
Label3.Caption = mes
Else
Label3.Caption = ""
End If
End If
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim gg As String
Winsock1.GetData gg, vbString
If gg <> "" Then
If Text4.Text = 1 Then
If Tet1.Text = "" Then
Tet1.Text = gg
Else
If Tet2.Text = "" Then
Tet2.Text = gg
Image4.Visible = True
Label6.Caption = Tet2.Text
Winsock1.RemoteHost = Tet1.Text
Winsock1.SendData Winsock1.LocalIP
Winsock1.SendData Text3.Text
Else
If Tet3.Text = "" Then
Tet3.Text = gg
Else
Tet4.Text = gg
Image3.Visible = True
Label5.Caption = Tet4.Text
Winsock1.RemoteHost = Tet3.Text
Winsock1.SendData Winsock1.LocalIP
Winsock1.SendData Text3.Text
Winsock1.SendData Winsock1.LocalIP
Winsock1.SendData Text3.Text
Winsock1.RemoteHost = Tet1.Text
Winsock1.SendData Tet3.Text
Winsock1.SendData Tet4.Text
nn = -1
Call Timer1_Timer
If Text1.Text = -1 Then
Winsock2.RemoteHost = Tet1.Text
Winsock2.SendData "1"
Winsock2.RemoteHost = Tet3.Text
Winsock2.SendData "0"
Form2.Label4.Visible = True
End If
If Text1.Text = 0 Then
Winsock2.RemoteHost = Tet1.Text
Winsock2.SendData "-1"
Winsock2.RemoteHost = Tet3.Text
Winsock2.SendData "1"
Form2.Label5.Visible = True
Form2.Command1.Visible = True
Form2.Command2.Visible = True
Form2.Command3.Visible = True
End If
If Text1.Text = 1 Then
Winsock2.RemoteHost = Tet1.Text
Winsock2.SendData "0"
Winsock2.RemoteHost = Tet3.Text
Winsock2.SendData "-1"
Form2.Label6.Visible = True
End If
Winsock2.Close
Me.Visible = False
Form2.Visible = True
End If
End If
End If
End If
If Text4.Text = 0 Then
If Tet1.Text = "" Then
Tet1.Text = gg
Else
If Tet2.Text = "" Then
Tet2.Text = gg
Image4.Visible = True
Label6.Caption = Tet2.Text
Else
If Tet3.Text = "" Then
Tet3.Text = gg
Else
Tet4.Text = gg
End If
End If
End If
End If
End If
End Sub
Private Sub Winsock2_DataArrival(ByVal bytesTotal As Long)
Dim gg As String
Winsock2.GetData gg, vbString
If gg <> "" Then
If Text4.Text = 0 Then
gb = Val(gg)
If gb = -1 Then
Form2.Label4.Visible = True
End If
If gb = 0 Then
Form2.Label5.Visible = True
Form2.Command1.Visible = True
Form2.Command2.Visible = True
Form2.Command3.Visible = True
End If
If gb = 1 Then
Form2.Label6.Visible = True
End If
Me.Visible = False
Form2.Visible = True
Winsock2.Close
End If
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -