vb中文文字游戏源码_vb游戏代码大全

hacker|
145

文章目录:

急求用vb做打字游戏的代码~好的追加分~~

'给你写个容易理解的吧,在窗体上画两个TextBox,分别是Text1和Text2。

private sub Form_Load()

randomize timer '重新设置随机因子,使每次运行程序都能获得不同的字符序列

text2.tabindex=0 '窗体显示后,光标定位在text2

Text2_KeyPress 0 '模拟调用一次text2的键盘操作,其内部程序会使text1刷新

end sub

private sub Text2_KeyPress(KeyAscii as integer) 'text2键盘操作产生的事件

dim i as long

if len(text1.text)=len(text2.text) then 'text2已完成输入(或首次使用刷新)

keyascii=0 '屏蔽当前按键

text1.text=vbnullstring '清空Text1内容

text2.text=vbnullstring '清空Text2内容

for i=1 to 20 '随机生成20个字符排列

text1.text=text1.text chr$(int(rnd()*26)+asc("a")) '产生一个a~z的字符,追加到text1的尾部

next i

else

if keyasciiasc(vba.mid$(text1.text,len(text2.text)+1,1)) then keyascii=0:beep '字符输入错误,提示beep声音警报并取消当前键盘操作。

end if

end sub

'你还可以在这个基础上美化界面、增加判分、计时等功能。

VB制作小游戏源代码

猜数字

建一个文本文档,输入以下代码,后缀改为.frm用vb打开就可以了

以下是程序源码:

VERSION 5.00

Begin VB.Form Form1

BorderStyle = 3 'Fixed Dialog

Caption = "猜数游戏"

ClientHeight = 3900

ClientLeft = 45

ClientTop = 435

ClientWidth = 4680

LinkTopic = "Form1"

MaxButton = 0 'False

MinButton = 0 'False

ScaleHeight = 3900

ScaleWidth = 4680

ShowInTaskbar = 0 'False

StartUpPosition = 3 '窗口缺省

Begin VB.CommandButton Command2

Caption = "重新开始"

Height = 615

Left = 2640

TabIndex = 2

Top = 2760

Width = 1095

End

Begin VB.CommandButton Command1

Caption = "确定"

Height = 615

Left = 840

TabIndex = 1

Top = 2760

Width = 1095

End

Begin VB.TextBox Text1

Height = 375

Left = 1200

TabIndex = 0

Top = 2040

Width = 2055

End

Begin VB.Label Label9

Caption = "戏"

BeginProperty Font

Name = "宋体"

Size = 24

Charset = 134

Weight = 400

Underline = 0 'False

Italic = 0 'False

Strikethrough = 0 'False

EndProperty

ForeColor = H000080FF

Height = 615

Left = 3720

TabIndex = 11

Top = 240

Width = 615

End

Begin VB.Label Label8

Caption = "游"

BeginProperty Font

Name = "宋体"

Size = 24

Charset = 134

Weight = 400

Underline = 0 'False

Italic = 0 'False

Strikethrough = 0 'False

EndProperty

ForeColor = H00808080

Height = 615

Left = 3240

TabIndex = 10

Top = 240

Width = 615

End

Begin VB.Label Label7

Caption = "数"

BeginProperty Font

Name = "宋体"

Size = 24

Charset = 134

Weight = 400

Underline = 0 'False

Italic = 0 'False

Strikethrough = 0 'False

EndProperty

ForeColor = H0000FFFF

Height = 495

Left = 2760

TabIndex = 9

Top = 240

Width = 615

End

Begin VB.Label Label6

Caption = "猜"

BeginProperty Font

Name = "宋体"

Size = 24

Charset = 134

Weight = 400

Underline = 0 'False

Italic = 0 'False

Strikethrough = 0 'False

EndProperty

ForeColor = H00FF00FF

Height = 495

Left = 2280

TabIndex = 8

Top = 240

Width = 735

End

Begin VB.Label Label5

Caption = "入"

BeginProperty Font

Name = "宋体"

Size = 24

Charset = 134

Weight = 400

Underline = 0 'False

Italic = 0 'False

Strikethrough = 0 'False

EndProperty

ForeColor = H00FF0000

Height = 615

Left = 1800

TabIndex = 7

Top = 240

Width = 855

End

Begin VB.Label Label4

Caption = "进"

BeginProperty Font

Name = "宋体"

Size = 24

Charset = 134

Weight = 400

Underline = 0 'False

Italic = 0 'False

Strikethrough = 0 'False

EndProperty

ForeColor = H0000FF00

Height = 735

Left = 1320

TabIndex = 6

Top = 240

Width = 735

End

Begin VB.Label Label3

Caption = "迎"

BeginProperty Font

Name = "宋体"

Size = 24

Charset = 134

Weight = 400

Underline = 0 'False

Italic = 0 'False

Strikethrough = 0 'False

EndProperty

ForeColor = H00FFFF00

Height = 735

Left = 840

TabIndex = 5

Top = 240

Width = 735

End

Begin VB.Label Label2

Caption = "欢"

BeginProperty Font

Name = "宋体"

Size = 24

Charset = 134

Weight = 400

Underline = 0 'False

Italic = 0 'False

Strikethrough = 0 'False

EndProperty

ForeColor = H000000FF

Height = 615

Left = 360

TabIndex = 4

Top = 240

Width = 495

End

Begin VB.Label Label1

Caption = "我这儿有1~10的整数,你猜猜看他是多少......"

Height = 375

Left = 480

TabIndex = 3

Top = 1320

Width = 3855

End

End

Attribute VB_Name = "Form1"

Attribute VB_GlobalNameSpace = False

Attribute VB_Creatable = False

Attribute VB_PredeclaredId = True

Attribute VB_Exposed = False

Dim x As Integer, y As Integer, z As Integer

Dim cishu As Integer

Private Sub Command1_Click()

If cishu = 3 Then MsgBox "已经猜3次了,这个数是" x: Exit Sub

y = Val(Text1.Text)

If Text1.Text = "" Or Not IsNumeric(Text1.Text) Then

MsgBox "输入有误!请重新输入数字", 48

Text1.Text = ""

Text1.SetFocus

Exit Sub

End If

cishu = cishu + 1

Select Case x - y

Case Is 0

z = MsgBox("你猜数大了,请重猜。注意:你只有三次机会", 48 + 1)

Text1.Text = ""

Text1.SetFocus

Case Is 0

z = MsgBox("你猜数小了,请重猜。注意:你只有三次机会", 48 + 1)

Text1.Text = ""

Text1.SetFocus

Case Else

z = MsgBox("恭喜你猜中了!", 1)

End Select

End Sub

Private Sub Command2_Click()

cishu = 0

Randomize Timer

x = Int((Rnd * 10) + 1)

End Sub

Private Sub Form_Load()

cishu = 0

Randomize Timer

x = Int((Rnd * 10) + 1)

End Sub

代码结束

卓7358/

欢迎来我空间

用VB做打字游戏~代码~急求~~~~~~~~

Dim t As Integer

Dim s(1 To 5, 1 To 5) As String '用二维数组s()来存放打字数据

Dim n As Integer

Dim r As Integer

Private Sub Command1_Click()

If t = 0 Then

MsgBox "请先选择好打字选项", vbCritical + vbOKOnly + vbDefaultButton1, "提示"

Else

Label1.Caption = ""

Command1.Enabled = False

If t = 1 Then

Call producenumsigh

For i = 1 To 5

For j = 1 To 5

Label1.Caption = Label1.Caption + s(i, j)

Next j

Next i

ElseIf t = 2 Then

Call produceu

For i = 1 To 5

For j = 1 To 5

Label1.Caption = Label1.Caption + s(i, j)

Next j

Next i

ElseIf t = 3 Then

Call producel

For i = 1 To 5

For j = 1 To 5

Label1.Caption = Label1.Caption + s(i, j)

Next j

Next i

ElseIf t = 4 Then

Call producem

For i = 1 To 5

For j = 1 To 5

Label1.Caption = Label1.Caption + s(i, j)

Next j

Next i

ElseIf t = 5 Then

Call producemix

For i = 1 To 5

For j = 1 To 5

Label1.Caption = Label1.Caption + s(i, j)

Next j

Next i

End If

Timer1.Enabled = True

End If

'以上是根据用户选的打字选项分别调用对应的过程来产生打字数据

Text1.SetFocus

End Sub

Private Sub Command2_Click()

End

End Sub

Private Sub Form_Load()

Timer1.Interval = 1000

Timer1.Enabled = False

Label1.Caption = "欢迎使用打字练习程序"

End Sub

Private Sub l_Click()

t = 3

End Sub

Private Sub m_Click()

t = 4

End Sub

Private Sub mix_Click()

t = 5

End Sub

Private Sub numsigh_Click()

t = 1

End Sub

Private Sub Text1_Change()

If Len(Text1.Text) = 25 Then

Timer1.Enabled = False

For i = 1 To 25

If Mid(Text1.Text, i, 1) = Mid(Label1.Caption, i, 1) Then r = r + 1

Next

MsgBox "您的输入速度是:" Int(25 / n) "字符/秒" vbCrLf "您的正确率为:" 4 * r "%", vbInformation + vbOKOnly + vbDefaultButton1, "打字统计"

t = 0

Text1.Text = ""

Label1.Caption = ""

Command1.Enabled = True

Label1.Caption = "选择打字选项,按开始重新测试"

End If

End Sub

Private Sub Timer1_Timer()

n = n + 1 '统计打字的时间

End Sub

Private Sub u_Click()

t = 2

End Sub

Private Sub producenumsigh() '产生随机的数字字符并存放在数组s()中

Dim a%, b%, c%, d%, e%

For i = 1 To 5

Randomize

a = Int(Rnd * 15) + 33

b = Int(Rnd * 6) + 58 '根据键盘上的数字字符的Ascii码值,以下过程同

c = Int(Rnd * 5) + 91

d = Int(Rnd * 3) + 123

e = Int(Rnd * 9) + 48

s(i, 1) = Chr(a)

s(i, 2) = Chr(b)

s(i, 3) = Chr(c)

s(i, 4) = Chr(d)

s(i, 5) = Chr(e)

Next

End Sub

Private Sub produceu() Randomize

For i = 1 To 5

For j = 1 To 5

s(i, j) = Chr(Int(Rnd * 25) + 65)

Next j

Next i

End Sub

Private Sub producel()

For i = 1 To 5

For j = 1 To 5

Randomize

s(i, j) = Chr(Int(Rnd * 25) + 97)

Next j

Next i

End Sub

Private Sub producem() '产生随机的大小写字母并存放在数组s()中

Dim a%, b%

For i = 1 To 5

Randomize

a = Int(Rnd * 25) + 65

b = Int(Rnd * 25) + 97

s(i, 1) = Chr(a)

s(i, 2) = Chr(b)

s(i, 3) = Chr(a)

s(i, 4) = Chr(b)

s(i, 5) = Chr(a)

Next i

End Sub

Private Sub producemix() '产生随机的数字、字符及大小写字母并存放在数组s()中

For i = 1 To 5

For j = 1 To 5

Randomize

s(i, j) = Chr(Int(Rnd * 93) + 33)

Next j

Next i

End Sub

发你邮箱了

2条大神的评论

  • avatar
    访客 2022-07-03 上午 09:35:28

    Top = 2760 Width = 1095 End Begin VB.CommandButton Command1 Caption =

  • avatar
    访客 2022-07-03 上午 10:20:24

    Click() If t = 0 Then MsgBox "请先选择好打字选项", vbCritical + vbOKOnly + vbDefaultButton1, "提示" Else Label1.Caption = "" Command1.En

发表评论