VB直角寻路学习1

VB直角寻路学习1,第1张

概述Private Const Col_Num = 100Private Const Row_Num = 100Private Const a = 10Private Type Ant_Type x As Integer y As Integer x1 As Integer y1 As Integer stat
Private Const Col_Num = 100Private Const Row_Num = 100Private Const a = 10Private Type Ant_Type    x       As Integer    y       As Integer    x1      As Integer    y1      As Integer    state   As Integer    destX   As Integer    destY   As Integer    Now_place As IntegerEnd TypePrivate Declare Sub Sleep lib "kernel32" (ByVal DWMilliseconds As Long)Private Declare Function SetPixelV lib "gdi32" (ByVal hdc As Long,ByVal x As Long,ByVal y As Long,ByVal crcolor As Long) As LongPrivate ant(3) As Ant_TypeDim Map() As LongDim XX As LongDim YY As LongDim XN As LongDim YN As LongPrivate Sub Command1_Click()    ClsEnd SubPrivate Sub Form_Activate()'    Call DrawAnt(0,vbGreen)End SubPrivate Sub Form_Load()'    ReDim Map(Row_Num,Col_Num)    ant(1).state = 0    XX = 1    YY = 1'    Call DrawAnt(1,1,vbGreen)End SubPrivate Sub DrawAnt(lngX As Long,lngY As Long,color As Long)'    Form1.line (lngX * a + 2,lngY * a + 2)-Step(a - 4,a - 4),color,BFEnd SubPrivate Sub clear_AntDraw(lngX As Long,lngY As Long)'    Form1.line (lngX * a + 2,Form1.Backcolor,BFEnd SubPrivate Sub Form_MouseDown(button As Integer,Shift As Integer,x As Single,y As Single)'    Dim i As Integer,j As Integer,M As Long,n As Long    If (x <= Row_Num * a) And (y <= Col_Num * a) Then        M = Fix(x / a): DeBUG.Print M        n = Fix(y / a): DeBUG.Print n        DeBUG.Print button        If button = 1 Then            If Map(M,n) = 1 Then                Map(M,n) = 0                Call clear_AntDraw(M,n)            Else                Map(M,n) = 1                Call DrawAnt(M,n,vbRed)            End If            DeBUG.Print Map(M,n)        End If        If button = 2 Then            XN = M            YN = n            Call autoFinDWay(XX,YY,XN,YN)        End If    End IfEnd SubPublic Function autoFinDWay(lngStartX As Long,lngStartY As Long,lngEndX As Long,lngEndY As Long) As Boolean'    Dim f As Integer    Dim path() As Long    Dim lngOKPath As Long    Dim PathLength As Long    Dim CurrentX As Integer    Dim CurrentY As Integer    Dim PointState As Boolean    Dim currentState As Boolean    Dim MapArea As Long    Dim Direction(3,1) As Integer    Dim reSearched() As Boolean    Dim MapWIDth As Integer    Dim MapHeight As Integer        MapWIDth = 100    MapHeight = 100        MapArea = MapWIDth * MapHeight    ReDim path(2,MapArea) As Long    ReDim reSearched(MapWIDth,MapHeight) As Boolean        reSearched(lngStartX,lngStartY) = True    path(0,0) = lngStartX    path(1,0) = lngStartY    path(2,0) = 0        Direction(0,0) = -1:       Direction(0,1) = 0    Direction(1,0) = 0:        Direction(1,1) = -1    Direction(2,0) = 1:        Direction(2,1) = 0    Direction(3,0) = 0:        Direction(3,1) = 1        lngOKPath = 0:              PathLength = 0        Do        For f = 0 To 3            CurrentX = path(0,lngOKPath) + Direction(f,0)            CurrentY = path(1,1)            If CurrentX = lngEndX And CurrentY = lngEndY Then                Exit Do            End If            If CurrentX > 0 And CurrentX < MapWIDth And CurrentY > 0 And CurrentY < MapHeight Then                PointState = Map(CurrentX,CurrentY)                If Not reSearched(CurrentX,CurrentY) Then                    currentState = False                    If PointState = 0 Then                        currentState = True                    End If                    If currentState Then                        reSearched(CurrentX,CurrentY) = True                        PathLength = PathLength + 1                        If PathLength >= UBound(path,2) Then                            MapArea = MapArea + 100000                            ReDim Preserve path(2,MapArea) As Long                        End If                        path(0,PathLength) = CurrentX                        path(1,PathLength) = CurrentY                        path(2,PathLength) = lngOKPath                    End If                End If            End If        Next f        lngOKPath = lngOKPath + 1        If path(0,lngOKPath) = 0 And path(1,lngOKPath) = 0 Then            For PathLength = 0 To lngOKPath                        Next PathLength            MsgBox "------------NO WAY-------------"            autoFinDWay = False            Exit Function        End If    Loop    PathLength = lngOKPath    Do        Form1.line (path(0,PathLength) * 10,path(1,PathLength) * 10)-Step(a - 4,vbGreen,BF        PathLength = path(2,PathLength)    Loop Until PathLength = 0    autoFinDWay = True    MsgBox "OK"    End Function
总结

以上是内存溢出为你收集整理的VB直角寻路学习1全部内容,希望文章能够帮你解决VB直角寻路学习1所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1281625.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-09
下一篇 2022-06-09

发表评论

登录后才能评论

评论列表(0条)

保存