分享
 
 
 

俄罗斯方块--vb6实现

王朝c#·作者佚名  2006-12-17
窄屏简体版  字體: |||超大  

俄罗斯方块--vb6实现

俄罗斯方块--vb6实现 ‘FuangKuai(FuangKuai.bas)

Option Explicit

Public Type FangKuai

Info(1 To 4, 1 To 4) As Integer '存储每个方块的信息,用4*4的格子表示方块

PicType As Integer '方块的图型,有效值1 到4

End Type

Public FKArray(1 To 6, 1 To 4) As FangKuai

Public ImageFKArray(12 * 19) As Integer '当前方块

Public BackImageFKArray(12 * 19) As Integer '备份方块

Public ImageBackFKArray(12 * 19) As Integer '背景图形

Public gFKTypeX '当前的方块类型

Public gFKTypeY

Public gFKTypePicType

Public getLine As Integer '存储玩家已经消掉的行数

Public TimeInterVal1 'timer 控件的interval 值

Public TimeInterVal2

Public TimerInterVal3

Public TimerInterVal4

Public FKChangeTypeNum '记录方块的变型方式,1同向变型,2随机变型

'显示方块

Public Sub VisibleFK()

Dim m

Dim n

Dim tem

For m = 1 To 19

For n = 1 To 12

tem = (m - 1) * 12 + n

If ImageFKArray(tem) = 1 Then

Form1!ImageFK(tem).Visible = True

End If

Next n

Next m

End Sub

Public Sub DisVisibleFK()

'开始游戏,visible=false所有方块

Dim m

Dim n

Dim tem

For m = 1 To 19

For n = 1 To 12

tem = (m - 1) * 12 + n

Form1!ImageFK(tem).Visible = False

Next n

Next m

VisibleBackImg

End Sub

'方块下移一行

Public Sub FKMoveNext()

Dim m

Dim n

Dim tem

DisVisibleFK

'清空备份数组

CleanFKBack

'复制数据到备份数组

For m = 1 To 19

If m = 19 Then

Exit For

End If

For n = 1 To 12

tem = (m - 1) * 12 + n

If ImageFKArray(tem) = 1 Then

BackImageFKArray(tem + 12) = 1

ImageFKArray(tem) = 0

End If

Next n

Next m

'清空当前数组

CleanFK

'拷备备份数组到当前数组

For m = 1 To 19

For n = 1 To 12

tem = (m - 1) * 12 + n

ImageFKArray(tem) = BackImageFKArray(tem)

Next n

Next m

VisibleFK

End Sub

'清除存放方块的东西

Public Sub CleanFK()

Dim m

Dim n

Dim tem

For m = 1 To 19

For n = 1 To 12

tem = (m - 1) * 12 + n

ImageFKArray(tem) = 0

Next n

Next m

End Sub

'清空备份的数组

Public Sub CleanFKBack()

Dim m

Dim n

Dim tem

For m = 1 To 19

For n = 1 To 12

tem = (m - 1) * 12 + n

BackImageFKArray(tem) = 0

Next n

Next m

End Sub

Public Sub FKMoveLeft()

Dim m

Dim n

Dim tem

Dim temX

Dim temY

'找着存放方块的左上角格子的坐标值

For m = 1 To 19

For n = 1 To 12

tem = (m - 1) * 12 + n

If ImageFKArray(tem) = 1 Then

temX = m

GoTo FindtemY

End If

Next n

Next m

FindtemY:

For m = 1 To 12

For n = 1 To 19

tem = (n - 1) * 12 + m

If ImageFKArray(tem) = 1 Then

temY = m

GoTo FindOK

End If

Next n

Next m

FindOK:

'方块左边不为空

If temY = 1 Then Exit Sub

For m = 1 To 19

For n = 1 To 11

tem = (m - 1) * 12 + n

If ImageBackFKArray(tem) = 1 And ImageFKArray(tem + 1) = 1 Then

Exit Sub

End If

Next n

Next m

'清除备份数组

CleanFKBack

'备份数组

For m = 1 To 19

For n = 1 To 12

tem = (m - 1) * 12 + n

If (n - 1) = 0 And ImageFKArray(tem) = 1 Then

Exit Sub

End If

If ImageFKArray(tem) = 1 Then

BackImageFKArray(tem - 1) = 1

End If

Next n

Next m

'清空当前数组

CleanFK

'拷备备份数组到当前数组

For m = 1 To 19

For n = 1 To 12

tem = (m - 1) * 12 + n

ImageFKArray(tem) = BackImageFKArray(tem)

Next n

Next m

DisVisibleFK

VisibleFK

End Sub

Public Sub FKMoveRight()

Dim m

Dim n

Dim tem

Dim temX

Dim temY

'得到方块右上角的坐标

For m = 1 To 19

For n = 1 To 12

tem = (m - 1) * 12 + n

If ImageFKArray(tem) = 1 Then

temX = m

End If

GoTo FindtemY

Next n

Next m

FindtemY:

For m = 1 To 12

For n = 1 To 19

tem = (n - 1) * 12 + m

If ImageFKArray(tem) = 1 Then

temY = m

End If

Next n

GoTo FindOK

Next m

FindOK:

'到最右了,不能移动了

If temY = 12 Then Exit Sub

'如果右边的格子不为空

For m = 1 To 19

For n = 2 To 12

tem = (m - 1) * 12 + n

If ImageBackFKArray(tem) = 1 And ImageFKArray(tem - 1) = 1 Then

Exit Sub

End If

Next n

Next m

'清除备份数组

CleanFKBack

'备份数组

For m = 1 To 19

For n = 1 To 12

tem = (m - 1) * 12 + n

If n = 12 And ImageFKArray(tem) = 1 Then

Exit Sub

End If

If ImageFKArray(tem) = 1 Then

BackImageFKArray(tem + 1) = 1

End If

Next n

Next m

'清空当前数组

CleanFK

'拷备备份数组到当前数组

For m = 1 To 19

For n = 1 To 12

tem = (m - 1) * 12 + n

ImageFKArray(tem) = BackImageFKArray(tem)

Next n

Next m

DisVisibleFK

VisibleFK

End Sub

'方块变型

Public Sub FKChangeType()

Dim m

Dim n

Dim tem

Dim getTypeY

Dim temX '存放当前方块左上角坐标X

Dim temY ''''''''''''''''''''''''Y

Dim TTT

Static aa As Long

aa = gFKTypeY '变量胡开始写了

If CanMoveNext = 0 Then

Exit Sub

End If

If FKChangeTypeNum = 1 Then

'正向变型

getTypeY = ((aa) Mod 4) + 1

Else

'不规则变型

getTypeY = ((Int(Rnd * 10)) Mod 4) + 1

'方块变型,得到一个不同于gFKTypeY的值就可

While getTypeY = gFKTypeY

getTypeY = ((Int(Rnd * 10)) Mod 4) + 1

Wend

End If

gFKTypeY = getTypeY

'清除备份数组

CleanFKBack

'找着存放方块的左上角格子的坐标值

For m = 1 To 19

For n = 1 To 12

tem = (m - 1) * 12 + n

If ImageFKArray(tem) = 1 Then

temX = m

GoTo FindtemY

End If

Next n

Next m

FindtemY:

For m = 1 To 12

For n = 1 To 19

tem = (n - 1) * 12 + m

If ImageFKArray(tem) = 1 Then

temY = m

GoTo FindOK

End If

Next n

Next m

FindOK:

'得到temx,temy

DisVisibleFK

CleanFK

'重显方块

For m = temX To temX + 3

For n = temY To temY + 3

Debug.Print gFKTypeX

Debug.Print gFKTypeY

If FKArray(gFKTypeX, gFKTypeY).Info(m - temX + 1, n - temY + 1) = 1 Then

tem = (m - 1) * 12 + n

ImageFKArray(tem) = 1

End If

Next n

Next m

VisibleFK

End Sub

'生成下一个方块

Public Sub GetNext()

Form1!Timer.Interval = TimerInterVal4

Randomize '在调用 Rnd 之前,先使用无参数的 Randomize 语句初始化随机数生成器,该生成器具有根据系统计时器得到的种子。

gFKTypeX = ((Int(Rnd * 10)) Mod 6) + 1 '当前的方块类型

gFKTypeY = ((Int(Rnd * 10)) Mod 4) + 1

gFKTypePicType = ((Int(Rnd * 10)) Mod 4) + 1

Dim FKTypeX

Dim FKTypeY

Dim FKtypePicType

Dim CanMovNext

Dim tem

Dim temX

Dim temY

Dim TTT '实现想不出来什么好名字了

FKTypeX = gFKTypeX

FKTypeY = gFKTypeY

FKtypePicType = gFKTypePicType

CleanFK

DisVisibleFK

For temX = 1 To 4

For temY = 1 To 4

If FKArray(FKTypeX, FKTypeY).Info(temX, temY) = 1 Then

TTT = (temX - 1) * 12 + temY + 4

Form1!ImageFK(TTT).Visible = True

ImageFKArray(TTT) = 1

End If

Next temY

Next temX

'调用显示方块的东西

VisibleFK

VisibleBackImg

If CanMoveNext = 0 Then

Dead

End If

End Sub

Public Sub DrawNextFK()

Dim m

Dim n

Dim tem

'备份当前的图型数组

For m = 1 To 12

For n = 1 To 19

tem = (n - 1) * 12 + m

If Form1!ImageFK(tem).Visible = True Then

ImageBackFKArray(tem) = 1

End If

Next n

Next m

CleanFK

GetNext

End Sub

'能下移吗? 返回1能下移,

'反回 2 到了最底行

Public Function CanMoveNext() As Integer

Dim m

Dim n

Dim tem

Dim test As Integer

Dim tem2

test = 0

'到最底行,不能下移

m = 19

For n = 1 To 12

tem = (m - 1) * 12 + n

If ImageFKArray(tem) = 1 Then

test = 0 '到了最低行

GoTo goback

Else

End If

Next n

'没到最底行,但是不下面有方块了,不能再下移了

For m = 1 To 18

For n = 1 To 12

tem2 = m * 12 + n

tem = (m - 1) * 12 + n

If ImageFKArray(tem) = 1 And ImageBackFKArray(tem2) = 1 Then

test = 0

GoTo goback

End If

Next n

Next m

test = 1

goback:

If test = 0 Then

CanMoveNext = 0

Else

CanMoveNext = 1

End If

End Function

'这里要干什么呢?

Public Sub VisibleBackImg()

Dim m

Dim n

Dim tem

For m = 1 To 19

For n = 1 To 12

tem = (m - 1) * 12 + n

If ImageBackFKArray(tem) = 1 Then

Form1!ImageFK(tem).Visible = True

End If

Next n

Next m

End Sub

Public Sub SaveFK()

Dim m

Dim n

Dim tem

For m = 1 To 19

For n = 1 To 12

tem = (m - 1) * 12 + n

If ImageFKArray(tem) = 1 Then

ImageBackFKArray(tem) = 1

End If

Next n

Next m

VisibleBackImg

End Sub

'能消掉一行吗?

'某行满了吗?

Public Sub DisLine()

Dim m

Dim n

Dim tem

Dim s

For m = 1 To 19

s = 0

For n = 1 To 12

tem = (m - 1) * 12 + n

If Form1!ImageFK(tem).Visible = True Then

s = s + 1

End If

Next n

Debug.Print 's=' & s

If s = 12 Then

getLine = getLine + 1 '得份行数加1

DisPlayLine (m) '调用函数消掉每m行

End If

Next m

VisibleBackImg

End Sub

Public Function DisPlayLine(ByVal numLine As Integer) As Integer

Dim m

Dim n

Dim tem

'取消显示满格的一行

For n = 1 To 12

tem = (numLine - 1) * 12 + n

ImageBackFKArray(tem) = 0

Next n

For m = 1 To 19

For n = 1 To 12

tem = (m - 1) * 12 + n

If ImageFKArray(tem) = 1 Then

ImageBackFKArray(tem) = 1

End If

Next n

Next m

'方块下移

Dim temArray(12 * 19) As Integer

For m = 1 To numLine - 1

For n = 1 To 12

tem = (m - 1) * 12 + n

Debug.Print tem + 12

temArray(tem + 12) = ImageBackFKArray(tem) '这里有点问题,如果第一行满格了怎么办?不过这种情况能出现吗?

'here is a bug?

'改成+12 OK?

Next '发现错误,应是numline-1

Next

For m = 1 To numLine - 1

For n = 1 To 12

tem = (m - 1) * 12 + n

ImageBackFKArray(tem) = temArray(tem)

Next

Next

DisVisibleFK

VisibleBackImg

End Function

'死了吗?

'这个函数现在没有用了

Public Function IsDead(ByVal numLine As Integer) As Integer

Dim test

If CanMoveNext = 0 And 1 Then

test = 1 '等于1,玩死了

End If

test = 0

IsDead = test

End Function

'游戏失败,玩家死掉了,处理这些东西吧

Public Sub Dead()

Form1!Timer.Enabled = False

MsgBox '游戏结束' & Chr(13) & '您的得分是' & getLine

Form1!lblStart.Visible = True

'do other things

Dim m

Dim n

Dim tem

For m = 1 To 19

For n = 1 To 12

tem = (m - 1) * 12 + n

ImageBackFKArray(tem) = 1

Next n

Next m

VisibleBackImg

CleanFK

CleanFKBack

End Sub

Public Sub MoveNextQuick()

Dim m

Dim n

Dim tem

Form1!Timer.Interval = 1

End Sub

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有