首页
网站首页
公司简介
资讯中心
推荐内容
返回顶部
canvas的贪吃蛇,这不是159行的俄罗斯方块么
发布时间:2020-02-15 03:56
浏览次数:
PublicClassForm1PrivateShowBitMapAsNewBitmap(20,20),BackBitMapAsNewBitmap(20,20),BlockTypeAsInteger,BlockStateAsInteger,NextTypeAsInteger=3,Blocks(,)AsInteger'0隐藏,1显示,2静止PrivateDrawRectangleAsRectangle=NewRectangle(2,2,15,25),DrawLocationAsPoint=NewPoint(5,0),Score(1)AsLongPrivateWithEventsMyTimerAsNewTimerPrivateFunctionGetPreviewPoints(ByValnTypeAsInteger,ByValnStateAsInteger)AsPoint()IfnType=1ThenIfnStateMod4=0ThenReturnNewPoint(){NewPoint(0,1),NewPoint(1,1),NewPoint(2,1),NewPoint(2,0)}IfnStateMod4=1ThenReturnNewPoint(){NewPoint(0,0),NewPoint(0,1),NewPoint(0,2),NewPoint(1,2)}IfnStateMod4=2ThenReturnNewPoint(){NewPoint(0,0),NewPoint(0,1),NewPoint(1,0),NewPoint(2,0)}IfnStateMod4=3ThenReturnNewPoint(){NewPoint(0,0),NewPoint(1,0),NewPoint(1,1),NewPoint(1,2)}ElseIfnType=2ThenIfnStateMod4=0ThenReturnNewPoint(){NewPoint(0,0),NewPoint(1,0),NewPoint(2,0),NewPoint(2,1)}IfnStateMod4=1ThenReturnNewPoint(){NewPoint(0,0),NewPoint(0,1),NewPoint(0,2),NewPoint(1,0)}IfnStateMod4=2ThenReturnNewPoint(){NewPoint(0,0),NewPoint(0,1),NewPoint(1,1),NewPoint(2,1)}IfnStateMod4=3ThenReturnNewPoint(){NewPoint(1,0),NewPoint(1,1),NewPoint(1,2),NewPoint(0,2)}ElseIfnType=3ThenIfnStateMod2=0ThenReturnNewPoint(){NewPoint(0,0),NewPoint(1,0),NewPoint(2,0),NewPoint(3,0)}IfnStateMod2=1ThenReturnNewPoint(){NewPoint(0,0),NewPoint(0,1),NewPoint(0,2),NewPoint(0,3)}ElseIfnType=4ThenIfnStateMod2=0ThenReturnNewPoint(){NewPoint(0,0),NewPoint(0,1),NewPoint(1,1),NewPoint(1,2)}IfnStateMod2=1ThenReturnNewPoint(){NewPoint(0,1),NewPoint(1,0),NewPoint(1,1),NewPoint(2,0)}ElseIfnType=5ThenIfnStateMod2=0ThenReturnNewPoint(){NewPoint(0,1),NewPoint(0,2),NewPoint(1,0),NewPoint(1,1)}IfnStateMod2=1ThenReturnNewPoint(){NewPoint(0,0),NewPoint(1,0),NewPoint(1,1),NewPoint(2,1)}ElseIfnType=6ThenIfnStateMod4=0ThenReturnNewPoint(){NewPoint(0,1),NewPoint(1,0),NewPoint(1,1),NewPoint(1,2)}IfnStateMod4=1ThenReturnNewPoint(){NewPoint(0,0),NewPoint(1,0),NewPoint(1,1),NewPoint(2,0)}IfnStateMod4=2ThenReturnNewPoint(){NewPoint(0,0),NewPoint(0,1),NewPoint(0,2),NewPoint(1,1)}IfnStateMod4=3ThenReturnNewPoint(){NewPoint(0,1),NewPoint(1,1),NewPoint(2,1),NewPoint(1,0)}ElseReturnNewPoint(){NewPoint(0,0),NewPoint(0,1),NewPoint(1,0),NewPoint(1,1)}EndIfEndFunctionPrivateFunctionNewBlock(ByValnLocationAsPoint)AsBooleanDimLeftAsInteger=100,RightAsInteger=-1,BottomAsInteger=-1,TopAsInteger=100,nPointsAsPoint()=GetPreviewPoints(BlockType,BlockState)ForEachnAsPointInnPointsIfn.XLeftThenLeft=n.XIfn.XRightThenRight=n.XIfn.YTopThenTop=n.YIfn.YBottomThenBottom=n.YNextIfnLocation.X+Left0ThennLocation.X=-LeftElseIfnLocation.X+Right-LeftDrawRectangle.WidthThennLocation.X=DrawRectangle.Width-(Right-Left)EndIfIfnLocation.Y+Top0ThennLocation.Y=-TopElseIfnLocation.Y+(Bottom-Top)DrawRectangle.HeightThennLocation.Y=DrawRectangle.Height-(Bottom-Top)ReturnTrueEndIfForEachpAsPointInnPointsIfBlocks(p.X+nLocation.X,p.Y+nLocation.Y)1ThenReturnTrueNextForyAsInteger=0ToDrawRectangle.HeightForxAsInteger=0ToDrawRectangle.WidthIfBlocks(x,y)=1OrElseBlocks(x,y)5ThenBlocks(x,y)=0NextNextForEachpAsPointInnPointsBlocks(p.X+nLocation.X,p.Y+nLocation.Y)=1NextDrawLocation=nLocationEndFunctionPrivateSubKey_Up(ByValsenderAsObject,ByValeAsSystem.Windows.Forms.KeyEventArgs)HandlesMyBase.KeyUpIfe.KeyCode=Keys.WOrElsee.KeyCode=Keys.UpThenBlockState+=1IfNewBlock(DrawLocation)=FalseThenDrawBlock()ElseIfe.KeyCode=Keys.DOrElsee.KeyCode=Keys.RightThenIfNewBlock(NewPoint(DrawLocation.X+1,DrawLocation.Y))=FalseThenDrawBlock()ElseIfe.KeyCode=Keys.AOrElsee.KeyCode=Keys.LeftThenIfNewBlock(NewPoint(DrawLocation.X-1,DrawLocation.Y))=FalseThenDrawBlock()ElseIfe.KeyCode=Keys.SOrElsee.KeyCode=Keys.DownOrElsee.KeyCode=Keys.SpaceThenForyAsInteger=0ToDrawRectangle.HeightIfNewBlock(NewPoint(DrawLocation.X,DrawLocation.Y+1))ThenExitForNextDrawBlock()ElseIfe.KeyCode=Keys.EnterOrElsee.KeyCode=Keys.EscapeThenMyTimer.Enabled=NotMyTimer.EnabledIfMyTimer.EnabledThenReDimBlocks(DrawRectangle.Width,DrawRectangle.Height)NewBlock(NewPoint(5,0))Score(1)=0Me.Text="分数:"Score(1)EndIfEndIfEndSubPrivateSubTimer_Tick(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesMyTimer.TickIfNewBlock(NewPoint(DrawLocation.X,DrawLocation.Y+1))=FalseThenDrawBlock()ElseForyAsInteger=0ToDrawRectangle.HeightForxAsInteger=0ToDrawRectangle.WidthIfBlocks(x,y)=1ThenBlocks(x,y)=2NextNextScore(0)=ClearLine(0)IfScore(0)ThenScore(1)+=(Score(0)^2)*10Me.Text="分数:"Score(1)ElseBlockType=NextTypeNextType=Rnd()*6IfNewBlock(NewPoint(5,0))ThenMyTimer.Enabled=FalseMsgBox("游戏结束,按下Enter键重新开始。")EndIfEndIfEndIfEndSubPrivateFunctionClearLine(ByValStartIndexAsInteger)AsInteger'消行IfStartIndexDrawRectangle.HeightThenReturn0ForxAsInteger=0ToDrawRectangle.WidthIfBlocks(x,StartIndex)2ThenReturnClearLine(StartIndex+1)NextForxAsInteger=0ToDrawRectangle.WidthFory=StartIndexTo0Step-1Ify=0ThenBlocks(x,y)=0ElseBlocks(x,y)=Blocks(x,y-1)EndIfNextNextReturnClearLine(StartIndex+1)+1EndFunctionPrivateSubDrawBlock()Dimi(4,4)AsIntegerForEachpAsPointInGetPreviewPoints(NextType,0)i(p.X+1,p.Y+1)=1NextDrawPicture(Blocks,DrawRectangle.Location,Me.CreateGraphics)DrawPicture(i,NewPoint(DrawRectangle.Right+2,DrawRectangle.Y),Me.CreateGraphics)EndSubPrivateSubDrawPicture(ByValPicture(,)AsInteger,ByValnDrawPointAsPoint,ByValDrawGraphicsAsGraphics)ForxAsInteger=0ToPicture.GetUpperBound(0)ForyAsInteger=0ToPicture.GetUpperBound(1)IfPicture(x,y)=0ThenDrawGraphics.DrawImage(BackBitMap,NewPoint(nDrawPoint.X*20+x*20,nDrawPoint.Y*20+y*20))ElseIfPicture(x,y)=1OrElsePicture(x,y)=2ThenDrawGraphics.DrawImage(ShowBitMap,NewPoint(nDrawPoint.X*20+x*20,nDrawPoint.Y*20+y*20))EndIfNextNextEndSubPrivateSubForm_Load(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesMyBase.LoadRandomize()Graphics.FromImage(ShowBitMap).FillRectangle(NewSystem.Drawing.Drawing2D.HatchBrush(Rnd()*52,Color.FromArgb(HFF000000OrHFFFFFF*Rnd()),Color.FromArgb(HFF000000OrHFFFFFF*Rnd())),NewRectangle(0,0,20,20))Graphics.FromImage(ShowBitMap).DrawRectangle(Pens.Black,NewRectangle(0,0,19,19))Graphics.FromImage(BackBitMap).FillRectangle(NewSystem.Drawing.Drawing2D.HatchBrush(Rnd()*52,Color.FromArgb(HFF000000OrHFFFFFF*Rnd()),Color.FromArgb(HFF000000OrHFFFFFF*Rnd())),NewRectangle(0,0,20,20))Graphics.FromImage(BackBitMap).DrawRectangle(Pens.Black,NewRectangle(0,0,19,19))MyTimer.Interval=500Me.Text="按下Enter开始新游戏"Me.SetBounds(Screen.PrimaryScreen.Bounds.X+(Screen.PrimaryScreen.Bounds.Width-(DrawRectangle.Right+10)*20)/2,Screen.PrimaryScreen.Bounds.Y+(Screen.PrimaryScreen.Bounds.Height-(DrawRectangle.Bottom+5)*20)/2,(DrawRectangle.Right+10)*20,(DrawRectangle.Bottom+5)*20)Me.FormBorderStyle=Windows.Forms.FormBorderStyle.FixedToolWindowMe.MaximizeBox=FalseEndSubEndClass

刚才被反映说数据库太大,要查原因,手头没有脚本就现写了一个,感觉还蛮简单明了的,发上来给大家共享一下。

第一次写canvas...demo:

图片 1

友情链接: 网站地图
Copyright © 2015-2019 http://www.nflfreepicks.net. 新葡萄京娱乐场网址有限公司 版权所有