admin 管理员组

文章数量: 887021


2023年12月22日发(作者:this is为什么不能缩写)

人人都会用的VB游戏小程序代码

3. 球来回弹

在窗体上添加一shape空间,shape为circle,计时器空间inteval=10

通用

Dim bz

Private Sub Timer1_Timer()

If >= idth - Then bz = 1

If <= 0 Then bz = 0

If bz = 0 Then = + 10

If bz = 1 Then = - 10

End Sub

注意:bz的使用(bz为一临时标志,用于判断移动方向)

2. 六角星

Dim i%, j%, k%

For i = 1 To 10

If i < 4 Or i > 6 Then

Print Space(20 - i);

For j = 1 To i

Print "○";

Next j

Else

Print Space(6 + i);

For k = 14 - i To 1 Step -1

Print "○";

Next k

End If

Print

Next i

For i = 3 To 1 Step -1

Print Space(20 - i);

For j = 1 To i

Print "○";

Next j

Print

Next i

1. 空心三角形

Dim i%, j%

Print Space(20); "*"

For i = 2 To 9

Print Space(21 - i); "*"; Space(2 * i - 3); "*"

Next

Print Space(10);

For i = 1 To 10

Print Space(1); "*";

Next

扩展程序

Const n = 15

Dim a(1 To n) As Integer

Dim i%, j%, t%

Randomize

For i = 1 To n

a(i) = Int(100 * Rnd) '生成15个0~100的随机整数存入数组

Next

Print "排序前:"

For i = 1 To n

Print a(i);

Next

Print

For i = 1 To n - 1

For j = i + 1 To n

If a(j) < a(i) Then t = a(j): a(j) = a(i): a(i) = t

Next

Next

Print "排序后:"

For i = 1 To n

Print a(i);

Next

3. 球来回弹

在窗体上添加一shape空间,shape为circle,计时器空间inteval=10

通用

Dim bz

Private Sub Timer1_Timer()

If >= idth - Then bz = 1

If <= 0 Then bz = 0

If bz = 0 Then = + 10

If bz = 1 Then = - 10

End Sub

注意:bz的使用(bz为一临时标志,用于判断移动方向)

4. 从大到小再从小到大变化

在窗体添加一标签label1,autosize=true,caption="★",添加一计时器空间timer1,inteval=100

通用:

Dim bz

Private Sub Timer1_Timer()

If ze >= 72 Then bz = 1

If ze <= 8 Then bz = 0

If bz = 0 Then ze = ze + 2

If bz = 1 Then ze = ze - 2

End Sub

5. 在VB中用画圆

Dim x, y, i As Single

Cls

Scale (-15, 15)-(15, -15) '定义笛卡儿坐标系

For i = 0 To 6.28 Step 0.05

y = 10 * Sin(i)

x = 10 * Cos(i)

CurrentX = x

CurrentY = y

Print "*"

Next

6. 四周循环移动

创建一个窗体,在上面添加“开始”和“停止”两个按钮,添加一个计时器控件timer1

在窗体上添加一个shape控件,设置背景不透明,红色,调整大小

程序代码如下:

Option Explicit

Dim bz%

Private Sub Command1_Click() '开始按钮

Timer1 = True

End Sub

Private Sub Command2_Click() '停止按钮

Timer1 = False

End Sub

Private Sub Form_Load()

= 0

= 0

Timer1 = False

al = 10

End Sub

Private Sub Timer1_Timer()

If >= idth - And <= 0 Then

bz = 1

If >= eight - Then bz = 2

If <= 0 Then bz = 3

If <= 0 And <= 0 Then bz = 0

Select Case bz

Case 0

= + 10

Case 1

= + 10

Case 2

= - 10

Case 3

= - 10

End Select

End Sub


本文标签: 添加 移动 窗体 游戏 会用