小老鼠走迷宫.ppt
《小老鼠走迷宫.ppt》由会员分享,可在线阅读,更多相关《小老鼠走迷宫.ppt(24页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、班級班級:奈米一乙奈米一乙學號學號:49914019姓名姓名:陳聖倫陳聖倫老師老師:謝慶存謝慶存小老鼠走迷宮小老鼠走迷宮程式介面 選擇迷宮選擇迷宮開始開始 老鼠老鼠 出口出口 程式碼Public Class Form1 Dim PicBox(50,50)As PictureBox Dim SqWidth,FWidth,FHeight,MazeX,MazeY,k,Totalm,Totaln,x,y,dx,dy,AI,Steps(50,50)As Integer Dim Map(50,50)As Integer Dim StepTotal As Integer Dim RandMapVal As
2、Single Dim newgames As Boolean Dim title As String Dim cross(50,50)As Integer Dim InMaze As IO.StreamReader Dim ImPortF,InString As String Dim MapRow,StartPx,StartPy,EndPx,EndPy,TotalStep As IntegerPrivate Sub Form1_Load(ByVal sender As System.Object,ByVal e As System.EventArgs)Handles MyBase.Load t
3、itle=老鼠走迷宮 Me.Text=title Me.ShowPath.Enabled=False Me.Stopmouse.Enabled=False Me.Stopmouse.Enabled=False EditMaze.CheckOnClick=True ToolStatus.Text=閒置中 newgames=True MazeX=50 MazeY=50 SqWidth=15 FWidth=SqWidth*(MazeX+3)FHeight=SqWidth*(MazeY+4)+40 Me.Width=FWidth Me.Height=FHeight For i As Integer=1
4、 To 50 For j As Integer=1 To 50 Call initial(i,j)Next Next InMaze=IO.File.OpenText(MazeMap.txt)Call MapGen()Me.Text=title End Sub Sub initial(ByVal i As Integer,ByVal j As Integer)Dim mypic As New PictureBox Me.Controls.Add(mypic)PicBox(i,j)=mypic End Sub Private Sub AddEvents(ByVal CtrlParent As Co
5、ntrol)Dim pic As Control For Each pic In CtrlParent.Controls If TypeOf pic Is PictureBox Then AddHandler pic.MouseClick,AddressOf MapEdit End If Next End SubPrivate Sub MapEdit(ByVal sender As Object,ByVal e As System.Windows.Forms.MouseEventArgs)If NewMap.Enabled=True Then Exit Sub End If ToolStatu
6、s.Text=迷宮編輯中 With DirectCast(sender,PictureBox)If e.Button=Windows.Forms.MouseButtons.Left Then If.Tag=1 Then .BackColor=Color.White .Tag=0 Else .BackColor=Color.Black .Tag=1 End If End If If e.Button=Windows.Forms.MouseButtons.Right Then If.Tag=0 Or.Tag=1 Or.Tag=3 Then .BackColor=Color.Chocolate .T
7、ag=2 ElseIf.Tag=2 Then .BackColor=Color.LawnGreen .Tag=3 End If End If End With End SubSub newgameset(ByVal i As Integer,ByVal j As Integer)Dim Px,Py As Integer Me.ShowPath.Enabled=True If i MazeX Or j MazeY Then Px=MazeX*SqWidth Py=MazeY*SqWidth+15 Map(i,j)=1 Else Px=i*SqWidth Py=j*SqWidth+15 End I
8、f With PicBox(i,j).SetBounds(Px,Py,SqWidth,SqWidth).BackColor=Color.White .Tag=0 If i=1 Or j=1 Or i=MazeX Or j=MazeY Then .BackColor=Color.Black .Tag=1 End If If i=StartPx And j=StartPy Then .BackColor=Color.Chocolate .Tag=2 End If If i=EndPx And j=EndPy Then .BackColor=Color.LawnGreen .Tag=3 End If
9、 End With End SubSub retag()If newgames=False Then PicBox(x,y).BackColor=Color.White Else PicBox(StartPx,StartPy).BackColor=Color.Chocolate PicBox(EndPx,EndPy).BackColor=Color.LawnGreen End If newgames=False Dim i,j As Integer For i=0 To MazeX For j=0 To MazeY Steps(i,j)=100000 If i 0 And j 0 Then W
10、ith PicBox(i,j)If.Tag=0 Then .BackColor=Color.White Steps(i,j)=1 cross(i,j)=0 ElseIf.Tag=3 Then Steps(i,j)=0 .BackColor=Color.LawnGreen ElseIf.Tag=2 Then Steps(i,j)=100000 .BackColor=Color.Chocolate Else .BackColor=Color.Black Steps(i,j)=100000 End If End With End If Next j Next i End Sub Private Su
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 老鼠 迷宫
限制150内