基于 VB6的猜拳游戏
1 欢迎页的制作
-
welcomeFrom
添加一个定时器
代码如下:
Private Sub Form_Load()'定时器Timer1的时间间隔设置为1000毫秒Timer1.Interval = 1000Timer1.Enabled = TrueEnd SubPrivate Sub Timer1_Timer()'关闭当前窗体Unload MeReadyFrom.ShowEnd Sub
2 准备页的制作
-
放Image数组 组件
-
下面再放一个Image,以便拖动选择头像
-
如下
-
设置图片拖动图标属性
DragIcon
-
拖动头像代码如下
Public intIndex As Integer ' 当前图片索引
Public intFlag As Integer ' 标记变量,用于判断是否选择了图片
' 图片控件的鼠标按下事件
Private Sub Image1_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)Image1(Index).Drag vbBeginDrag ' 开始拖动图片intIndex = Index ' 记录当前图片的索引
End Sub
' 图片控件的放下事件
Private Sub Image2_DragDrop(Source As Control, X As Single, Y As Single)Image2.Picture = Image1(intIndex).Picture ' 将拖动的图片设置为目标图片intFlag = 1 ' 设置标记变量为1,表示已选择了图片
End Sub
- 加入一个按钮和文本框
- 代码如下
Private Sub nameEdit_KeyDown(KeyCode As Integer, Shift As Integer)' 按下Enter键时触发事件If KeyCode = 13 ThenCall playGameEnd If
End SubPrivate Sub playBtn_Click()Call playGame
End SubPrivate Sub playGame()' 游戏开始逻辑If nameEdit.Text = "" ThenMsgBox "お名前をご入力ください!" ' 提示输入用户名ElseIf intFlag = 0 ThenMsgBox "アバターを選択してください" ' 提示选择一张图片ElsestrUserName = nameEdit.Text ' 获取用户输入的用户名' 显示游戏主界面并关闭当前窗体gameFrom.ShowUnload MeEnd If
End Sub
3 游戏页的制作
- 页面图
1 显示选择的头像和用户名
代码如下:
Dim strMyName As String ' 玩家名称
Private Sub Form_Load()Call pageInit' 初始化界面控件状态'历史聊天框historyEdit.Locked = True'连接IP按钮connectBtn.Enabled = False'发送信息按钮sendBtn.Enabled = False'发送信息文本区textEdit.Enabled = False'选择石头剪刀按钮myChoiceBtn.Enabled = FalseEnd Sub' 页面初始化函数
Private Sub pageInit()If ReadyFrom.intIndex = 0 ThenstrImgPath = "\img\img0.jpg"ElseIf ReadyFrom.intIndex = 1 ThenstrImgPath = "\img\img1.jpg"ElseIf ReadyFrom.intIndex = 2 ThenstrImgPath = "\img\img2.jpeg"ElseIf ReadyFrom.intIndex = 3 ThenstrImgPath = "\img\img3.jpg"ElseIf ReadyFrom.intIndex = 4 ThenstrImgPath = "\img\img4.jpg"End If' 加载图片到界面myImg.Picture = LoadPicture(App.Path & strImgPath)' 设置玩家名称myNameLable.Caption = ReadyFrom.strUserNamestrMyName = ReadyFrom.strUserName
End Sub
2 石头剪刀布显示在我的选择框中
代码如下:
Dim strChoosedImgPath As String ' 选择的图片路径
Dim boolImgFlag As Boolean ' 是否可以选择图片
Dim boolMePunches As Boolean ' 我的出拳情况'单机imgGame组件事件
Private Sub imgGame_Click(Index As Integer)If boolImgFlag Or boolMePunches = False Then' 显示对手选择的默认图片FriChoiceImg.Picture = LoadPicture(App.Path & "\img\img5.jpg")If Index = 0 ThenstrChoosed = 1 ' 石头strChoosedImgPath = "\img\shi.jpg"ElseIf Index = 1 ThenstrChoosed = 2 ' 剪刀strChoosedImgPath = "\img\jian.jpg"ElseIf Index = 2 ThenstrChoosed = 3 ' 布strChoosedImgPath = "\img\bu.jpg"End If' 启用确认按钮myChoiceBtn.Enabled = TrueMyChoiceImg.Picture = LoadPicture(App.Path & strChoosedImgPath)ElseMsgBox "当前不能选择手势或已经出拳,请等待对手出拳完成后再操作"End If
End Sub
3 ip是否正确地址的检验,及利用Winsock进行udp连接作成简单聊天
-
引入Winsock,并设置protocol
-
检验文本框ip是否正确
Dim strIpAddress As String ' IP地址
'校验IP地址
Private Sub friendIpEdit_Change()connectBtn.Enabled = False ' 禁用连接按钮' 获取用户输入的IP地址strIpAddress = friendIpEdit.Text' 检查IP地址是否合法If IsValidstrIpAddress(strIpAddress) ThenconnectBtn.Enabled = True ' 若IP地址合法,则启用连接按钮End If
End Sub
' 校验IP地址是否合法的函数
Public Function IsValidstrIpAddress(ByVal strIpAddress As String) As Boolean' 声明变量Dim parts() As String ' 用于存储IP地址各部分的数组Dim i As Integer ' 循环计数器Dim temp As Integer ' 临时存储转换后的IP地址部分值' 使用"."分割IP地址字符串并存入数组partsparts = Split(strIpAddress, ".")' 判断IP地址部分数量是否为4If UBound(parts) <> 3 ThenIsValidstrIpAddress = False ' 返回FalseExit Function ' 退出函数End If' 遍历IP地址的各个部分For i = LBound(parts) To UBound(parts)' 判断是否为数字If Not IsNumeric(parts(i)) ThenIsValidstrIpAddress = False ' 返回FalseExit Function ' 退出函数End If' 将IP地址部分转换为整数并判断是否在0~255范围内temp = CInt(parts(i))If temp < 0 Or temp > 255 ThenIsValidstrIpAddress = False ' 返回FalseExit Function ' 退出函数End IfNext i' 若通过上述检查,则IP地址合法,返回TrueIsValidstrIpAddress = True
End Function
- udp的连接及聊天和状态显示
代码如下
Dim strImgPath As String ' 图片路径
Dim strDataName As String ' 数据名称
Dim boolConnectFlag As Boolean ' 是否连接状态
Dim boolImgFlag As Boolean ' 是否可以选择图片
' 发起连接按钮点击事件
Private Sub Form_Load()Dim ipname As StringDim Bind() As String' 获取本地IP地址ipname = Winsock.LocalIP' 将IP地址按点分割成数组Bind = Split(ipname, ".")' 绑定本地IP和端口号,端口号为1000 + IP地址的最后一位Winsock.Bind (1000 + Bind(3))boolImgFlag = TrueboolConnectFlag = True
End Sub
Private Sub connectBtn_Click()On Error Resume Next' 设置远程主机IP和端口号With Winsock.RemoteHost = strIpAddressDim RemotePort() As StringRemotePort = Split(strIpAddress, ".").RemotePort = (1000 + RemotePort(3))End With' 发送初始化消息包括玩家名称和图片路径Winsock.SendData "#InitSend#" & strMyName & "#" & strImgPathIf Err.Number <> 0 ThenMsgBox (Err.Description)Err.ClearEnd If
End SubPrivate Sub sendBtn_Click()' 检查文本编辑框是否有内容If textEdit.Text <> "" ThenhistoryEdit.Text = historyEdit.Text & "---mine---" & vbCrLf ' 在历史记录中添加发送消息标识historyEdit.Text = historyEdit.Text & textEdit.Text & vbCrLf ' 在历史记录中添加发送的文本内容' 发送消息包括玩家名称和文本内容Winsock.SendData "@MsgSend@" & strMyName & "@" & textEdit.Text ' 发送消息数据textEdit.Text = "" ' 清空文本编辑框内容ElseMsgBox "请输入要发送的消息内容" ' 如果文本编辑框内容为空,弹出提示框End If
End Sub'接受数据处理
Private Sub Winsock_DataArrival(ByVal bytesTotal As Long)Dim strData As String ' 定义字符串变量用于存储接收的数据Dim strDatas() As String ' 定义字符串数组用于存储分割后的数据Dim strDataTxt As String ' 定义字符串变量用于存储文本数据Dim strDataImgPath As String ' 定义字符串变量用于存储图片路径' 接收数据Winsock.GetData strDataIf InStr(strData, "#InitSend#") Then' 如果接收到初始化数据strDatas = Split(strData, "#") ' 使用#符号分割数据strDataName = strDatas(2) ' 获取对方名称strDataImgPath = strDatas(3) ' 获取对方头像路径friendNameLable.Caption = strDataName ' 设置对方名称标签显示内容Print (strDataImgPath)'friendImg.Picture = LoadPicture(App.Path & strDataImgPath) ' 加载对方头像图片' 如果是刚连接上,则回复初始化消息If boolConnectFlag ThenWinsock.SendData "#InitSend#" & strMyName & "#" & strImgPath ' 回复初始化消息boolConnectFlag = False ' 将连接标志设为FalseEnd IfsendBtn.Enabled = True ' 启用发送按钮textEdit.Enabled = True ' 启用文本编辑框ElseIf InStr(strData, "#MsgSend#") Then' 如果接收到消息数据strDatas = Split(strData, "#") ' 使用#符号分割数据strDataName = strDatas(2) ' 获取对方名称strDataTxt = strDatas(3) ' 获取消息内容historyEdit.Text = historyEdit.Text & "---" & strDataName & "---" & vbCrLf ' 在历史记录中添加对方名称historyEdit.Text = historyEdit.Text & strDataTxt & vbCrLf ' 在历史记录中添加消息内容historyEdit.SelStart = Len(historyEdit.Text) ' 将光标定位到文本末尾End If
End Sub
- 猜拳游戏的完成
代码如下:
Dim strChoosed As String ' 选择的手势
Dim strMyName As String ' 玩家名称
Dim IntGameNumber As Integer ' 游戏局数
Dim strDataChoPath As String ' 数据路径
Dim strDataFriChoe As String ' 对手选择
Dim strGame As String ' 我和对手的选择Dim boolFriPunches As Boolean ' 对手的出拳情况Private Sub Form_Load()boolMePunches = FalseboolFriPunches = False
End SubPrivate Sub myChoiceBtn_Click()' 禁用确认按钮myChoiceBtn.Enabled = FalseboolMePunches = True' 发送游戏出拳消息包括玩家名称和选择的手势Winsock.SendData "@GameSend@" & strMyName & "@" & strChoosed & "@" & strChoosedImgPathhistoryEdit.Text = historyEdit.Text & "等待对手出拳..." & vbCrLf' 如果双方都已出拳,则判断胜负If boolMePunches And boolFriPunches ThenWinOrLoseEnd IfboolImgFlag = False
End SubPrivate Sub Winsock_DataArrival(ByVal bytesTotal As Long)Dim strData As String ' 定义字符串变量用于存储接收的数据Dim strDatas() As String ' 定义字符串数组用于存储分割后的数据Dim strDataTxt As String ' 定义字符串变量用于存储文本数据Dim strDatastrImgPath As String ' 定义字符串变量用于存储图片路径' 接收数据Winsock.GetData strDataIf InStr(strData, "@InitSend@") Then' 如果接收到初始化数据strDatas = Split(strData, "@") ' 使用@符号分割数据strDataName = strDatas(2) ' 获取对方名称strDatastrImgPath = strDatas(3) ' 获取对方头像路径friendNameLable.Caption = strDataName ' 设置对方名称标签显示内容friendImg.Picture = LoadPicture(App.Path & strDatastrImgPath) ' 加载对方头像图片' 如果是刚连接上,则回复初始化消息If boolConnectFlag ThenWinsock.SendData "@InitSend@" & strMyName & "@" & strImgPath ' 回复初始化消息boolConnectFlag = False ' 将连接标志设为FalseEnd IfsendBtn.Enabled = True ' 启用发送按钮textEdit.Enabled = True ' 启用文本编辑框ElseIf InStr(strData, "@GameSend@") Then' 如果接收到游戏数据strDatas = Split(strData, "@") ' 使用@符号分割数据strDataName = strDatas(2) ' 获取对方名称strDataFriChoe = strDatas(3) ' 获取对方选择strDataChoPath = strDatas(4) ' 获取对方选择图片路径boolFriPunches = True ' 对方已出拳标志设为True' 如果双方都已出拳,则判断胜负If boolMePunches And boolFriPunches ThenWinOrLose ' 调用判断胜负函数End If ElseIf InStr(strData, "@MsgSend@") Then' 如果接收到消息数据strDatas = Split(strData, "@") ' 使用@符号分割数据strDataName = strDatas(2) ' 获取对方名称strDataTxt = strDatas(3) ' 获取消息内容historyEdit.Text = historyEdit.Text & "---" & strDataName & "---" & vbCrLf ' 在历史记录中添加对方名称historyEdit.Text = historyEdit.Text & strDataTxt & vbCrLf ' 在历史记录中添加消息内容historyEdit.SelStart = Len(historyEdit.Text) ' 将光标定位到文本末尾ElseIf InStr(strData, "@endSend@") Then' 如果接收到结束连接数据MsgBox "对方已断开连接" ' 弹出提示对话框friendImg.Picture = LoadPicture(App.Path & "\img\img5.jpg") ' 加载默认对方头像friendNameLable.Caption = "???" ' 设置对方名称为问号FriChoiceImg.Picture = LoadPicture(App.Path & "\img\img5.jpg") ' 加载默认选择图片strDataChoPath = "" ' 清空选择图片路径strDataFriChoe = "" ' 清空对方选择strGame = "" ' 清空游戏状态strDataName = "" ' 清空对方名称End If
End SubPrivate Sub WinOrLose()' 显示对手选择的图片FriChoiceImg.Picture = LoadPicture(App.Path & strDataChoPath)' 判断胜负strGame = strChoosed & strDataFriChoeSelect Case strGameCase "11"MsgBox "平局"DisResults ("0")Case "12"MsgBox "你赢了"DisResults (strMyName)Case "13"MsgBox "对方赢了"DisResults (strDataName)Case "21"MsgBox "对方赢了"DisResults (strDataName)Case "22"MsgBox "平局"DisResults ("0")Case "23"MsgBox "你赢了"DisResults (strMyName)Case "31"MsgBox "你赢了"DisResults (strMyName)Case "32"MsgBox "对方赢了"DisResults (strDataName)Case "33"MsgBox "平局"DisResults ("0")End SelectboolImgFlag = TrueIntGameNumber = 0strChoosed = ""strDataFriChoe = ""strDataChoPath = ""strDataFriChoe = ""strGame = ""boolFriPunches = FalseboolMePunches = FalseboolImgFlag = True
End SubPrivate Sub DisResults(str As String)If str = "0" ThenhistoryEdit.Text = historyEdit.Text & vbCrLf & "--**平局**--" & vbCrLf & vbCrLfElsehistoryEdit.Text = historyEdit.Text & vbCrLf & "结果--" & str & "--胜利" & vbCrLf & vbCrLfEnd IfhistoryEdit.Text = historyEdit.Text & "------------------------" & vbCrLf & vbCrLfhistoryEdit.SelStart = Len(historyEdit.Text)
End Sub
- 该页总代码
Dim strImgPath As String ' 图片路径
Dim strMyName As String ' 玩家名称
Dim strChoosedImgPath As String ' 选择的图片路径
Dim strIpAddress As String ' IP地址
Dim strDataName As String ' 数据名称
Dim boolConnectFlag As Boolean ' 是否连接状态Dim strChoosed As String ' 选择的手势
Dim IntGameNumber As Integer ' 游戏局数
Dim strDataChoPath As String ' 数据路径
Dim strDataFriChoe As String ' 对手选择
Dim strGame As String ' 我和对手的选择Dim boolFriPunches As Boolean ' 对手的出拳情况Dim boolImgFlag As Boolean ' 是否可以选择图片
Dim boolMePunches As Boolean ' 我的出拳情况
Private Sub Form_Load()Call pageInit' 初始化界面控件状态'历史聊天框historyEdit.Locked = True'连接IP按钮connectBtn.Enabled = False'发送信息按钮sendBtn.Enabled = False'发送信息文本区textEdit.Enabled = False'选择石头剪刀按钮myChoiceBtn.Enabled = FalseDim ipname As StringDim Bind() As String' 获取本地IP地址ipname = Winsock.LocalIP' 将IP地址按点分割成数组Bind = Split(ipname, ".")' 绑定本地IP和端口号,端口号为1000 + IP地址的最后一位Winsock.Bind (1000 + Bind(3))boolMePunches = FalseboolFriPunches = FalseboolImgFlag = TrueboolConnectFlag = True
End SubPrivate Sub myChoiceBtn_Click()' 禁用确认按钮myChoiceBtn.Enabled = FalseboolMePunches = True' 发送游戏出拳消息包括玩家名称和选择的手势Winsock.SendData "#GameSend#" & strMyName & "#" & strChoosed & "#" & strChoosedImgPathhistoryEdit.Text = historyEdit.Text & "等待对手出拳..." & vbCrLf' 如果双方都已出拳,则判断胜负If boolMePunches And boolFriPunches ThenWinOrLoseEnd IfboolImgFlag = False
End Sub' 发起连接按钮点击事件
Private Sub connectBtn_Click()On Error Resume Next' 设置远程主机IP和端口号With Winsock.RemoteHost = strIpAddressDim RemotePort() As StringRemotePort = Split(strIpAddress, ".").RemotePort = (1000 + RemotePort(3))End With' 发送初始化消息包括玩家名称和图片路径Winsock.SendData "#InitSend#" & strMyName & "#" & strImgPathIf Err.Number <> 0 ThenMsgBox (Err.Description)Err.ClearEnd If
End SubPrivate Sub sendBtn_Click()' 检查文本编辑框是否有内容If textEdit.Text <> "" ThenhistoryEdit.Text = historyEdit.Text & "---mine---" & vbCrLf ' 在历史记录中添加发送消息标识historyEdit.Text = historyEdit.Text & textEdit.Text & vbCrLf ' 在历史记录中添加发送的文本内容' 发送消息包括玩家名称和文本内容Winsock.SendData "#MsgSend#" & strMyName & "#" & textEdit.Text ' 发送消息数据textEdit.Text = "" ' 清空文本编辑框内容ElseMsgBox "请输入要发送的消息内容" ' 如果文本编辑框内容为空,弹出提示框End If
End Sub'接受数据处理
Private Sub Winsock_DataArrival(ByVal bytesTotal As Long)Dim strData As String ' 定义字符串变量用于存储接收的数据Dim strDatas() As String ' 定义字符串数组用于存储分割后的数据Dim strDataTxt As String ' 定义字符串变量用于存储文本数据Dim strDataImgPath As String ' 定义字符串变量用于存储图片路径' 接收数据Winsock.GetData strDataIf InStr(strData, "#InitSend#") Then' 如果接收到初始化数据strDatas = Split(strData, "#") ' 使用#符号分割数据strDataName = strDatas(2) ' 获取对方名称strDataImgPath = strDatas(3) ' 获取对方头像路径friendNameLable.Caption = strDataName ' 设置对方名称标签显示内容friendImg.Picture = LoadPicture(App.Path & strDataImgPath) ' 加载对方头像图片' 如果是刚连接上,则回复初始化消息If boolConnectFlag ThenWinsock.SendData "#InitSend#" & strMyName & "#" & strImgPath ' 回复初始化消息boolConnectFlag = False ' 将连接标志设为FalseEnd IfsendBtn.Enabled = True ' 启用发送按钮textEdit.Enabled = True ' 启用文本编辑框ElseIf InStr(strData, "#GameSend#") Then' 如果接收到游戏数据strDatas = Split(strData, "#") ' 使用#符号分割数据strDataName = strDatas(2) ' 获取对方名称strDataFriChoe = strDatas(3) ' 获取对方选择strDataChoPath = strDatas(4) ' 获取对方选择图片路径boolFriPunches = True ' 对方已出拳标志设为True' 如果双方都已出拳,则判断胜负If boolMePunches And boolFriPunches ThenWinOrLose ' 调用判断胜负函数End IfElseIf InStr(strData, "#MsgSend#") Then' 如果接收到消息数据strDatas = Split(strData, "#") ' 使用#符号分割数据strDataName = strDatas(2) ' 获取对方名称strDataTxt = strDatas(3) ' 获取消息内容historyEdit.Text = historyEdit.Text & "---" & strDataName & "---" & vbCrLf ' 在历史记录中添加对方名称historyEdit.Text = historyEdit.Text & strDataTxt & vbCrLf ' 在历史记录中添加消息内容historyEdit.SelStart = Len(historyEdit.Text) ' 将光标定位到文本末尾ElseIf InStr(strData, "#endSend#") Then' 如果接收到结束连接数据MsgBox "对方已断开连接" ' 弹出提示对话框friendImg.Picture = LoadPicture(App.Path & "\img\img5.jpg") ' 加载默认对方头像friendNameLable.Caption = "???" ' 设置对方名称为问号FriChoiceImg.Picture = LoadPicture(App.Path & "\img\img5.jpg") ' 加载默认选择图片strDataChoPath = "" ' 清空选择图片路径strDataFriChoe = "" ' 清空对方选择strGame = "" ' 清空游戏状态strDataName = "" ' 清空对方名称End If
End Sub
Private Sub WinOrLose()' 显示对手选择的图片FriChoiceImg.Picture = LoadPicture(App.Path & strDataChoPath)' 判断胜负strGame = strChoosed & strDataFriChoeSelect Case strGameCase "11"MsgBox "平局"DisResults ("0")Case "12"MsgBox "你赢了"DisResults (strMyName)Case "13"MsgBox "对方赢了"DisResults (strDataName)Case "21"MsgBox "对方赢了"DisResults (strDataName)Case "22"MsgBox "平局"DisResults ("0")Case "23"MsgBox "你赢了"DisResults (strMyName)Case "31"MsgBox "你赢了"DisResults (strMyName)Case "32"MsgBox "对方赢了"DisResults (strDataName)Case "33"MsgBox "平局"DisResults ("0")End SelectboolImgFlag = TrueIntGameNumber = 0strChoosed = ""strDataFriChoe = ""strDataChoPath = ""strDataFriChoe = ""strGame = ""boolFriPunches = FalseboolMePunches = FalseboolImgFlag = True
End SubPrivate Sub DisResults(str As String)If str = "0" ThenhistoryEdit.Text = historyEdit.Text & vbCrLf & "--**平局**--" & vbCrLf & vbCrLfElsehistoryEdit.Text = historyEdit.Text & vbCrLf & "结果--" & str & "--胜利" & vbCrLf & vbCrLfEnd IfhistoryEdit.Text = historyEdit.Text & "------------------------" & vbCrLf & vbCrLfhistoryEdit.SelStart = Len(historyEdit.Text)
End Sub'单机imgGame组件事件
Private Sub imgGame_Click(Index As Integer)If boolImgFlag Or boolMePunches = False Then' 显示对手选择的默认图片FriChoiceImg.Picture = LoadPicture(App.Path & "\img\img5.jpg")If Index = 0 ThenstrChoosed = 1 ' 石头strChoosedImgPath = "\img\shi.jpg"ElseIf Index = 1 ThenstrChoosed = 2 ' 剪刀strChoosedImgPath = "\img\jian.jpg"ElseIf Index = 2 ThenstrChoosed = 3 ' 布strChoosedImgPath = "\img\bu.jpg"End If' 启用确认按钮myChoiceBtn.Enabled = TrueMyChoiceImg.Picture = LoadPicture(App.Path & strChoosedImgPath)ElseMsgBox "当前不能选择手势或已经出拳,请等待对手出拳完成后再操作"End If
End Sub'校验IP地址
Private Sub friendIpEdit_Change()connectBtn.Enabled = False ' 禁用连接按钮' 获取用户输入的IP地址strIpAddress = friendIpEdit.Text' 检查IP地址是否合法If IsValidstrIpAddress(strIpAddress) ThenconnectBtn.Enabled = True ' 若IP地址合法,则启用连接按钮End If
End Sub' 校验IP地址是否合法的函数
Public Function IsValidstrIpAddress(ByVal strIpAddress As String) As Boolean' 声明变量Dim parts() As String ' 用于存储IP地址各部分的数组Dim i As Integer ' 循环计数器Dim temp As Integer ' 临时存储转换后的IP地址部分值' 使用"."分割IP地址字符串并存入数组partsparts = Split(strIpAddress, ".")' 判断IP地址部分数量是否为4If UBound(parts) <> 3 ThenIsValidstrIpAddress = False ' 返回FalseExit Function ' 退出函数End If' 遍历IP地址的各个部分For i = LBound(parts) To UBound(parts)' 判断是否为数字If Not IsNumeric(parts(i)) ThenIsValidstrIpAddress = False ' 返回FalseExit Function ' 退出函数End If' 将IP地址部分转换为整数并判断是否在0~255范围内temp = CInt(parts(i))If temp < 0 Or temp > 255 ThenIsValidstrIpAddress = False ' 返回FalseExit Function ' 退出函数End IfNext i' 若通过上述检查,则IP地址合法,返回TrueIsValidstrIpAddress = True
End Function' 页面初始化函数
Private Sub pageInit()If ReadyFrom.intIndex = 0 ThenstrImgPath = "\img\img0.jpg"ElseIf ReadyFrom.intIndex = 1 ThenstrImgPath = "\img\img1.jpg"ElseIf ReadyFrom.intIndex = 2 ThenstrImgPath = "\img\img2.jpeg"ElseIf ReadyFrom.intIndex = 3 ThenstrImgPath = "\img\img3.jpg"ElseIf ReadyFrom.intIndex = 4 ThenstrImgPath = "\img\img4.jpg"End If' 加载图片到界面myImg.Picture = LoadPicture(App.Path & strImgPath)' 设置玩家名称myNameLable.Caption = ReadyFrom.strUserNamestrMyName = ReadyFrom.strUserName
End SubPrivate Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)' 若仍处于连接状态则发送断开消息If strDataName <> "" ThenWinsock.SendData "@endSend@"End IffrmBye.ShowUnload MeEnd Sub
- 页面4,结束页面
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)' 若仍处于连接状态则发送断开消息If strDataName <> "" ThenWinsock.SendData "@endSend@"End IfUnload MefrmBye.Show
End Sub
- frmBye
Private Sub Form_Load()Timer1.Interval = 1500Timer1.Enabled = True
End SubPrivate Sub Timer1_Timer()Unload MeEnd
End Sub