俄罗斯方块能否下降 vb版问题
源码如下,主要问题是downable这个函数写的好像有问题,代码上写的是判断四个方块的每一个的下一个的填充色是否为黑色,用的是and,但and用的话又不对,用or又出问题,高手看一下:Private n(3), m(3) As Integer
Private situation, situation2, linenum, t As Integer
Private Sub Form_Load()
downtimer.Enabled = False
timetimer.Enabled = False
start.Enabled = True
For i = 1 To 199
Load Shape(i)
Next i
For i = 0 To 199
Shape(i).Left = (i Mod 10) * Shape(0).Width + Shape(0).Left + 10 * (i Mod 10)
Shape(i).Top = (i \ 10) * Shape(0).Height + Shape(0).Top + 10 * (i / 10)
Shape(i).Visible = True
Next i
For i = 4 To 36 '创建预览区的方块
Load Shape1(i)
Next i
For i = 4 To 36 '在预览区排列方块
Shape1(i).Left = ((i Mod 10) - 3) * Shape1(3).Width + Shape1(3).Left + 10 * (i Mod 10)
Shape1(i).Top = (i \ 10) * Shape1(3).Height + Shape1(3).Top + 10 * (i / 10)
Shape1(i).Visible = True
Next i
Randomize
loadfangkuai
showfang 1
End Sub
Private Sub start_click()
downtimer.Enabled = True
timetimer.Enabled = True
start.Enabled = False
If guantxt.Text <> "" Then
downtimer.Interval = 1000 / Val(guantxt)
Else: downtimer.Interval = 1000
End If
For i = 0 To 3
n(i) = m(i)
Next i
situation = situation2
End Sub
Private Sub downtimer_Timer()
If guantxt.Text <> "" Then
downtimer.Interval = 1000 / Val(guantxt)
End If
hidefang 0
If downable = True Then
For i = 0 To 3
n(i) = n(i) + 10
Next i
showfang 0
Else
showfang 0
clearline
For i = 0 To 3 '引用预览区已经产生的方块
n(i) = m(i)
Next
showfang 0
situation = situation2
hidefang 1 '清空预览区
loadfangkuai '继续在预览区产生方块
'继续在预览区产生方块
showfang 1
End If
scoretxt.Text = linenum * 100
End Sub
Private Sub loadfangkuai() '定义随机产生一种方块的过程
End Select
End Sub
Private Sub hidefang(a As Integer)
Select Case a
Case 0
Shape(n(0)).FillColor = RGB(255, 255, 255)
Shape(n(1)).FillColor = RGB(255, 255, 255)
Shape(n(2)).FillColor = RGB(255, 255, 255)
Shape(n(3)).FillColor = RGB(255, 255, 255)
Case 1
Shape1(m(0)).FillColor = RGB(255, 255, 255)
Shape1(m(1)).FillColor = RGB(255, 255, 255)
Shape1(m(2)).FillColor = RGB(255, 255, 255)
Shape1(m(3)).FillColor = RGB(255, 255, 255)
End Select
End Sub
Private Sub showfang(a As Integer)
Select Case a
Case 0
Shape(n(0)).FillColor = RGB(0, 0, 0)
Shape(n(1)).FillColor = RGB(0, 0, 0)
Shape(n(2)).FillColor = RGB(0, 0, 0)
Shape(n(3)).FillColor = RGB(0, 0, 0)
Case 1
Shape1(m(0)).FillColor = RGB(0, 0, 0)
Shape1(m(1)).FillColor = RGB(0, 0, 0)
Shape1(m(2)).FillColor = RGB(0, 0, 0)
Shape1(m(3)).FillColor = RGB(0, 0, 0)
For i = 3 To 36
If Shape1(i).FillColor = RGB(255, 255, 255) Then
Shape1(i).Visible = False
End If
Next i
End Select
End Sub
Private Function downable() As Boolean '自定义函数,确定方块是否能下降
If n(0) < 190 And n(1) < 190 And n(2) < 190 And n(3) < 190 Then
If Shape(n(0) + 10).FillColor = RGB(225, 255, 255) Or _
Shape(n(1) + 10).FillColor = RGB(225, 255, 255) Or _
Shape(n(2) + 10).FillColor = RGB(225, 255, 255) Or _
Shape(n(3) + 10).FillColor = RGB(255, 255, 255) Then
downable = True
Else: downable = False
End If
Else: downable = False
End If
End Function
Private Function leftable() As Boolean '自定义函数,确定方块是否能左移
If n(0) Mod 10 <> 0 And n(1) Mod 10 <> 0 And n(2) Mod 10 <> 0 And n(3) Mod 10 <> 0 Then
If Shape(n(0) - 1).FillColor = RGB(255, 255, 255) And _
Shape(n(1) - 1).FillColor = RGB(255, 255, 255) And _
Shape(n(2) - 1).FillColor = RGB(255, 255, 255) And _
Shape(n(3) - 1).FillColor = RGB(255, 255, 255) Then
leftable = True
Else: leftable = False
End If
Else: leftable = False
End If
End Function
Private Function rightable() As Boolean '自定义函数,确定方块是否能右移
If n(0) Mod 10 <> 9 And n(1) Mod 10 <> 9 And n(2) Mod 10 <> 9 And n(3) Mod 10 <> 9 Then
If Shape(n(0) + 1).FillColor = RGB(255, 255, 255) And _
Shape(n(1) + 1).FillColor = RGB(255, 255, 255) And _
Shape(n(2) + 1).FillColor = RGB(255, 255, 255) And _
Shape(n(3) + 1).FillColor = RGB(255, 255, 255) Then
rightable = True
Else: rightable = False
End If
Else: rightable = False
End If
End Function
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) '键盘事件
hidefang 0
Select Case KeyCode
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Case vbKeyLeft '点击向左键
If leftable = True Then
For j = 0 To 3
n(j) = n(j) - 1
Next j
End If
showfang 0
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Case vbKeyDown '点击向下键
If downable = True Then
For j = 0 To 3
n(j) = n(j) + 10
Next j
End If
showfang 0
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Case vbKeyRight '点击向右键
If rightable = True Then
For j = 0 To 3
n(j) = n(j) + 1
Next j
End If
showfang 0
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Case vbKeyUp '点击旋转键(向上键)
showfang 0
zhuan
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Case Else
showfang 0
End Select
End Sub
Private Sub clearline()
For i = 19 To 0 Step -1
If Shape(i * 10 + 0).FillColor = RGB(0, 0, 0) And _
Shape(i * 10 + 1).FillColor = RGB(0, 0, 0) And _
Shape(i * 10 + 2).FillColor = RGB(0, 0, 0) And _
Shape(i * 10 + 3).FillColor = RGB(0, 0, 0) And _
Shape(i * 10 + 4).FillColor = RGB(0, 0, 0) And _
Shape(i * 10 + 5).FillColor = RGB(0, 0, 0) And _
Shape(i * 10 + 6).FillColor = RGB(0, 0, 0) And _
Shape(i * 10 + 7).FillColor = RGB(0, 0, 0) And _
Shape(i * 10 + 8).FillColor = RGB(0, 0, 0) And _
Shape(i * 10 + 9).FillColor = RGB(0, 0, 0) Then
For j = 0 To 9
Shape(i * 10 + j).FillColor = RGB(255, 255, 255)
Next j
linenum = linenum + 1
For k = i * 10 - 1 To 0 Step -1
If Shape(k).FillColor = RGB(0, 0, 0) And Shape(k + 10).FillColor = RGB(255, 255, 255) Then
Shape(k).FillColor = RGB(255, 255, 255)
Shape(k + 10).FillColor = RGB(0, 0, 0)
End If
Next k
clearline
End If
Next i
End Sub
Private Sub timetimer_Timer()
t = t + 1
timetxt = t
End Sub
大家主要看这段的代码:
Private Function downable() As Boolean '自定义函数,确定方块是否能下降
If n(0) < 190 And n(1) < 190 And n(2) < 190 And n(3) < 190 Then
If Shape(n(0) + 10).FillColor = RGB(225, 255, 255) and _
Shape(n(1) + 10).FillColor = RGB(225, 255, 255) and _
Shape(n(2) + 10).FillColor = RGB(225, 255, 255) and _
Shape(n(3) + 10).FillColor = RGB(255, 255, 255) Then
downable = True
Else: downable = False
End If
Else: downable = False
End If
End Function
这个软件运行后的界面:
--------------------编程问答-------------------- 应该先将当前物体擦除后再进行判断。
比如正方形的物体,上面一行将要落下的格子就是下面一行的当前位置,不是黑色。
其他动作的判断也一样要先擦除再判断。 --------------------编程问答-------------------- 单步调试和设断点调试是程序员必须掌握的技能之一。
--------------------编程问答-------------------- 你要注意当前小块下面那小块可能是你当前大块的一部分,此时即使其颜色不是背景色,当前大块也可能能下移。 --------------------编程问答-------------------- 应该将数据和界面分开来处理。所谓数据就是可以将游戏处理成小二维数组(块)在一个大的二维数组(背景)中的运动,进行计算处理后,将结果用界面(如各种控件或图形)显示出来。也可以说是算法与界面独立,这样只用将界面中的图片改变,就可以形成不同的视觉效果,实现“扶肤”功能,而算法完全不用修改。
俄罗斯方块VB源代码:http://download.csdn.net/source/1738728 --------------------编程问答-------------------- 楼主简单的用and或or判断都是不对滴。
你要按照不同的方块分情况判断。
补充:VB , VBA