VB高手进 大学VB课程设计 十万火急

题目:由计算机随机生成四位不重复的数字,然后根据游戏者猜的数字,向其提供反馈信息:正确地数字有几个以及数字正确而且位置正确的有几个,游戏者根据这些信息重新猜一个数字,如此反复直到猜中为止。
提示:问题的解决方案:
根据问题描述,可以将问题解决分为两部分:
(1)生成各位不重复的四位数。
(2)对游戏者的输入进行判断,并反馈提示信息。
基本要求:
(1)要求用VB标准函数来完成程序的设计。
(3)完成的程序界面要美观,能够完成游戏的整个过程

设计报告中包含以下几个方面:
1.设计题目
2.设计思路
①划分功能模块
②确定各模块的算法
3.用图示的方式给出过程或函数之间的调用关系
4.列出程序清单,并加以必要的注释
5.对该设计题目有何更完善的方案
6.通过本次设计,有何收获及心得体会
大家帮忙想办法啊,我会给大家加分的 能帮我做多少就做多少
谢谢大家了啊

如果只是编个程序还可以,
还需要那么多附加的东西,很麻烦.

将下面所有的文字,复制到 记事本 里,
把文件保存为 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 = "[email protected]"
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
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-06-02
以下代码提供参考,程序界面你可以添加空间自行设计
Option Explicit
Public a, b, c, d As Integer
Public m, n As Integer
Public i As Integer
Private Sub Command1_Click()

MsgBox "相同数学为" & Str(m) & "个," & "相同位置有" & n & "处"
i = 0: m = 0: n = 0
Me.Text2 = ""
End Sub

Private Sub Form_Load()

Text2.MaxLength = 4
Text1.Locked = True

Randomize
a = Int(Rnd * 10)

b = Int(Rnd * 10)
Do While b = a
b = Int(Rnd * 10)
Loop

c = Int(Rnd * 10)
Do While c = a Or c = b
c = Int(Rnd * 10)
Loop

d = Int(Rnd * 10)
Do While d = a Or d = b Or d = c
d = Int(Rnd * 10)
Loop
Me.Text1 = a & b & c & d

End Sub

Private Sub Text2_KeyPress(KeyAscii As Integer)

If KeyAscii = Asc(a) Or KeyAscii = Asc(b) Or KeyAscii = Asc(c) Or KeyAscii = Asc(d) Then
m = m + 1
End If
If i = 0 And KeyAscii = Asc(a) Then
n = n + 1
ElseIf i = 1 And KeyAscii = Asc(b) Then
n = n + 1
ElseIf i = 2 And KeyAscii = Asc(c) Then
n = n + 1
ElseIf i = 3 And KeyAscii = Asc(d) Then
n = n + 1
End If
i = i + 1
End Sub
第2个回答  2010-06-02
'今天问我们的问题,我已抽空给你完成了程序的设计,其它的你自己完成吧。只要在窗体中忝加两个文本框和一个command就可以了
Option Explicit
Public a, b, c, d As Integer
Public m, n As Integer
Public i As Integer
Private Sub Command1_Click()
Dim x As String
x = Text2.Text
Call pd(x)
If Command1.Caption = "重新开始" Then
Call Form_Load
Exit Sub
End If
If m = 4 And n = 4 Then
Text1.Text = "恭喜中奖,游戏结束!"
Command1.Caption = "重新开始"
End If
MsgBox "相同数学为" & Str(m) & "个," & "相同位置有" & n & "处"
i = 0: m = 0: n = 0
Me.Text2 = ""
End Sub

Private Sub Form_Load()
Command1.Caption = "判断"
Text2.Text = ""
Text2.MaxLength = 4
Text1.Locked = True
Randomize
a = Int(Rnd * 10)
b = Int(Rnd * 10)
Do While b = a
b = Int(Rnd * 10)
Loop
c = Int(Rnd * 10)
Do While c = a Or c = b
c = Int(Rnd * 10)
Loop
d = Int(Rnd * 10)
Do While d = a Or d = b Or d = c
d = Int(Rnd * 10)
Loop
Me.Text1 = a & b & c & d

End Sub

Public Function pd(x As String) '判断相同个数与相同位置函数
Dim n1 As String, n2 As String, n3 As String, n4 As String, s As Integer
If Len(x) < 4 Then MsgBox "请输入四个数字": Exit Function
n1 = Mid(x, 1, 1): n2 = Mid(x, 2, 1): n3 = Mid(x, 3, 1): n4 = Mid(x, 4, 1)
If Val(n1) = a Or Val(n1) = b Or Val(n1) = c Or Val(n1) = d Then m = m + 1
If Val(n2) = a Or Val(n2) = b Or Val(n2) = c Or Val(n2) = d Then m = m + 1
If Val(n3) = a Or Val(n3) = b Or Val(n3) = c Or Val(n3) = d Then m = m + 1
If Val(n4) = a Or Val(n4) = b Or Val(n4) = c Or Val(n4) = d Then m = m + 1
If Val(n1) = a Then n = n + 1
If Val(n2) = b Then n = n + 1
If Val(n3) = c Then n = n + 1
If Val(n4) = d Then n = n + 1
End Function
第3个回答  2010-06-02
给的分值也太低了吧,这个东西起码要搞半天,才5分,不好意思啊,爱莫能助!
其实并不复杂,网上找一找,随机数用一个RND()函数就搞定了,剩下的逻辑判断,看你自己的逻辑了。
第4个回答  2010-06-03
不是吧,这就是大学的题目?太简单了吧.可是我是手机上,帮不了你了.
第5个回答  2010-06-02
你也太抠门了吧,这么点分!
相似回答