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/

欢迎来我空间

题目一:

Private Sub Text1_Change()

Text2.Text = Text1.Text

End Sub

题目二:

Private Sub Command1_Click()

Text1.Text = "程序设计第一步:设计界面"

End Sub

Private Sub Command2_Click()

Text1.Text = "程序设计第二步:属性设置"

End Sub

Private Sub Command3_Click()

Text1.Text = "程序设计第三步:编写代码"

End Sub

题目三:

Private Sub Command1_Click()

Text1.PasswordChar = "*"

End Sub

题目四:

运消隐行结果:

23

23

23

hellonihao

hellonihao

hello 100

helloI

100nihao

Inihao

..........先写这么多 - - 先睡觉去了。。亮态。明儿再敬桥源说!

加一个WInsock1控件,两个文本框(txtMess、txtSend)和一个按钮,代码如下Private Sub Command1_Click()

Winsock1.SendData txtSend.Text '发送聊天内容

txtSend.Text = "" '聊天内正态容清空

End SubPrivate Sub Form_Load()

Dim my As String

Winsock1.Protocol = sckUDPProtocol '设置为UDP协义

Winsock1.LocalPort = 60 '随便设租塌置,不过两个要一样

Winsock1.RemotePort = 60

my = Winsock1.LocalIP '取得自己举型源的IP地址,是不要的

Winsock1.RemoteHost = my '这里应该是改为别人计算机的IP,由于自己是单机,所以就设置成自己的,自己给自己发信息,可以拿另一台主机试试End SubPrivate Sub Winsock1_DataArrival(ByVal bytesTotal As Long) '取到数据时发生

Dim Tmp As String

Winsock1.GetData Tmp, vbString '取得数据

Tmp = "对方IP地址:" + Winsock1.RemoteHostIP + "发送内容为-->" + Tmp

txtMess.Text = Tmp + Chr$(13) + Chr$(10) + txtMess.Text'换行输出聊天信息

End Sub语句超简单,我用了几小时才弄出。


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

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

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

发表评论

登录后才能评论

评论列表(0条)

保存