学习VB编程第42天,赛马游戏开发(知识点越来越巩固)

学习VB编程第42天,赛马游戏开发(知识点越来越巩固)

首页休闲益智闲置赛马更新时间:2024-04-28

嫌啰嗦的,直接从11分30秒开始看

今天学习了刘金玉老师零基础VB教程的第52期,学习的主要内容是赛马游戏开发。

1.思路:利用时钟控件,通过动态加载图片实现赛马的奔跑效果,通过随机增加frame控件左边的距离实现电脑赛马的移动,通过鼠标单击label控件,增加frame控件左边的距离实现参赛选手赛马的移动。

2.如图新建控件:

3.输入代码:

Dim pcIndex%

Dim plindex%

Private Sub Command1_Click()

Timer1.Enabled = True

Timer2.Enabled = True

Timer3.Enabled = True

Command1.Enabled = False

Frame1.Left = 0

Frame2.Left = 0

End Sub

Private Sub Form_Load()

End Sub

Private Sub Timer1_Timer()

pcIndex = pcIndex 1

If pcIndex > 15 Then pcIndex = 1

Image1.Picture = LoadPicture(App.Path & "/马的动态图片/ma" & pcIndex & ".gif")

Randomize

Frame1.Left = Frame1.Left Rnd * 100

End Sub

Private Sub Timer2_Timer()

plindex = plindex 1

If plindex > 15 Then plindex = 1

Image2.Picture = LoadPicture(App.Path & "/马的动态图片/ma" & pcIndex & ".gif")

End Sub

Private Sub Label1_Click()

Randomize

Frame2.Left = Frame2.Left Rnd * 500

End Sub

Private Sub Timer3_Timer()

If Frame1.Left Frame1.Width >= Line3.X1 Then

MsgBox "电脑玩家获胜", vbInformation, "通知"

Timer3.Enabled = False

Command1.Enabled = True

Exit Sub

End If

If Frame2.Left Frame2.Width >= Line3.X1 Then

MsgBox "参赛选手获胜", vbInformation, "通知"

Timer3.Enabled = False

Command1.Enabled = True

Exit Sub

End If

End Sub

4.运行效果详见视频,感谢朋友们的关注支持。有需要程序的朋友可以私信留下邮箱。

查看全文
大家还看了
也许喜欢
更多游戏

Copyright © 2024 妖气游戏网 www.17u1u.com All Rights Reserved