大学VB题目 请VB高手帮忙 万分感激

问题描述:

由计算机随机生成四位不重复的数字,然后根据游戏者猜的数字,向其提供反馈信息:正确地数字有几个以及数字正确而且位置正确的有几个,游戏者根据这些信息重新猜一个数字,如此反复直到猜中为止。

问题的解决方案:

根据问题描述,可以将问题解决分为两部分:

(1)生成各位不重复的四位数。

(2)对游戏者的输入进行判断,并反馈提示信息。

主要技术问题的描述:

(1)生成各位不重复的四位数:利用随机分步生成,并作简单的循环判断,使四位数字均不重复。

2)判断和反馈:利用循环判定并将结果输出。

基本要求:

(1)要求用VB标准函数来完成程序的设计。

(3)完成的程序界面要美观,能够完成游戏的整个过程。

创新要求:

在基本要求达到后,进行创新设计,如增加记分功能等。
最新回答
三天三夜,三斤作业

2024-06-26 07:25:02

这几天好多人问这道题啊.我已经帮其中一个人编好了.
下面的程序已经是一个比较完整的猜数字游戏.你看看吧

将下面所有的文字,复制到 记事本 里,
把文件保存为 csz.txt,再把扩展名改为 .frm
即最终文件全名为: csz.frm
然后,在装有VB6.0的机器上双击就可以了.

VERSION 5.00
Begin VB.Form Form1
BorderStyle = 1 'Fixed Single
Caption = "猜数字"
ClientHeight = 3480
ClientLeft = 45
ClientTop = 330
ClientWidth = 5970
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 3480
ScaleWidth = 5970
StartUpPosition = 2 '屏幕中心
Begin VB.CommandButton Command1
Caption = "帮 助"
Height = 375
Left = 4140
TabIndex = 12
Top = 2700
Width = 795
End
Begin VB.OptionButton opbDH
Caption = "显示代号"
Height = 255
Left = 4200
TabIndex = 6
Top = 2280
Width = 1455
End
Begin VB.OptionButton opbWZ
Caption = "显示文字"
Height = 255
Left = 4200
TabIndex = 5
Top = 1980
Value = -1 'True
Width = 1455
End
Begin VB.CommandButton cmdTC
Caption = "退 出"
Height = 375
Left = 4980
TabIndex = 8
Top = 2700
Width = 795
End
Begin VB.TextBox txtGC
BackColor = &H00C0C0C0&
Height = 2955
Left = 120
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 7
Top = 120
Width = 3735
End
Begin VB.CommandButton cmdCS
Caption = "猜数"
Height = 375
Left = 5040
TabIndex = 4
Top = 1440
Width = 675
End
Begin VB.CommandButton cmdNEW
Caption = "新 题 目"
Height = 375
Left = 4080
TabIndex = 1
Top = 120
Width = 1635
End
Begin VB.TextBox txtCS
Alignment = 2 'Center
BeginProperty Font
Name = "宋体"
Size = 18
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 435
Left = 4080
MaxLength = 4
TabIndex = 0
Top = 1380
Width = 855
End
Begin VB.CommandButton cmdCK
Caption = "查看"
Height = 375
Left = 5040
TabIndex = 3
Top = 780
Width = 675
End
Begin VB.Label lblCS
Alignment = 2 'Center
Caption = "0"
Height = 195
Left = 1200
TabIndex = 10
Top = 3180
Width = 495
End
Begin VB.Label Label2
Caption = "469876252@qq.COM"
Height = 195
Left = 4200
TabIndex = 9
Top = 3180
Width = 1515
End
Begin VB.Label lblSWS
Alignment = 2 'Center
BorderStyle = 1 'Fixed Single
BeginProperty Font
Name = "宋体"
Size = 18
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 435
Left = 4080
TabIndex = 2
Top = 720
Width = 855
End
Begin VB.Label Label1
Caption = "猜数次数:"
Height = 195
Left = 180
TabIndex = 11
Top = 3180
Width = 915
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim sws As String '储存 四位数 的字符串
Dim cs As Long '猜数的 次数

Private Sub cmdCK_Click()
lblSWS.Caption = sws
End Sub

Private Sub cmdCS_Click()
Dim ts As String, txt As String, txtW(4) As Integer
Dim n As Integer, zqs As Integer, zqsw As Integer
ts = "请输入四位不重复的数字"
txt = txtCS.Text
'判断是否是四个字符
If Len(txt) <> 4 Then MsgBox ts: Exit Sub
For n = 1 To 4
txtW(n) = Mid(txt, n, 1)
Next n
'判断是否是四个数字
If Asc(txtW(1)) < 48 Or Asc(txtW(1)) > 57 Or Asc(txtW(2)) < 48 Or Asc(txtW(2)) > 57 Or Asc(txtW(3)) < 48 Or Asc(txtW(3)) > 57 Or Asc(txtW(4)) < 48 Or Asc(txtW(4)) > 57 Then MsgBox ts: Exit Sub
'判断是否有重复数字
If txtW(1) = txtW(2) Or txtW(1) = txtW(3) Or txtW(1) = txtW(4) Or txtW(2) = txtW(3) Or txtW(2) = txtW(4) Or txtW(3) = txtW(4) Then MsgBox ts: Exit Sub
For n = 1 To 4
If InStr(sws, txtW(n)) <> 0 Then zqs = zqs + 1
If Mid(sws, n, 1) = txtW(n) Then zqsw = zqsw + 1
Next n
If cs = 0 Then txtGC.Text = ""
cs = cs + 1
lblCS.Caption = CStr(cs)
If opbWZ.Value Then
txtGC.Text = txtGC.Text + txt + vbTab + CStr(zqs) + "个数字正确,其中" + CStr(zqsw) + "个位置也正确" + vbCrLf
Else
txtGC.Text = txtGC.Text + txt + vbTab + CStr(zqs) + "A" + CStr(zqsw) + "B" + vbCrLf
End If
If zqsw = 4 Then lblSWS.Caption = sws: MsgBox "恭喜你!你部猜中!" + vbCrLf + "猜测次数:" + CStr(cs) + vbCrLf + vbCrLf + "开始新题目!": cmdNEW_Click
End Sub

Private Sub cmdNEW_Click()
'生成新的四位数,并设置各控件的显示值
Dim sz As String
Dim n As Integer, sjs As Integer
sz = "1234567890"
Randomize Timer
sws = ""
For n = 1 To 4
sjs = Int(Rnd * Len(sz)) + 1
sws = sws + Mid(sz, sjs, 1)
sz = Left(sz, sjs - 1) + Right(sz, Len(sz) - sjs)
Next n
cs = 0
lblSWS.Caption = "????"
txtGC.Text = ""
lblCS.Caption = CStr(cs)

End Sub

Private Sub cmdTC_Click()
Unload Me
End Sub

Private Sub Form_Load()
cmdNEW_Click
txtGC.Text = "查看 按钮,可以先查看数字" + vbCrLf + "用于在游戏过程中 做弊" + vbCrLf + "如果不需要这个功能,可以将按钮的" + vbCrLf + "Visible 属性设置为 False"
End Sub

Private Sub txtCS_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
cmdCS_Click
txtCS.SelStart = 0
txtCS.SelLength = 4
End If
End Sub
最初

2024-06-26 00:44:39

'加一个文本框,用于接收用户输入,一个按钮
Option Explicit
Dim myData As String

Private Sub Command1_Click()
Dim i As Integer, j As Integer, my2right As Integer, my1right As Integer
For i = 1 To 4
If Len(Text1.Text) <> Len(Replace(Text1.Text, Mid(Text1.Text, i, 1), "")) + 1 Then MsgBox "必须输入不重复的四位数": Exit Sub
Next
For i = 1 To 4
If Mid(myData, i, 1) = Mid(Text1.Text, i, 1) Then my2right = my2right + 1
Next
For i = 1 To 4
For j = 1 To 4
If i <> j And Mid(myData, i, 1) = Mid(Text1.Text, j, 1) Then my1right = my1right + 1
Next
Next
If my2right = 4 Then
MsgBox "恭喜你,猜对啦"
myData = my4g
Exit Sub
End If
Print my2right & "A" & my1right & "B"
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
Text1.SetFocus
End Sub
Private Sub Form_Click()
MsgBox "电脑出的数字是:" & myData
End Sub
Private Sub Form_Load()
Me.Caption = "A表示位置和数字都对,B表示数字对位置不对"
myData = my4g
Text1.MaxLength = 4
End Sub
Private Function my4g() As String '产生四位不重复的数字
Dim myStr As String, myTemp As String
Do
Randomize (Timer)
myTemp = Trim(Int(Rnd * 10))
If InStr(1, myStr, myTemp) = 0 Then myStr = myStr & myTemp
If Len(myStr) = 4 Then Exit Do
DoEvents
Loop
my4g = myStr
End Function
抵住引诱

2024-06-26 01:15:18

http://zhidao.baidu.com/question/157127226.html
一澜冬雪

2024-06-26 11:20:18

楼上高手啊,代码控件都有了
夜见树

2024-06-26 14:24:39

大学的题目越来越难了。。。建议自己查资料做 对于以后的帮助还是很大滴~