基于 VB6的猜拳游戏

基于 VB6的猜拳游戏

1 欢迎页的制作

  • welcomeFrom

    在这里插入图片描述
    在这里插入图片描述
    添加一个定时器
    在这里插入图片描述

代码如下:

	Private Sub Form_Load()
    '定时器Timer1的时间间隔设置为1000毫秒
    Timer1.Interval = 1000
    Timer1.Enabled = True
	End Sub
	Private Sub Timer1_Timer()
	    '关闭当前窗体
	    Unload Me
	    ReadyFrom.Show
	End 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 Then
        Call playGame
    End If
End Sub


Private Sub playBtn_Click()
    Call playGame
End Sub

Private Sub playGame()
    ' 游戏开始逻辑
    If nameEdit.Text = "" Then
        MsgBox "お名前をご入力ください!" ' 提示输入用户名
    ElseIf intFlag = 0 Then
        MsgBox "アバターを選択してください" ' 提示选择一张图片
    Else
        strUserName = nameEdit.Text ' 获取用户输入的用户名
        ' 显示游戏主界面并关闭当前窗体
        gameFrom.Show
        Unload Me
    End 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 = False

End Sub

' 页面初始化函数
Private Sub pageInit()
    If ReadyFrom.intIndex = 0 Then
        strImgPath = "\img\img0.jpg"
    ElseIf ReadyFrom.intIndex = 1 Then
        strImgPath = "\img\img1.jpg"
    ElseIf ReadyFrom.intIndex = 2 Then
        strImgPath = "\img\img2.jpeg"
    ElseIf ReadyFrom.intIndex = 3 Then
        strImgPath = "\img\img3.jpg"
    ElseIf ReadyFrom.intIndex = 4 Then
        strImgPath = "\img\img4.jpg"
    End If
    
    ' 加载图片到界面
    myImg.Picture = LoadPicture(App.Path & strImgPath)
    ' 设置玩家名称
    myNameLable.Caption = ReadyFrom.strUserName
    strMyName = 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 Then
            strChoosed = 1 ' 石头
            strChoosedImgPath = "\img\shi.jpg"
        ElseIf Index = 1 Then
            strChoosed = 2 ' 剪刀
            strChoosedImgPath = "\img\jian.jpg"
        ElseIf Index = 2 Then
            strChoosed = 3 ' 布
            strChoosedImgPath = "\img\bu.jpg"
        End If
        
        ' 启用确认按钮
        myChoiceBtn.Enabled = True
        MyChoiceImg.Picture = LoadPicture(App.Path & strChoosedImgPath)
    Else
        MsgBox "当前不能选择手势或已经出拳,请等待对手出拳完成后再操作"
    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) Then
        connectBtn.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地址字符串并存入数组parts
    parts = Split(strIpAddress, ".")

    ' 判断IP地址部分数量是否为4
    If UBound(parts) <> 3 Then
        IsValidstrIpAddress = False  ' 返回False
        Exit Function  ' 退出函数
    End If

    ' 遍历IP地址的各个部分
    For i = LBound(parts) To UBound(parts)
        ' 判断是否为数字
        If Not IsNumeric(parts(i)) Then
            IsValidstrIpAddress = False  ' 返回False
            Exit Function  ' 退出函数
        End If

        ' 将IP地址部分转换为整数并判断是否在0~255范围内
        temp = CInt(parts(i))
        If temp < 0 Or temp > 255 Then
            IsValidstrIpAddress = False  ' 返回False
            Exit Function  ' 退出函数
        End If
    Next i

    ' 若通过上述检查,则IP地址合法,返回True
    IsValidstrIpAddress = 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 String
    Dim Bind() As String

    ' 获取本地IP地址
    ipname = Winsock.LocalIP
    ' 将IP地址按点分割成数组
    Bind = Split(ipname, ".")
    ' 绑定本地IP和端口号,端口号为1000 + IP地址的最后一位
    Winsock.Bind (1000 + Bind(3))
    
    boolImgFlag = True
    boolConnectFlag = True
End Sub
Private Sub connectBtn_Click()
    On Error Resume Next
    ' 设置远程主机IP和端口号
    With Winsock
        .RemoteHost = strIpAddress
        Dim RemotePort() As String
        RemotePort = Split(strIpAddress, ".")
        .RemotePort = (1000 + RemotePort(3))
    End With
    ' 发送初始化消息包括玩家名称和图片路径
    Winsock.SendData "#InitSend#" & strMyName & "#" & strImgPath
    If Err.Number <> 0 Then
         MsgBox (Err.Description)
         Err.Clear
    End If
End Sub

Private Sub sendBtn_Click()
    ' 检查文本编辑框是否有内容
    If textEdit.Text <> "" Then
        historyEdit.Text = historyEdit.Text & "---mine---" & vbCrLf  ' 在历史记录中添加发送消息标识
        historyEdit.Text = historyEdit.Text & textEdit.Text & vbCrLf  ' 在历史记录中添加发送的文本内容
      
        ' 发送消息包括玩家名称和文本内容
        Winsock.SendData "@MsgSend@" & strMyName & "@" & textEdit.Text  ' 发送消息数据
        
        textEdit.Text = ""  ' 清空文本编辑框内容

    Else
        MsgBox "请输入要发送的消息内容"  ' 如果文本编辑框内容为空,弹出提示框
    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 strData

    If 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 Then
            Winsock.SendData "#InitSend#" & strMyName & "#" & strImgPath  ' 回复初始化消息
            boolConnectFlag = False  ' 将连接标志设为False
        End If
        
        sendBtn.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 = False
    boolFriPunches = False
End Sub

Private Sub myChoiceBtn_Click()
    ' 禁用确认按钮
    myChoiceBtn.Enabled = False
    boolMePunches = True
    ' 发送游戏出拳消息包括玩家名称和选择的手势
    Winsock.SendData "@GameSend@" & strMyName & "@" & strChoosed & "@" & strChoosedImgPath
    historyEdit.Text = historyEdit.Text & "等待对手出拳..." & vbCrLf
    ' 如果双方都已出拳,则判断胜负
    If boolMePunches And boolFriPunches Then
        WinOrLose
    End If
    boolImgFlag = False
End Sub

Private 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 strData
    If InStr(strData, "@InitSend@") Then
        ' 如果接收到初始化数据
        strDatas = Split(strData, "@")  ' 使用@符号分割数据
        strDataName = strDatas(2)  ' 获取对方名称
        strDatastrImgPath = strDatas(3)  ' 获取对方头像路径
        friendNameLable.Caption = strDataName  ' 设置对方名称标签显示内容
        friendImg.Picture = LoadPicture(App.Path & strDatastrImgPath)  ' 加载对方头像图片
        ' 如果是刚连接上,则回复初始化消息
        If boolConnectFlag Then
            Winsock.SendData "@InitSend@" & strMyName & "@" & strImgPath  ' 回复初始化消息
            boolConnectFlag = False  ' 将连接标志设为False
        End If
        
        sendBtn.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 Then
            WinOrLose  ' 调用判断胜负函数
        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 Sub

Private Sub WinOrLose()
    ' 显示对手选择的图片
    FriChoiceImg.Picture = LoadPicture(App.Path & strDataChoPath)

    ' 判断胜负
    strGame = strChoosed & strDataFriChoe
    Select Case strGame
        Case "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 Select
    
    boolImgFlag = True
    IntGameNumber = 0
    strChoosed = ""
    strDataFriChoe = ""
    strDataChoPath = ""
    strDataFriChoe = ""
    strGame = ""
    boolFriPunches = False
    boolMePunches = False
    boolImgFlag = True
End Sub

Private Sub DisResults(str As String)
    If str = "0" Then
        historyEdit.Text = historyEdit.Text & vbCrLf & "--**平局**--" & vbCrLf & vbCrLf
    Else
        historyEdit.Text = historyEdit.Text & vbCrLf & "结果--" & str & "--胜利" & vbCrLf & vbCrLf
    End If
    historyEdit.Text = historyEdit.Text & "------------------------" & vbCrLf & vbCrLf
    historyEdit.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 = False
    
    
    Dim ipname As String
    Dim Bind() As String

    ' 获取本地IP地址
    ipname = Winsock.LocalIP
    ' 将IP地址按点分割成数组
    Bind = Split(ipname, ".")
    ' 绑定本地IP和端口号,端口号为1000 + IP地址的最后一位
    Winsock.Bind (1000 + Bind(3))
    
    boolMePunches = False
    boolFriPunches = False
    boolImgFlag = True
    boolConnectFlag = True
End Sub






Private Sub myChoiceBtn_Click()
    ' 禁用确认按钮
    myChoiceBtn.Enabled = False

    boolMePunches = True
    ' 发送游戏出拳消息包括玩家名称和选择的手势
    Winsock.SendData "#GameSend#" & strMyName & "#" & strChoosed & "#" & strChoosedImgPath
    historyEdit.Text = historyEdit.Text & "等待对手出拳..." & vbCrLf

    ' 如果双方都已出拳,则判断胜负
    If boolMePunches And boolFriPunches Then
        WinOrLose
    End If

    boolImgFlag = False
End Sub








' 发起连接按钮点击事件
Private Sub connectBtn_Click()
    On Error Resume Next
    ' 设置远程主机IP和端口号
    With Winsock
        .RemoteHost = strIpAddress
        Dim RemotePort() As String
        RemotePort = Split(strIpAddress, ".")
        .RemotePort = (1000 + RemotePort(3))
    End With
    ' 发送初始化消息包括玩家名称和图片路径
    Winsock.SendData "#InitSend#" & strMyName & "#" & strImgPath
    If Err.Number <> 0 Then
         MsgBox (Err.Description)
         Err.Clear
    End If
End Sub



Private Sub sendBtn_Click()
    ' 检查文本编辑框是否有内容
    If textEdit.Text <> "" Then
        historyEdit.Text = historyEdit.Text & "---mine---" & vbCrLf  ' 在历史记录中添加发送消息标识
        historyEdit.Text = historyEdit.Text & textEdit.Text & vbCrLf  ' 在历史记录中添加发送的文本内容
      
        ' 发送消息包括玩家名称和文本内容
        Winsock.SendData "#MsgSend#" & strMyName & "#" & textEdit.Text  ' 发送消息数据
        
        textEdit.Text = ""  ' 清空文本编辑框内容

    Else
        MsgBox "请输入要发送的消息内容"  ' 如果文本编辑框内容为空,弹出提示框
    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 strData

    If InStr(strData, "#InitSend#") Then
        ' 如果接收到初始化数据
        strDatas = Split(strData, "#")  ' 使用#符号分割数据
        strDataName = strDatas(2)  ' 获取对方名称
        strDataImgPath = strDatas(3)  ' 获取对方头像路径
        friendNameLable.Caption = strDataName  ' 设置对方名称标签显示内容
        friendImg.Picture = LoadPicture(App.Path & strDataImgPath)  ' 加载对方头像图片
        
        ' 如果是刚连接上,则回复初始化消息
        If boolConnectFlag Then
            Winsock.SendData "#InitSend#" & strMyName & "#" & strImgPath  ' 回复初始化消息
            boolConnectFlag = False  ' 将连接标志设为False
        End If
        
        sendBtn.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 Then
            WinOrLose  ' 调用判断胜负函数
        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 Sub
Private Sub WinOrLose()
    ' 显示对手选择的图片
    FriChoiceImg.Picture = LoadPicture(App.Path & strDataChoPath)

    ' 判断胜负
    strGame = strChoosed & strDataFriChoe
    Select Case strGame
        Case "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 Select
    
    boolImgFlag = True
    IntGameNumber = 0
    strChoosed = ""
    strDataFriChoe = ""
    strDataChoPath = ""
    strDataFriChoe = ""
    strGame = ""
    boolFriPunches = False
    boolMePunches = False
    boolImgFlag = True
End Sub

Private Sub DisResults(str As String)
    If str = "0" Then
        historyEdit.Text = historyEdit.Text & vbCrLf & "--**平局**--" & vbCrLf & vbCrLf
    Else
        historyEdit.Text = historyEdit.Text & vbCrLf & "结果--" & str & "--胜利" & vbCrLf & vbCrLf
    End If
    historyEdit.Text = historyEdit.Text & "------------------------" & vbCrLf & vbCrLf
    
    historyEdit.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 Then
            strChoosed = 1 ' 石头
            strChoosedImgPath = "\img\shi.jpg"
        ElseIf Index = 1 Then
            strChoosed = 2 ' 剪刀
            strChoosedImgPath = "\img\jian.jpg"
        ElseIf Index = 2 Then
            strChoosed = 3 ' 布
            strChoosedImgPath = "\img\bu.jpg"
        End If
        
        ' 启用确认按钮
        myChoiceBtn.Enabled = True
        MyChoiceImg.Picture = LoadPicture(App.Path & strChoosedImgPath)
    Else
        MsgBox "当前不能选择手势或已经出拳,请等待对手出拳完成后再操作"
    End If
End Sub

'校验IP地址
Private Sub friendIpEdit_Change()
    connectBtn.Enabled = False  ' 禁用连接按钮

    ' 获取用户输入的IP地址
    strIpAddress = friendIpEdit.Text

    ' 检查IP地址是否合法
    If IsValidstrIpAddress(strIpAddress) Then
        connectBtn.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地址字符串并存入数组parts
    parts = Split(strIpAddress, ".")

    ' 判断IP地址部分数量是否为4
    If UBound(parts) <> 3 Then
        IsValidstrIpAddress = False  ' 返回False
        Exit Function  ' 退出函数
    End If

    ' 遍历IP地址的各个部分
    For i = LBound(parts) To UBound(parts)
        ' 判断是否为数字
        If Not IsNumeric(parts(i)) Then
            IsValidstrIpAddress = False  ' 返回False
            Exit Function  ' 退出函数
        End If

        ' 将IP地址部分转换为整数并判断是否在0~255范围内
        temp = CInt(parts(i))
        If temp < 0 Or temp > 255 Then
            IsValidstrIpAddress = False  ' 返回False
            Exit Function  ' 退出函数
        End If
    Next i

    ' 若通过上述检查,则IP地址合法,返回True
    IsValidstrIpAddress = True
End Function

' 页面初始化函数
Private Sub pageInit()
    If ReadyFrom.intIndex = 0 Then
        strImgPath = "\img\img0.jpg"
    ElseIf ReadyFrom.intIndex = 1 Then
        strImgPath = "\img\img1.jpg"
    ElseIf ReadyFrom.intIndex = 2 Then
        strImgPath = "\img\img2.jpeg"
    ElseIf ReadyFrom.intIndex = 3 Then
        strImgPath = "\img\img3.jpg"
    ElseIf ReadyFrom.intIndex = 4 Then
        strImgPath = "\img\img4.jpg"
    End If
    
    ' 加载图片到界面
    myImg.Picture = LoadPicture(App.Path & strImgPath)
    ' 设置玩家名称
    myNameLable.Caption = ReadyFrom.strUserName
    strMyName = ReadyFrom.strUserName
End Sub


Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    ' 若仍处于连接状态则发送断开消息
    If strDataName <> "" Then
        Winsock.SendData "@endSend@"
    End If
    frmBye.Show
    Unload Me
    
End Sub




  • 页面4,结束页面

在这里插入图片描述
在这里插入图片描述

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    ' 若仍处于连接状态则发送断开消息
    If strDataName <> "" Then
        Winsock.SendData "@endSend@"
    End If
    Unload Me
	frmBye.Show
End Sub
  • frmBye
Private Sub Form_Load()
    Timer1.Interval = 1500
    Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
    Unload Me
    End
End Sub

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/493616.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

一键换脸的facefusion

FaceFusion 一个开源换脸软件&#xff0c;提供UI界面&#xff0c;启动后可直接在浏览器上面上传图片进行换脸操作。 电脑环境win10&#xff0c;软件pycharm&#xff0c;需要提前安装好python环境&#xff0c;推荐使用Anaconda3。关注文章下方公共号发送 “ 软件安装包 ”可以获…

Leaflet 中创建一个二维地图

要在 Leaflet 中创建一个二维地图&#xff0c;需要以下步骤&#xff1a; 1. 引入 Leaflet 库 首先&#xff0c;你需要在 HTML 文件中引入 Leaflet 库的 CSS 和 JavaScript 文件。你可以从官方网站下载 Leaflet&#xff0c;或者通过 CDN 引入。 <!-- Leaflet CSS --> &…

2024年上半年数学建模竞赛一览表(附赠12场竞赛的优秀论文+格式要求)[电工、妈杯、数维、五一等12场]

为了帮助大家更好地备战今年上半年十二场数学建模竞赛&#xff0c;我们为大家收集到了这十二场相关竞赛的优秀论文以及格式要求&#xff0c;具体内容如下所示。 资料获取 在文末 文中资料来源 名称竞赛官方网站天府杯https://www.tfmssy.org.cn/认证杯http://www.tzmcm.cn/i…

SpringBoot学习笔记一、SpringBoot应用初创建以及应用

一、创建SpringBoot的两种方式 1.Spring Initializr方式创建 &#xff08;1&#xff09;第一步在IDEA中选择 File-->NEW-->Project &#xff0c;选择 Spring Initializr &#xff0c;指定Maven坐标、包名、指定 JDK 版本 1.8 &#xff0c;然后点击Next 。如下图&#x…

一款比 K8S 更好用的编排工具——Nomod 单机部署

上下文 最近公司需要调研类似 EMCHub 这样支持算力共享的服务。第一直觉是使用 K8S 或 K3S&#xff0c;作为 CNCF 孵化的顶级项目&#xff0c;同时也是当前云原生生态使用最广的编排系统。但是在学习 EMC Hub 源码过程中&#xff0c;偶然发现它是基于 Nomad 做的集群管理。 相…

STM32收发HEX数据包

在实际应用中&#xff0c;STM32的串口通信都是以数据包格式进行收发&#xff0c;这个数据包一般都包含包头和包尾&#xff0c;表示一个数据包。源代码在文末给出 数据包格式&#xff1a; 固定长度&#xff0c;含包头包尾 可变包长&#xff0c;含包头包尾 问题1&#xff1a;当…

学点儿数据库_Day11_多表、等值连接、内连接、模糊查找

1 多表 学生表、班级表、课程表、班级课程表 关系型数据库&#xff1a; MySql、SqlServer、Oracle 相同的数据出现多次绝不是一件好事&#xff0c;这是关系数据库设计的基础。关系表的设计就是要把信息分解成多个表&#xff0c;一个数据一个表&#xff0c;各表通过某些共同的…

真机笔记(3) 真机需求讲解

目录 拓扑分析&#xff1a; 设计理念&#xff1a; 1. 生产区交换需求&#xff1a; 2. 生产区交换需求&#xff1a; 3. 服务器区交换需求&#xff1a; 4. 路由设计 5. 地址规划&#xff1a; 拓扑分析&#xff1a; 蓝色&#xff1a;网线 红色&#xff1a;多模光纤 黄色&am…

AI Agent(LLM Agent)入门解读

1. 什么是AI Agent&#xff1f; AI Agent可以理解为一个智能体&#xff0c;包括感知模块、规划决策模块和行动模块&#xff0c;类似于人类的五官、大脑和肢体。它能帮助人类处理复杂的任务&#xff0c;并能根据环境反馈进行学习和调整。 五官可以理解为感知模块&#xff0c;大…

React和Vue.js的有什么区别

在当今前端开发领域&#xff0c;React 和 Vue.js 作为两大热门的前端框架备受开发者关注。它们各自拥有独特的特点和优势&#xff0c;在实际项目中有着广泛的运用。本文将深入探讨 React 和 Vue.js 之间的区别&#xff0c;从组件化方式、数据绑定、模板语法以及生态系统和工具支…

全国草地资源类型分布图

草地出现在世界各地&#xff0c;约占全球陆地面积的24%&#xff0c;大多分布于大陆内部气候干燥、降水较少的地区&#xff0c;其中澳大利亚、俄罗斯、中国、美国和巴西等国面积较大。中国草地面积约占国土面积的40%&#xff0c;主要分布在内蒙古、东北、西北和青藏高原&#xf…

2024/03/27(C++·day3)

一、思维导图 二、完成下面类 代码 #include <cstring> #include <iostream>using namespace std;class myString { private:char *str; // 记录C风格的字符串int size; // 记录字符串的实际长度public:// 无参构造函数myString() : size(10){str new char[si…

力扣Lc23--- 290. 单词规律(java版)-2024年3月27日

1.题目描述 2.知识点 1&#xff09;思路 &#xff08;1&#xff09;s.split(" "); 是将字符串 s 按空格进行分割&#xff0c;得到一个单词列表。 &#xff08;2&#xff09;建立模式字符和单词之间的双向映射关系&#xff0c;我们可以使用两个哈希映射&#xff08;或…

Oracle数据库管理:从基础到高级应用【文末送书-45】

文章目录 入门篇&#xff1a;初识Oracle进阶篇&#xff1a;深入学习Oracle精通篇&#xff1a;掌握Oracle高级技术Oracle从入门到精通&#xff08;第5版&#xff09;&#xff08;软件开发视频大讲堂&#xff09;【文末送书-45】 在当今数字化时代&#xff0c;数据是企业成功的关…

数据结构之单链表的详细实现(图解)

前言 本次博客讲结合图例讲解单向不带头非循环链表 此后会讲解一些题目 1单链表的实现 1.1什么是单链表 我们先看数组&#xff0c;即顺序表的是什么样的&#xff0c;再看链表 1.2单链表的特点 实际中要实现的链表的结构非常多样&#xff0c;以下情况组合起来就有8种链表结…

【业界动态】Digital Twin-数字孪生

绝大多数的人对数字孪生是一个模糊的概念&#xff0c;数字孪生也被称为数字映射、数字镜像&#xff0c;他既是一种技术&#xff0c;也是一种生态。随着互联网的建设与发展&#xff0c;数字孪生在未来又会如何发展&#xff0c;虚拟与现实之间会产生怎样的星火&#xff1f; 上帝按…

【MATLAB源码-第170期】基于matlab的BP神经网络股票价格预测GUI界面附带详细文档说明。

操作环境&#xff1a; MATLAB 2022a 1、算法描述 基于BP神经网络的股票价格预测是一种利用人工神经网络中的反向传播&#xff08;Backpropagation&#xff0c;简称BP&#xff09;算法来预测股票市场价格变化的技术。这种方法通过模拟人脑的处理方式&#xff0c;尝试捕捉股票…

chrome 浏览器报错 This page will not function without javascript enabled

This page will not function without javascript enabled. Please enable javascript on your browser. 在访问公司spark history 页面时&#xff0c;发现页面加载不全&#xff0c;并提示如上报错&#xff0c;因此按照如下步骤&#xff0c;已解决问题。 在浏览器中启用 JavaS…

产品经理进阶:抖音电商的商业逻辑(抖店)

目录 内容简介 市场情况 作者简介 内容简介 最近看到很多人在讲如何开抖店、如何做无货源等等这些事情。 这个事本身没有什么问题&#xff0c;毕竟有人下场挖金子&#xff0c;就有人卖工具。 问题在于很多是边开店边传授知识&#xff0c;而抖店本身其实赚的是信息差的钱。…

Openstack创建和操作实例,实现与外部网络通信

一、熟悉OpenStack图形界面操作 1、了解Horizon项目 Horizon项目 各OpenStack服务的图形界面都是由Horizon提供的。Horizon提供基于Web的模块化用户界面。Horizon为云管理员提供一个整体的视图。Horizon为终端用户提供一个自主服务的门户。Horizon由云管理员进行管理与控制&a…