俄罗斯方块源VB代码.docx
- 文档编号:3714606
- 上传时间:2022-11-24
- 格式:DOCX
- 页数:15
- 大小:16.20KB
俄罗斯方块源VB代码.docx
《俄罗斯方块源VB代码.docx》由会员分享,可在线阅读,更多相关《俄罗斯方块源VB代码.docx(15页珍藏版)》请在冰豆网上搜索。
俄罗斯方块源VB代码
DimType_NowAsInteger'目前方块的类型
DimType_NextAsInteger'下个方块的类型
DimintRotateAsInteger'方块旋转的状态
DimfenAsInteger'定义分数
DimjiAsInteger'定义级别
FunctionGet_X_Value()
IfGetValue(1,2)Then'GetXValue
IfMaxX-MinX>=2Then
IfMaxX-CurX<=1Then
Adjust_Left=MaxX-2-1
Else
Adjust_Left=CurX-1
EndIf
Get_X_Value=True
ExitFunction
EndIf
EndIf
Get_X_Value=False
EndFunction
FunctionGetValue(nTypeAsInteger,nWidAsInteger)
GetCoor
OnErrorResumeNext
DimOKCount,EmptyCountAsInteger
MinX=Xs
(1).cX
MaxX=Xs
(1).cX
MinY=Xs
(1).cY
MaxY=Xs
(1).cY
Fori=2To4
IfMinX>Xs(i).cXThenMinX=Xs(i).cX
IfMaxX IfMinY>Xs(i).cYThenMinY=Xs(i).cY IfMaxY Next Fori=MinXToMaxX Forj=MinYToMaxY IfTotal(i,j)Then GetValue=False ExitFunction EndIf Next Next IfnType=0Then'GetYValue EmptyCount=0'GetMinY OKCount=0 Fori=MinY-1ToMinY-(nWid-1)Step-1 Forj=MinXToMaxX IfTotal(j,i)=FalseThenOKCount=OKCount+1 Next IfOKCount>=picPictureNow.WidthAndOKCount>=picPictureNow.HeightThen EmptyCount=EmptyCount+1 OKCount=0 Else ExitFor EndIf Next MinY=MinY-EmptyCount IfMinY<1ThenMinY=1 EmptyCount=0'GetMaxY OKCount=0 Fori=MaxY+1ToMaxY+nWid-1 Forj=MinXToMaxX IfTotal(j,i)=FalseThenOKCount=OKCount+1 Next IfOKCount>=picPictureNow.WidthAndOKCount>=picPictureNow.HeightThen EmptyCount=EmptyCount+1 OKCount=0 Else ExitFor EndIf Next MaxY=MaxY+EmptyCount IfMaxY>20ThenMaxY=20 Else'GetXValue EmptyCount=0'GetMinX OKCount=0 Fori=MinX-1ToMinX-(nWid-1)Step-1 Forj=MinYToMaxY IfTotal(i,j)=FalseThenOKCount=OKCount+1 Next IfOKCount>=picPictureNow.WidthAndOKCount>=picPictureNow.HeightThen EmptyCount=EmptyCount+1 OKCount=0 Else ExitFor EndIf Next MinX=MinX-EmptyCount IfMinX<1ThenMinX=1 EmptyCount=0'GetMaxX OKCount=0 Fori=MaxX+1ToMaxX+(nWid-1) Forj=MinYToMaxY IfTotal(i,j)=FalseThenOKCount=OKCount+1 Next IfOKCount>=picPictureNow.WidthAndOKCount>=picPictureNow.HeightThen EmptyCount=EmptyCount+1 OKCount=0 Else ExitFor EndIf Next MaxX=MaxX+EmptyCount IfMaxX>10ThenMaxX=10 EndIf GetValue=True EndFunction FunctionGet_Y_Value() IfGetValue(0,2)Then'GetYValue IfMaxY-MinY>=2Then IfMaxY-(picPictureNow.Top+1)<=1Then Adjust_Top=MinY-1 Else Adjust_Top=picPictureNow.Top EndIf Get_Y_Value=True ExitFunction EndIf EndIf Get_Y_Value=False EndFunction SubGlobal_Init() '全局初始化 picBackGround.Cls imgPictureNext.Picture=LoadPicture("") picPictureNow.Visible=False tmrDrop.Enabled=False EndSub SubInit() '每个方块的初始化过程 picPictureNow.Visible=False tmrDrop.Enabled=False Type_Now=Type_Next picPictureNow.Picture=imgPictureNext.Picture imgPictureNowBackup.Picture=picPictureNow.Picture Sel_Next intRotate=0 picPictureNow.Left=4 picPictureNow.Top=0 picPictureNow.Visible=True tmrDrop.Enabled=True EndSub SubGetCoor() '获取一个方块的4个点的坐标 Fori=1To4'init Xs(i).cX=0 Xs(i).cY=0 Xs(i).cZ=False Next CurX=picPictureNow.Left+1 SelectCaseType_Now Case1'长条 IfintRotateMod2=1Then Xs (1).cX=CurX Xs (1).cY=picPictureNow.Top+1 Xs (1).cZ=True Fori=2To4 Xs(i).cX=CurX+i-1 Xs(i).cY=picPictureNow.Top+1 Xs(i).cZ=True Next Else Xs (1).cX=CurX Xs (1).cY=picPictureNow.Top+4 Xs (1).cZ=True Fori=2To4 Xs(i).cX=CurX Xs(i).cY=picPictureNow.Top+i-1 Xs(i).cZ=False Next EndIf Case2'2字 IfintRotateMod2=1Then Xs (1).cX=CurX Xs (1).cY=picPictureNow.Top+3 Xs (1).cZ=True Xs (2).cX=CurX+1 Xs (2).cY=picPictureNow.Top+2 Xs (2).cZ=True Fori=3To4 Xs(i).cX=CurX+i-3 Xs(i).cY=picPictureNow.Top+5-i Xs(i).cZ=False Next Else Xs (1).cX=CurX Xs (1).cY=picPictureNow.Top+1 Xs (1).cZ=True Xs (2).cX=CurX+1 Xs (2).cY=picPictureNow.Top+2 Xs (2).cZ=True Xs(3).cX=CurX+2 Xs(3).cY=picPictureNow.Top+2 Xs(3).cZ=True Xs(4).cX=CurX+1 Xs(4).cY=picPictureNow.Top+1 Xs(4).cZ=False EndIf Case3'7字 SelectCaseintRotateMod4 Case0 Xs (1).cX=CurX Xs (1).cY=picPictureNow.Top+1 Xs (1).cZ=True Xs (2).cX=CurX+1 Xs (2).cY=picPictureNow.Top+3 Xs (2).cZ=True Fori=3To4 Xs(i).cX=CurX+1 Xs(i).cY=picPictureNow.Top+i-2 Xs(i).cZ=False Next Case1 Xs (1).cX=CurX Xs (1).cY=picPictureNow.Top+2 Xs (1).cZ=True Xs (2).cX=CurX+1 Xs (2).cY=picPictureNow.Top+2 Xs (2).cZ=True Xs(3).cX=CurX+2 Xs(3).cY=picPictureNow.Top+2 Xs(3).cZ=True Xs(4).cX=CurX+2 Xs(4).cY=picPictureNow.Top+1 Xs(4).cZ=False Case2 Xs (1).cX=CurX Xs (1).cY=picPictureNow.Top+3 Xs (1).cZ=True Xs (2).cX=CurX+1 Xs (2).cY=picPictureNow.Top+3 Xs (2).cZ=True Fori=3To4 Xs(i).cX=CurX Xs(i).cY=picPictureNow.Top+i-2 Xs(i).cZ=False Next Case3 Xs (1).cX=CurX Xs (1).cY=picPictureNow.Top+2 Xs (1).cZ=True Xs (2).cX=CurX+1 Xs (2).cY=picPictureNow.Top+1 Xs (2).cZ=True Xs(3).cX=CurX+2 Xs(3).cY=picPictureNow.Top+1 Xs(3).cZ=True Xs(4).cX=CurX Xs(4).cY=picPictureNow.Top+1 Xs(4).cZ=False EndSelect Case4'T字 SelectCaseintRotateMod4 Case0 Xs (1).cX=CurX Xs (1).cY=picPictureNow.Top+2 Xs (1).cZ=True Xs (2).cX=CurX+1 Xs (2).cY=picPictureNow.Top+2 Xs (2).cZ=True Xs(3).cX=CurX+2 Xs(3).cY=picPictureNow.Top+2 Xs(3).cZ=True Xs(4).cX=CurX+1 Xs(4).cY=picPictureNow.Top+1 Xs(4).cZ=False Case1 Xs (1).cX=CurX Xs (1).cY=picPictureNow.Top+3 Xs (1).cZ=True Xs (2).cX=CurX+1 Xs (2).cY=picPictureNow.Top+2 Xs (2).cZ=True Fori=3To4 Xs(i).cX=CurX Xs(i).cY=picPictureNow.Top+i-2 Xs(i).cZ=False Next Case2 Xs (1).cX=CurX Xs (1).cY=picPictureNow.Top+1 Xs (1).cZ=True Xs (2).cX=CurX+1 Xs (2).cY=picPictureNow.Top+2 Xs (2).cZ=True Xs(3).cX=CurX+2 Xs(3).cY=picPictureNow.Top+1 Xs(3).cZ=True Xs(4).cX=CurX+1 Xs(4).cY=picPictureNow.Top+1 Xs(4).cZ=False Case3 Xs (1).cX=CurX Xs (1).cY=picPictureNow.Top+2 Xs (1).cZ=True Xs (2).cX=CurX+1 Xs (2).cY=picPictureNow.Top+3 Xs (2).cZ=True Fori=3To4 Xs(i).cX=CurX+1 Xs(i).cY=picPictureNow.Top+i-2 Xs(i).cZ=False Next EndSelect Case5'反7字 SelectCaseintRotateMod4 Case0 Xs (1).cX=CurX Xs (1).cY=picPictureNow.Top+3 Xs (1).cZ=True Xs (2).cX=CurX+1 Xs (2).cY=picPictureNow.Top+1 Xs (2).cZ=True Fori=3To4 Xs(i).cX=CurX Xs(i).cY=picPictureNow.Top+i-2 Xs(i).cZ=False Next Case1 Xs (1).cX=CurX Xs (1).cY=picPictureNow.Top+1 Xs (1).cZ=True Xs (2).cX=CurX+1 Xs (2).cY=picPictureNow.Top+1 Xs (2).cZ=True Xs(3).cX=CurX+2 Xs(3).cY=picPictureNow.Top+2 Xs(3).cZ=True Xs(4).cX=CurX+2 Xs(4).cY=picPictureNow.Top+1 Xs(4).cZ=False Case2 Xs (1).cX=CurX Xs (1).cY=picPictureNow.Top+3 Xs (1).cZ=True Xs (2).cX=CurX+1 Xs (2).cY=picPictureNow.Top+3 Xs (2).cZ=True Fori=3To4 Xs(i).cX=CurX+1 Xs(i).cY=picPictureNow.Top+i-2 Xs(i).cZ=False Next Case3 Xs (1).cX=CurX Xs (1).cY=picPictureNow.Top+2 Xs (1).cZ=True Xs (2).cX=CurX+1 Xs (2).cY=picPictureNow.Top+2 Xs (2).cZ=True Xs(3).cX=CurX+2 Xs(3).cY=picPictureNow.Top+2 Xs(3).cZ=True Xs(4).cX=CurX Xs(4).cY=picPictureNow.Top+1 Xs(4).cZ=False EndSelect Case6'反2字 IfintRotateMod2=1Then Xs (1).cX=CurX Xs (1).cY=picPictureNow.Top+2 Xs (1).cZ=True Xs (2).cX=CurX+1 Xs (2).cY=picPictureNow.Top+3 Xs (2).cZ=True Fori=3To4 Xs(i).cX=CurX+i-3 Xs(i).cY=picPictureNow.Top+i-2 Xs(i).cZ=False Next Else Xs (1).cX=CurX Xs (1).cY=picPictureNow.Top+2 Xs (1).cZ=True Xs (2).cX=CurX+1 Xs (2).cY=picPictureNow.Top+2 Xs (2).cZ=True Xs(3).cX=CurX+2 Xs(3).cY=picPictureNow.Top+1 Xs(3).cZ=True Xs(4).cX=CurX+1 Xs(4).cY=picPictureNow.Top+1 Xs(4).cZ=False EndIf Case7'田字 Xs (1).cX=CurX Xs (1).cY=picPictureNow.Top+2 Xs (1).cZ=True Xs (2).cX=CurX+1 Xs (2).cY=picPictureNow.Top+2 Xs (2).cZ=True Fori=3To4 Xs(i).cX=CurX+i-3 Xs(i).cY=picPictureNow.Top+1 Xs(i).cZ=False Next EndSelect EndSub SubJudge_Full() '判断是否堆满 R_Value=picPictureNow.Top+1'MinY rx_value=picPictureNow.Top+picPictureNow.Height'MaxY Fori=rx_valueToR_ValueStep-1 IfTotal(1,i)AndTotal(2,i)AndTotal(3,i)AndTotal(4,i)AndTotal(5,i)And_ Total(6,i)AndTotal(7,i)AndTotal(8,i)AndTotal(9,i)AndTotal(10,i)Then '如果一行已经堆满,则将此行上面的图象全部向下移动一点 k=BitBlt(picBackGround.hDC,0,20,200,(i-1)*20,picBackGround.hDC,0,0,vbSrcCopy) SUCCESS=sndPlaySound(App.Path+"\45\eat.WAV",&H1) fen=fen+10 Text1.Text=fen SUCCESS=sndPlaySound(App.Path+"\45\11.WAV",&H1) Forj=iTo1Step-1 Fork=1To10 Total(k,j)=Total(k,j-1) Nextk Nextj i=i+1 EndIf Nexti Iffen>=1000Then tmrDrop.Interval=200 ji=3 ElseIffen>=50Then tmrDrop.Interval=100 ji=2 Else: tmrDrop.Interval=450 ji=1 EndIf Text2.Text=ji '如果目前方块的顶点位置<=0,则表示全部堆满 IfpicPictureNow.Top<=1Then SUCCESS=sndPlaySound(App.Path+"\45\Dead.WAV",&H1) Sele
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 俄罗斯方块 VB 代码