VB猜数字游戏源代码?

2025-03-07 16:37:55
推荐回答(3个)
回答1:

Public Class Form1

    Dim b As Integer

    Dim js As Integer

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        If Me.Button1.Text = "开始" Then

            Dim a As Integer = MsgBox("游戏开始你准备好了吗", MsgBoxStyle.YesNo, "提示!")

            If a = 6 Then

                js = 1

                Me.Button1.Text = "确定"

                Me.Button2.Text = "返回"

                Me.Label2.Text = "我这里有1~10的正整数猜猜是多少"

                Me.TextBox1.Visible = True

                Randomize()

                b = Int(Rnd() * 9 + 1)

            Else

                Exit Sub

            End If

        Else

            If Me.TextBox1.Text.Trim = "" Or Asc(Me.TextBox1.Text) < 19 Or Asc(Me.TextBox1.Text) > 57 Then

                MsgBox("请输入数字")

                Exit Sub

            Else

                If js = 3 Then

                    MsgBox("对不起,你已经超过3次,请重新开始")

                    Me.Button1.Text = "开始"

                    Me.Button2.Text = "退出"

                    Me.TextBox1.Visible = False

                    Me.Label2.Text = ""

                Else

                    If Me.TextBox1.Text = b Then

                        Me.Label2.Text = "你真幸运猜对了"

                        Me.Button1.Visible = False

                        Me.Button2.Visible = False

                        Me.Button3.Visible = True

                    ElseIf TextBox1.Text > b Then

                        js += 1

                        Me.TextBox1.Text = ""

                        Me.Label2.Text = "你的数据太大了,请重新猜吧,注意只允许猜3次"

                    ElseIf TextBox1.Text < b Then

                        js += 1

                        Me.TextBox1.Text = ""

                        Me.Label2.Text = "你的数据太小了,请重新猜吧,注意只允许猜3次"

                    End If

                End If

            End If

        End If

    End Sub

  

  

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

        Me.Button1.Text = "开始"

        Me.Button2.Text = "返回"

        Me.TextBox1.Text = ""

        Me.Button3.Visible = False

        Me.TextBox1.Visible = False

        Me.Label2.Text = ""

        Me.Button1.Visible = True

        Me.Button2.Visible = True

    End Sub

End Class

刚才试了在VB里编译通过

如果你需要的话我传给你

回答2:

form1 

''''''''''''''''''''''''' 

Private Sub Command1_Click() 

a = MsgBox("游戏开始你准备好了吗", vbYesNo + 32) 

If a = 7 Then 

MsgBox "那你好好准备吧!" 

ElseIf a = 6 Then 

Load Form2 

Form1.Hide 

Form2.Show 

Unload Form1 

End If 

End Sub 

Private Sub Command2_Click() 

End 

End Sub 

Private Sub Form_Load() 

Label1.Caption = "欢迎进入猜字游戏" 

End Sub 

''''''''''''''''''''''''' 

form2 

''''''''''''''''''''''''' 

Dim bian As Integer: Dim jicuo As Integer 

Private Sub Command1_Click() 

If jicuo >= 3 Then 

MsgBox "你已经错了三次了,返回重来吧!" 

Else 

If Text1 = bian Then 

MsgBox "你真幸运猜对了" 

Else 

If Text1 > bian Then 

MsgBox "你猜大了,请重新猜吧!" 

ElseIf Text1 < bian Then 

MsgBox "你猜小了,请重新猜吧!" 

End If 

jicuo = jicuo + 1 

End If 

End If 

End Sub 

Private Sub Command2_Click() 

Unload Me 

Load Me 

End Sub 

Private Sub Form_Load() 

Label1.Caption = "我这里有1~10的正整数,猜猜是多少!" 

Randomize 

bian = Int(Rnd * 10 + 1) 

End Sub 

'''''''''''''''''''''''''

回答3:

dgfdgds