怎样用VB编写打字小游戏?
用一个标签label1放字母
添加一个计时器,设置时间为1000毫秒
再添加一个全局变量,用来表明字母有没有打对
再设一全局变量,用来计分
再添加一个命令按钮,用来开始游戏
dim flag%,score%
private sub form_load()
randomize
flag=1
score=0
timer1.enabled=false
label1.caption=""
end sub
private sub timer1_timer()
if flag=0 then
timer1.enabled=false
msgbox "游戏结束"
end
endif
flag=0
label1.caption=chr(int(rnd()*26)+97)
end sub
private sub command1_click()
timer1.enabled=true
end sub
private sub form_keypress(keyascii)
if keyascii=asc(label1.caption) then
flag=1
label1.caption=""
endif
end sub
下面是个程序!希望有用
'定义蛇的运动速度枚举值
Private Enum tpsSpeed
QUICKLY = 0
SLOWLY = 1
End Enum
'定义蛇的运动方向枚举值
Private Enum tpsDirection
D_UP = 38
D_DOWN = 40
D_LEFT = 37
D_RIGHT = 39
End Enum
'定义运动区域4个禁区的枚举值
Private Enum tpsForbiddenZone
FZ_TOP = 30
FZ_BOTTOM = 5330
FZ_LEFT = 30
FZ_RIGHT = 5730
End Enum
'定义蛇头及身体初始化数枚举值
Private Enum tpsSnake
SNAKEONE = 1
SNAKETWO = 2
SNAKETHREE = 3
SNAKEFOUR = 4
End Enum
'定义蛇宽度的常量
Private Const SNAKEWIDTH As Integer = 100
'该过程用于显示游戏信息
Private Sub Form_Load()
Me.Show
Me.lblTitle = "BS贪食蛇 — (版本 " & App.Major & "." & App.Minor & "." & App.Revision & ")"
Me.Caption = Me.lblTitle.Caption
frmSplash.Show 1
End Sub
'该过程用于使窗体恢复原始大小
Private Sub Form_Resize()
If Me.WindowState 1 Then
Me.Caption = ""
Me.Height = 6405 '窗体高度为 6405 缇
Me.Width = 8535 '窗体宽度为 8535 缇
Me.Left = (Screen.Width - Width) \ 2
Me.Top = (Screen.Height - Height) \ 2
End If
End Sub
'该过程用于重新开始开始游戏
Private Sub cmdGameStart_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Beep
msg = MsgBox("您确认要重新开始游戏吗?", 4 + 32, "BS贪食蛇")
If msg = 6 Then Call m_subGameInitialize
End Sub
'该过程用于暂停/运行游戏
Private Sub chkPause_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Me.chkPause.Caption = "暂停游戏(&P)" Then
Me.tmrSnakeMove.Enabled = False
Me.tmrGameTime.Enabled = False
Me.picMoveArea.Enabled = False
Me.lblPauseLab.Visible = True
Me.chkPause.Caption = "继续游戏(&R)"
Else
Me.tmrSnakeMove.Enabled = True
Me.tmrGameTime.Enabled = True
Me.picMoveArea.Enabled = True
Me.lblPauseLab.Visible = False
Me.chkPause.Caption = "暂停游戏(&P)"
End If
End Sub
'该过程用于显示游戏规则
Private Sub cmdGameRules_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Beep
MsgBox " BS贪食蛇:一个规则最简单的趣味游戏,您将用键盘" & Chr(13) & _
"上的4个方向键来控制蛇的运动方向。在运动过程中蛇" & Chr(13) & _
"不能后退,蛇的头部也不能接触到运动区域的边线以外" & Chr(13) & _
"和蛇自己的身体,否则就游戏失败。在吃掉随机出现的" & Chr(13) & _
"果子后,蛇的身体会变长,越长难度越大。祝您好运!!", 0 + 64, "游戏规则"
End Sub
'该过程用于显示游戏开发信息
Private Sub cmdAbout_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Beep
MsgBox "BS贪食蛇" & "(V-" & App.Major & "." & App.Minor & "版本)" & Chr(13) & Chr(13) & _
"" & Chr(13) & Chr(13) & _
"由PigheadPrince设计制作" & Chr(13) & _
"CopyRight(C)2002,BestSoft.TCG", 0, "关于本游戏"
End Sub
'该过程用于退出游戏
Private Sub cmdExit_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Beep
msg = MsgBox("您要退出本游戏吗?", 4 + 32, "BS贪食蛇")
Select Case msg
Case 6
End
Case 7
Me.chkWindowButton(2).Value = 0
Exit Sub
End Select
End Sub
'该过程用于拖动窗体_(点击图标)
Private Sub imgWindowTop_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
ReleaseCapture
SendMessage Me.hwnd, WM_SYSCOMMAND, SC_MOVE, 0
End Sub
'该共用过程用于处理窗体控制按钮组的相关操作_(锁定、最小化、退出)
Private Sub chkWindowButton_MouseUp(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button 1 Then Exit Sub
Select Case Index
Case 0 '锁定窗体
If Me.chkWindowButton(0).Value = 1 Then
Me.imgWindowTop.BorderStyle = 0
Me.imgWindowTop.Enabled = False
Else
Me.imgWindowTop.BorderStyle = 1
Me.imgWindowTop.Enabled = True
End If
Case 1 '最小化
Me.WindowState = 1
Me.chkWindowButton(1).Value = 0
Me.Caption = "BS贪食蛇 — (V-" & App.Major & "." & App.Minor & "版本)"
Case 2 '退出
Beep
msg = MsgBox("您要退出本游戏吗?", 4 + 32, "BS贪食蛇")
Select Case msg
Case 6
End
Case 7
Me.chkWindowButton(2).Value = 0
Exit Sub
End Select
End Select
End Sub
'该过程用于设置蛇运动速度的快慢
Private Sub hsbGameSpeed_Change()
Me.tmrSnakeMove.Interval = Me.hsbGameSpeed.Value
End Sub
'该过程用于通过键盘的方向键改变蛇的运动方向
Private Sub picMoveArea_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case g_intDirection
Case D_UP
If KeyCode = D_DOWN Then Exit Sub
Case D_DOWN
If KeyCode = D_UP Then Exit Sub
Case D_LEFT
If KeyCode = D_RIGHT Then Exit Sub
Case D_RIGHT
If KeyCode = D_LEFT Then Exit Sub
End Select
g_intDirection = KeyCode
End Sub
'该计时循环过程用于计算游戏耗费的秒数并显示
Private Sub tmrGameTime_Timer()
g_lngGameTime = g_lngGameTime + 1
Me.lblGameTime.Caption = g_lngGameTime & "秒"
End Sub
'该计时循环过程用于控制蛇的行动轨迹
Private Sub tmrSnakeMove_Timer()
Dim lngSnakeX As Long, lngSnakeY As Long, lngSnakeColor As Long
Dim lngPointX As Long, lngPointY As Long, lngPointColor As Long
Randomize
Me.picMoveArea.SetFocus
Me.picMoveArea.Cls
'确认蛇头的运动方向并获取新的位置
Select Case g_intDirection
Case D_UP '向上运动
g_udtSnake(SNAKEONE).Snake_CurX = g_udtSnake(SNAKEONE).Snake_OldX
g_udtSnake(SNAKEONE).Snake_CurY = g_udtSnake(SNAKEONE).Snake_OldY
g_udtSnake(SNAKEONE).Snake_CurY = g_udtSnake(SNAKEONE).Snake_CurY - SNAKEWIDTH
Case D_DOWN '向下运动
g_udtSnake(SNAKEONE).Snake_CurX = g_udtSnake(SNAKEONE).Snake_OldX
g_udtSnake(SNAKEONE).Snake_CurY = g_udtSnake(SNAKEONE).Snake_OldY
g_udtSnake(SNAKEONE).Snake_CurY = g_udtSnake(SNAKEONE).Snake_CurY + SNAKEWIDTH
Case D_LEFT '向左运动
g_udtSnake(SNAKEONE).Snake_CurX = g_udtSnake(SNAKEONE).Snake_OldX
g_udtSnake(SNAKEONE).Snake_CurX = g_udtSnake(SNAKEONE).Snake_CurX - SNAKEWIDTH
g_udtSnake(SNAKEONE).Snake_CurY = g_udtSnake(SNAKEONE).Snake_OldY
Case D_RIGHT '向右运动
g_udtSnake(SNAKEONE).Snake_CurX = g_udtSnake(SNAKEONE).Snake_OldX
g_udtSnake(SNAKEONE).Snake_CurX = g_udtSnake(SNAKEONE).Snake_CurX + SNAKEWIDTH
g_udtSnake(SNAKEONE).Snake_CurY = g_udtSnake(SNAKEONE).Snake_OldY
End Select
'根据新的位置绘制蛇头
lngSnakeX = g_udtSnake(SNAKEONE).Snake_CurX
lngSnakeY = g_udtSnake(SNAKEONE).Snake_CurY
lngSnakeColor = g_udtSnake(SNAKEONE).Snake_Color
Me.picMoveArea.PSet (lngSnakeX, lngSnakeY), lngSnakeColor
'移动蛇身体其他部分的位置
For i = 2 To g_intSnakeLength
g_udtSnake(i).Snake_CurX = g_udtSnake(i - 1).Snake_OldX
g_udtSnake(i).Snake_CurY = g_udtSnake(i - 1).Snake_OldY
lngSnakeX = g_udtSnake(i).Snake_CurX
lngSnakeY = g_udtSnake(i).Snake_CurY
lngSnakeColor = g_udtSnake(i).Snake_Color
Me.picMoveArea.PSet (lngSnakeX, lngSnakeY), lngSnakeColor
Next i
'更新蛇旧的坐标位置
For j = 1 To g_intSnakeLength
g_udtSnake(j).Snake_OldX = g_udtSnake(j).Snake_CurX
g_udtSnake(j).Snake_OldY = g_udtSnake(j).Snake_CurY
Next j
'判断蛇在移动中是否到了禁区而导致游戏失败
If m_funMoveForbiddenZone(g_udtSnake(SNAKEONE).Snake_CurX, g_udtSnake(SNAKEONE).Snake_CurY) Then
Beep
MsgBox "您的蛇移动到了禁区,游戏失败!", 0 + 16, "BS贪食蛇"
Me.tmrSnakeMove.Enabled = False
Me.tmrGameTime.Enabled = False
Me.picMoveArea.Visible = False
Exit Sub
End If
'判断蛇在移动中是否碰到了自己的身体而导致游戏失败
If m_funTouchSnakeBody(g_udtSnake(SNAKEONE).Snake_CurX, g_udtSnake(SNAKEONE).Snake_CurY) Then
Beep
MsgBox "您的蛇在移动中碰到了自己的身体,游戏失败!", 0 + 16, "BS贪食蛇"
Me.tmrSnakeMove.Enabled = False
Me.tmrGameTime.Enabled = False
Me.picMoveArea.Visible = False
Exit Sub
End If
'判断蛇是否吃到了果子
If m_funEatPoint(g_udtSnake(SNAKEONE).Snake_CurX, g_udtSnake(SNAKEONE).Snake_CurY) Then
'累加玩家的得分并刷新得分显示
g_intPlayerScore = g_intPlayerScore + 1
Me.lblYourScore.Caption = g_intPlayerScore & "分"
Call m_subAddSnake '加长蛇的身体
Call m_subGetPoint '获取下一个果子的位置和颜色
Else
'绘制果子
lngPointX = g_udtPoint.Point_X
lngPointY = g_udtPoint.Point_Y
lngPointColor = g_udtPoint.Point_Color
Me.picMoveArea.PSet (lngPointX, lngPointY), lngPointColor
End If
End Sub
'该私有子过程用于初始化游戏
Private Sub m_subGameInitialize()
Erase g_udtSnake '清空蛇的结构数组
g_intPlayerScore = 0 '清空玩家的得分
g_lngGameTime = 0 '清空游戏耗费的秒数
g_intDirection = D_DOWN '设定蛇的初始运动方向为下
g_intSnakeLength = 4 '设定蛇的初始长度
ReDim g_udtSnake(1 To g_intSnakeLength) '重新定义蛇的长度
'定义蛇头部的数据
With g_udtSnake(SNAKEONE)
.Snake_OldX = 530
.Snake_OldY = 530
.Snake_Color = vbBlack
End With
'定义蛇身第2节的数据
With g_udtSnake(SNAKETWO)
.Snake_OldX = 530
.Snake_OldY = 430
.Snake_Color = vbGreen
End With
'定义蛇身第3节的数据
With g_udtSnake(SNAKETHREE)
.Snake_OldX = 530
.Snake_OldY = 330
.Snake_Color = vbYellow
End With
'定义蛇身第4节的数据
With g_udtSnake(SNAKEFOUR)
.Snake_OldX = 530
.Snake_OldY = 230
.Snake_Color = vbRed
End With
Me.picMoveArea.Visible = True
Me.lblYourScore.Caption = g_intPlayerScore & "分"
Me.lblGameTime.Caption = g_lngGameTime & "秒"
Me.tmrSnakeMove.Interval = Me.hsbGameSpeed.Value
Me.tmrSnakeMove.Enabled = True
Me.tmrGameTime.Enabled = True
Call m_subGetPoint '获取第一个果子的位置和颜色
End Sub
'该私有子过程用于返回获取的果子的位置和颜色信息
Private Sub m_subGetPoint()
Dim lngRedValue As Long, lngGreenValue As Long, lngBlueValue As Long
Dim lngPointX As Long, lngPointY As Long, lngPointColor As Long
'随机获取果子的颜色
lngRedValue = Int((255 - 0 + 1) * Rnd + 0)
lngGreenValue = Int((255 - 0 + 1) * Rnd + 0)
lngBlueValue = Int((255 - 0 + 1) * Rnd + 0)
lngPointColor = RGB(lngRedValue, lngGreenValue, lngBlueValue)
'随机获取果子的位置
lngPointX = Int((FZ_LEFT - FZ_RIGHT + 1) * Rnd + FZ_RIGHT)
lngPointY = Int((FZ_TOP - FZ_BOTTOM + 1) * Rnd + FZ_BOTTOM)
Me.PSet (lngPointX, lngPointY), lngPointColor
'设置函数返回值
With g_udtPoint
.Point_X = lngPointX
.Point_Y = lngPointY
.Point_Color = lngPointColor
End With
End Sub
'该私有子过程用于加长蛇的身体
Private Sub m_subAddSnake()
Dim udtSnakeTemp() As Snake
Dim lngSnakeX As Long, lngSnakeY As Long, lngSnakeColor As Long
'备份蛇原先身体的数据并使蛇的身体加长
ReDim udtSnakeTemp(1 To g_intSnakeLength)
For k = 1 To g_intSnakeLength
With udtSnakeTemp(k)
.Snake_CurX = g_udtSnake(k).Snake_CurX
.Snake_CurY = g_udtSnake(k).Snake_CurY
.Snake_OldX = g_udtSnake(k).Snake_OldX
.Snake_OldY = g_udtSnake(k).Snake_OldY
.Snake_Color = g_udtSnake(k).Snake_Color
End With
Next k
g_intSnakeLength = g_intSnakeLength + 1
ReDim g_udtSnake(g_intSnakeLength)
'将备份蛇身体的数据返回到加长的蛇身数组中
For l = 1 To g_intSnakeLength - 1
With g_udtSnake(l)
.Snake_CurX = udtSnakeTemp(l).Snake_CurX
.Snake_CurY = udtSnakeTemp(l).Snake_CurY
.Snake_OldX = udtSnakeTemp(l).Snake_OldX
.Snake_OldY = udtSnakeTemp(l).Snake_OldY
.Snake_Color = udtSnakeTemp(l).Snake_Color
End With
Next l
'写入新加入的身体数据
Select Case g_intDirection
Case D_UP
With g_udtSnake(g_intSnakeLength)
.Snake_OldX = g_udtSnake(g_intSnakeLength - 1).Snake_CurX + SNAKEWIDTH
.Snake_OldY = g_udtSnake(g_intSnakeLength - 1).Snake_CurY
.Snake_Color = g_udtPoint.Point_Color
End With
Case D_DOWN
With g_udtSnake(g_intSnakeLength)
.Snake_OldX = g_udtSnake(g_intSnakeLength - 1).Snake_CurX - SNAKEWIDTH
.Snake_OldY = g_udtSnake(g_intSnakeLength - 1).Snake_CurY
.Snake_Color = g_udtPoint.Point_Color
End With
Case D_LEFT
With g_udtSnake(g_intSnakeLength)
.Snake_OldX = g_udtSnake(g_intSnakeLength - 1).Snake_CurX
.Snake_OldY = g_udtSnake(g_intSnakeLength - 1).Snake_CurY + SNAKEWIDTH
.Snake_Color = g_udtPoint.Point_Color
End With
Case D_RIGHT
With g_udtSnake(g_intSnakeLength)
.Snake_OldX = g_udtSnake(g_intSnakeLength - 1).Snake_CurX
.Snake_OldY = g_udtSnake(g_intSnakeLength - 1).Snake_CurY - SNAKEWIDTH
.Snake_Color = g_udtPoint.Point_Color
End With
End Select
lngSnakeX = g_udtSnake(g_intSnakeLength).Snake_CurX
lngSnakeY = g_udtSnake(g_intSnakeLength).Snake_CurY
lngSnakeColor = g_udtSnake(g_intSnakeLength).Snake_Color
Me.picMoveArea.PSet (lngSnakeX, lngSnakeY), lngSnakeColor
End Sub
'该自定义函数用于返回运动的蛇是否到达禁区而导致游戏失败
Private Function m_funMoveForbiddenZone(SnakeX As Long, SnakeY As Long) As Boolean
If (SnakeX >= FZ_LEFT And SnakeX = FZ_TOP And SnakeY <= FZ_BOTTOM) Then
m_funMoveForbiddenZone = False
Else
m_funMoveForbiddenZone = True
End If
End Function
'该自定义函数用于返回运动的蛇是否碰到自己的身体而导致游戏失败
Private Function m_funTouchSnakeBody(SnakeX As Long, SnakeY As Long) As Boolean
For m = 2 To g_intSnakeLength
If SnakeX = g_udtSnake(m).Snake_CurX And SnakeY = g_udtSnake(m).Snake_CurY Then
m_funTouchSnakeBody = True
Exit For
Else
m_funTouchSnakeBody = False
End If
Next m
End Function
'该自定义函数用于返回运动的蛇是否吃到了果子
Private Function m_funEatPoint(SnakeX As Long, SnakeY As Long) As Boolean
If Abs(SnakeX - g_udtPoint.Point_X) <= SNAKEWIDTH And Abs(SnakeY - g_udtPoint.Point_Y) <= SNAKEWIDTH Then
m_funEatPoint = True
Else
m_funEatPoint = False
End If
End Function
'(API函数调用过程_用以实现无标题窗体的拖动操作)---------------------------------
'RleaseCapture函数用以释放鼠标捕获
Public Declare Function ReleaseCapture Lib "user32" () As Long
'SendMessage函数用作向Windows发送移动窗体的消息
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As _
Long, ByVal wMsg As Long, ByVal wParam As Long, IParam As Any) As Long
Public Const WM_SYSCOMMAND = &H112 '声明向Windows发送消息的常量
Public Const SC_MOVE = &HF012 '声明控制移动窗体常量
'(游戏变量声明部分)-------------------------------------------------------------
'定义蛇的数据类型结构
Public Type Snake
Snake_OldX As Long
Snake_OldY As Long
Snake_CurX As Long
Snake_CurY As Long
Snake_Color As Long
End Type
'定义果子的数据类型结构
Public Type Point
Point_X As Long
Point_Y As Long
Point_Color As Long
End Type
'定义蛇的动态数组
Public g_udtSnake() As Snake
'定义果子
Public g_udtPoint As Point
'定义蛇的长度
Public g_intSnakeLength As Integer
'定义蛇的颜色
Public g_lngSnakeColor As Long
'定义蛇的运动方向
Public g_intDirection As Integer
'定义玩家的得分
Public g_intPlayerScore As Integer
'定义游戏耗费的秒数
Public g_lngGameTime As Long
VERSION 5.00
Begin VB.Form Form1
AutoRedraw = -1 'True
Caption = "打字游戏 小游戏而已"
ClientHeight = 4800
ClientLeft = 60
ClientTop = 750
ClientWidth = 5610
LinkTopic = "Form1"
ScaleHeight = 4800
ScaleWidth = 5610
StartUpPosition = 1 '所有者中心
Begin VB.Timer Timer1
Left = 0
Top = 3600
End
Begin VB.Label Label1
Caption = "Label1"
Height = 735
Index = 0
Left = 1320
TabIndex = 0
Top = 600
Width = 855
End
Begin VB.Menu MenuGame
Caption = "数量 (&N)"
Index = 0
End
Begin VB.Menu MenuGame
Caption = "速度 (&P)"
Index = 1
End
Begin VB.Menu MenuGame
Caption = "重置 (&R)"
Index = 2
End
Begin VB.Menu MenuGame
Caption = "开始 (&S)"
Index = 3
End
Begin VB.Menu MenuGame
Caption = "输赢 (&W)"
Index = 4
End
Begin VB.Menu MenuGame
Caption = "帮助 (&H)"
Index = 5
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim StartPause As Boolean
Dim n As Integer
Dim Speed As Integer
Dim Down As Integer, Hit As Integer
Dim DownLost As Integer, HitWin As Integer
Rem 自定义函数效率不高啊。。。
Private Sub Form_Initialize()
Speed = 10
DownLost = 100
HitWin = 100
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Randomize
For Index = 0 To n
If Chr(KeyCode) = Label1(Index).Caption Then
With Label1(Index)
.Top = Me.ScaleTop
.Caption = Chr(Int(Rnd * 26) + 65)
.Left = Rnd * (Me.ScaleWidth - Label1(Index).Width)
.ForeColor = RGB(Rnd * 255, Rnd * 255, Rnd * 255)
End With
Hit = Hit + 1
Me.Caption = "打字游戏 " & "掉落: " & Down & " 命中: " & Hit
End If
Next Index
End Sub
Private Sub Form_Load()
On Error Resume Next
Timer1.Interval = 10
Timer1.Enabled = False
Randomize
With Label1(0)
.Top = Me.ScaleTop
.Caption = Chr(Int(Rnd * 26) + 65)
.ForeColor = RGB(Rnd * 255, Rnd * 255, Rnd * 255)
.Left = Rnd * (Me.ScaleWidth - Label1(0).Width)
.FontSize = 30
.BackStyle = 0
End With
For Index = 1 To n
Load Label1(Index)
With Label1(Index)
.Visible = True
.FontSize = 30
.BackStyle = 0
.Top = Me.ScaleTop
.Caption = Chr(Int(Rnd * 26) + 65)
.Left = Rnd * (Me.ScaleWidth - Label1(Index).Width)
.ForeColor = RGB(Rnd * 255, Rnd * 255, Rnd * 255)
End With
Next Index
End Sub
Private Sub MenuGame_Click(Index As Integer)
On Error Resume Next
Select Case Index
Case 0
n = Int(InputBox("输入数量,建议输入1至5,如果输入0或者按取消,将会去缺省值1", "输入数量") - 1)
Form_Load
StartPause = False: MenuGame(3).Caption = "开始 (&S)"
Case 1
Speed = Int(Val(InputBox("输入速度参数,建议5-20,如果输入0或按取消,将会取缺省值0,就是不会移动", "输入速度参数")))
Timer1.Enabled = False
StartPause = False: MenuGame(3).Caption = "开始 (&S)"
Case 2
Hit = 0
Down = 0
Form_Load
StartPause = False: MenuGame(3).Caption = "开始 (&S)"
Case 3
StartPause = Not StartPause
If StartPause = True Then
MenuGame(3).Caption = "暂停 (&P)"
Timer1.Enabled = True
ElseIf StartPause = False Then
MenuGame(3).Caption = "开始 (&S)"
Timer1.Enabled = False
End If
Case 4
HitWin = Int(InputBox("输入数字,当命中数等于该数时即为胜利。", "输入数字"))
DownLost = Int(InputBox("输入数字,当掉落数等于该数时即为胜利。", "输入数字"))
Case 5
MsgBox "目前没有编辑帮助"
End Select
End Sub
Private Sub Timer1_Timer()
Randomize
For Index = 0 To n
Label1(Index).Top = Label1(Index).Top + Speed
If Label1(Index).Top >= Me.ScaleHeight Then
With Label1(Index)
.Top = Me.ScaleTop
.Caption = Chr(Int(Rnd * 26) + 65)
.Left = Rnd * (Me.ScaleWidth - Label1(Index).Width)
.ForeColor = RGB(Rnd * 255, Rnd * 255, Rnd * 255)
End With
Down = Down + 1
Me.Caption = "打字游戏 " & "掉落 " & Down & " 命中 " & Hit
End If
Next Index
If Down >= DownLost Then MsgBox "你输啦!", vbOKOnly, "You lost": End
If Hit >= HitWin Then MsgBox "你赢啦!", vbOKOnly, "You Win": End
End Sub
怎样用VB编写打字小游戏?
Me.Caption = "打字游戏 " & "掉落: " & Down & " 命中: " & Hit End If
各一个最简单的vb打字游戏代码
Case 1: ctStr = UCase(Str1) '大写字母 Case 2: ctStr = Str1 & UCase(Str1) '大小写混合字母 Case 3: ctStr = Str2: '特殊字符 Case 4: ctStr = Str3: '数字 Case 5: ctStr = Str1 & UCase(Str1) & Str2 & Str3 '大小写混合和特殊字符 Case 6: ctStr = ReadText(): '汉字 C...
用V B 编写一个打字游戏,就是26个英文字母重上面掉下来,一个一个的...
1个timer控件 1个commandbutton控件 把label1的index属性设置为0 把下面代码复制进去就可以了 --- Dim a() As Integer Dim k% '一次出现多少个字母 Dim s% '速度 Private Sub Command1_Click()Timer1.Enabled = True Command1.Enabled = False Form1.SetFocus End Sub Private Sub Form_KeyPr...
谁会用VB设计一个类似于金山打字小游戏的程序啊?
我最近做了一个打字软件,简单实用,现在我的女朋友正在用他练打字。‘是用VB做的,1700多行代码。最近正在考虑加点简单游戏进去
编写一个VB的英文打字练习程序 完整代码
For i = 1 To 30 Text2.Text = Text2.Text & Chr(Int(Rnd * 25 + 66))Next i Timer1.Enabled = True Timer1.Interval = 1000 m = 0 s = 1 End Sub Private Sub Command2_Click()Dim b As Integer For i = 1 To 30 If Mid(Text1.Text, i, 1) = Mid(Text2.Text, i,...
用vb怎么编一个简单的打字软件,
最简单的,做个文本框,所有功能都是文本框提供的啊,默认就行除了把文本框设置为 MultiLine 设置为 True
用vb做一个打字练习程序
textbox无法实现部分文本的颜色改变,要用RICHTEXTBOX,主要内容我已经写出来了,你看看 Private Sub Command1_Click()RichTextBox1.SetFocus End Sub Private Sub RichTextBox1_Change()Call duibi End Sub Private Sub duibi()a = Len(Text1.Text)b = Len(RichTextBox1.Text)If a > b Then...
VB 编制打字练习程序。首先单击“产生”,在文本框1随机产生一串大写字 ...
Private Sub Command1_Click()Dim a For i = 1 To 50 a = Int(Rnd * 26 + 65)s = s + UCase(Chr(a))Next Text1 = s End Sub Private Sub Command2_Click()Timer1.Enabled = False End Sub Private Sub Form_Load()Timer1.Interval = 1000 Text1 = "": Text2 = "": Text3...
怎样用VB做打字游戏???急求~~~
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...
我用vb编程编写一个打字程序,但是总是提示代码错误:缺少函数或变量,怎 ...
Sub zimu() Randomize Dim i As Integer Do i = Int(Rnd * 58 + 65) Loop While i > 90 And i < 97 zimuL.Caption = Chr(i) zimuL.Left = Rnd * (Me.ScaleWidth - zimuL.Width) zimuL.Top = 0End SubPrivate Sub Command1_Click() zimuL.Visible = True Ti...
廉湛力欣: 建立3个label控件1个timer控件1个commandbutton控件 把label1的index属性设置为0 把下面代码复制进去就可以了----------- Dim a() As Integer Dim k% '一次出现多少个字母 Dim s% '速度 Private Sub Command1_Click() Timer1.Enabled = True ...
虎林市19719595762: 如何编写vb拼音打字游戏 - ?
廉湛力欣: 加10个label1控件组,一个timer,操作:运行后,回车即可进行游戏,代码:Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer Dim m As Integer Private Sub Form_KeyPress(KeyAscii As Integer) If ...
虎林市19719595762: 怎么用VB精简版编写小游戏 - ?
廉湛力欣: Private Sub Command0_Click() Dim x As String x = "●" If Command2.Caption = x Then Command2.Caption = "○" Else Command2.Caption = "●" End If If Command4.Caption = x Then Command4.Caption = "○" Else Command4....
虎林市19719595762: 如何编写一套完整的VB小游戏程序 - ?
廉湛力欣: 楼上的朋友所说个人认为一些纰漏.第一,不要在设计时经常改动设计方案,否则工期会延误. 难道在编码和设计的时候经常改动? 在设计的时候改动与后期的改动谁会带来比较大的损失呢?况且软件危机是怎样产生的? 这是软件工程出现的原因...
虎林市19719595762: ■用vb编一个简单的游戏(代码)(要详细) - ?
廉湛力欣: '猜数字,这个简单了吧. Private Sub Form_Load()Randomizenum = Int(Rnd * 1000)str1 = "输入一个0到999间的整数"Donum1 = Val(InputBox(str1))If num1 > num Thenstr1 = "大了"ElseIf num1 < num Thenstr1 = "小了"ElseMsgBox "恭喜您!答对了."Exit DoEnd IfLoop End Sub
虎林市19719595762: 求大神!!如何用VB编写2048小游戏?把数字改成中文可以吗? - ?
廉湛力欣: If N = 0 Then Picture1.Line (L, T)-(L + 100, T + 100), RGB(200, 200, 200), BF Else Picture1.Line (L, T)-(L + 100, T + 100), BoxColor(N), BF tmpStr = Trim(Str(N)) W = TextWidth("0") / Screen.TwipsPerPixelX Picture1.CurrentX = L + (100 - ...
虎林市19719595762: 怎样用VB写一个打字的小程序?
廉湛力欣: 打字程序和金山打字通那样的就是要利用KEYPRESS事件 根据文字的位置和原本比对就可以了 至于判断哪个按键根据KEYCODE就可以判断
虎林市19719595762: 用vb怎么编一个简单的打字软件, - ?
廉湛力欣: 简单的打字代码,太难的俺不会做:窗体上创建一个text1,用于随机显示20 个字符 text2 用于打字输入 按钮1 :用于产生随机字符 label1 : 用于显示正确率 Option Explicit Private Sub Command1_Click() Dim i As Integer Dim rndNum As Integer ...
虎林市19719595762: VB或者Vb.net的模拟键盘(游戏)怎么做? - ?
廉湛力欣: 游戏里用keybd_event一般都是无效的,游戏防御强 如果阁下不想用按键精灵,非要用vb,那也行,在vb里用插件,也方便 我有插件,不管什么游戏都能做操作,自动点击,喊话这些,都不是事儿
虎林市19719595762: 如何用vb写一个这样的小游戏 - ?
廉湛力欣: 把代码复制到空窗体中按F5运行即可. Option Explicit Private WithEvents Timer1 As Timer Private WithEvents Label1 As Label Dim GFangXiang As Boolean Dim HWB As Single Dim She() As ShenTi Dim X As Long, Y As Long Dim ZhuangTai(...