VB制作小游戏源代码

VB制作小游戏源代码,第1张

猜数字

建一个文本文档,输入以下代码,后缀改为.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

代码结束

http://hi.baidu.com/卓7358/

欢迎来我空间

' '本程序在 vb6 调试通过

' '在窗体上放置 3 个控件:Timer1、Text1、Label1,在属性窗口将 Label1 的 Index

属性设置亏祥顷为 0,其他控件及属性无需进行任何设置

Dim ctStr As String

Private Sub Form_Load()

Dim I As

Long, Y As Long, nStr As String

ctStr =

Trim(GetSetting("xUnTime", "xOpt", "xCap", ""))

If ctStr =

"" Then ctStr = "高考"'默认标题

Text1.Font.Bold

= True

Label1(0).AutoSize = True: Label1(0).Font.Bold =

True

Label1(0).BackStyle = 0

For I = 1

To 5

Load Label1(I): Label1(I).Visible =

True

Next

Me.BackColor =

&HFF8888

Label1(0).ForeColor =

&HFF0000

Label1(0).ToolTipText =

"单击可修改标题"

nStr =

Trim(GetSetting("xUnTime", "xOpt", "xTime", ""))

'nStr = "" '****调试代码

If nStr

= "" Then'默认时间:为计算机当前年份的6月7日

Y

= Format(Date, "yyyy")

I = DateDiff("s",

Now, Y &"-6-7 9:00:00")

If I <0

Then Y = Y + 1

nStr = Y &"-6-7

9:00:00"

End If

Text1.MaxLength = 20:

Text1.Text = nStr

Timer1.Enabled = True: Timer1.Interval =

1000

Me.WindowState = vbMaximized'最大化

End Sub

Private Sub

Form_Unload(Cancel As Integer)

SaveSetting "xUnTime",

"xOpt", "xCap", ctStr

SaveSetting "xUnTime", "xOpt",

"xTime", Text1.Text

End Sub

Private Sub Label1_Click(Index As

Integer)

'用户修改标题

If Index <>0

Then Exit Sub

Dim nStr As String

nStr

= Trim(InputBox("请输入倒计时事件的标题:"宴手, "倒计时 - 设置标题"销陆, ctStr))

If

Right(nStr, 3) = "倒计时" Then nStr = Trim(Left(nStr, Len(nStr) -

3))

If nStr = "" Then Exit Sub

ctStr =

nStr

Call Form_Resize

End Sub

Private Sub

Text1_Change()

Call Timer1_Timer

Call

Form_Resize

End Sub

Private Sub Form_Resize()

Dim

I As Long, H As Single, F As Single, W1 As Single

Dim S0 As

Single, S1 As Single, S2 As Single, L1 As Single, L2 As

Single

S0 = 0

S1

= 5 + LenB(StrConv(ctStr, vbFromUnicode))

If S1 <9 Then

S1 = 9

S2 = 0.5 + LenB(StrConv(Text1.Text,

vbFromUnicode))

If S2 <16.5 Then S2 =

16.5

F = Me.ScaleX(Me.ScaleWidth,

Me.ScaleMode, 3) / (S0 * 2 + S1 + S2)'根据窗口宽度设置字体大小

H =

Me.ScaleY(Me.ScaleHeight, Me.ScaleMode, 3) /

12'根据窗口高度设置字体大小

If F >H

Then F = H

F = F - 1

If F <3 Then

F = 3

Text1.Font.Size =

F

hh =

Text1.Font.Size

Set Me.Font =

Text1.Font

W1 = Me.TextWidth("A")

L1 =

(Me.ScaleWidth - W1 * (S1 + S2)) * 0.5

L2 = L1 + W1 *

S1

Text1.Width = W1 *

S2

Label1(0).Font.Size = F *

1.5

For I = 1 To

Label1.UBound

Label1(I).Font.Size =

F

Next

H = Label1(1).Height *

0.5

'标题

Me.Caption = ctStr &

"倒计时"

Label1(0).Caption = ctStr &

"倒计时"

Label1(0).Move (Me.ScaleWidth - Label1(0).Width) *

0.5, (Me.ScaleHeight - H * 12) *

0.4

'当前时间

Label1(1).Caption =

"当前时间"

Label1(1).Move L1, Label1(0).Top + H * 4.5:

Label1(2).Move L2,

Label1(1).Top

'高考时间

Label1(3).Caption =

ctStr &"时间"

Label1(3).Move L1, Label1(1).Top + H *

3

Text1.Appearance = 0

Text1.Move L2,

Label1(3).Top, Text1.Width,

Label1(3).Height

'剩余时间

Label1(4).Move L1,

Label1(3).Top + H * 3: Label1(4).Caption =

"剩余时间"

Label1(5).Move L2, Label1(4).Top:

Label1(5).ForeColor = 255

End Sub

Private Sub

Timer1_Timer()

Dim D As Long, H As Long, M As Long, S As

Long

On Error GoTo

cuo

Label1(2).Caption = Now

S =

DateDiff("s", Now, CDate(Text1.Text))

If S <1 Then

Label1(5).Caption = "时间到": Exit Sub

D = S \ 86400'3600 * 24

S = S Mod 86400: H

= S \ 3600

S = S Mod 3600: M = S \

60

S = S Mod 60

Label1(5).Caption = D

&"天 " &H &"时" &M &"分" &S &

"秒"

Exit Sub

cuo:

Label1(5).Caption

= "输入的时间错误"

End Sub


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12409575.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-25
下一篇 2023-05-25

发表评论

登录后才能评论

评论列表(0条)

保存