Namespace myMojoApp#Import "<std>"#Import "<mojo>"Using std..Using mojo..Const Size := New Vec2i( 950, 720 )const Name:string = "FontSprite"const Ver:string = "V1.17"Function Main() New AppInstance New MyWindow App.Run()EndClass MyWindow Extends Window Method New() Super.New( "FontSprite Editor "+Ver, Size.X, Size.Y, WindowFlags.Resizable|WindowFlags.HighDPI ) SetMinSize( Size.X, Size.Y ) Layout = "fill" ClearColor = Color.Black End method protected 'MUST be an odd number const _mWidth:int = 17 const _mHeight:int = 13 field _maze:bool[, ] = New bool[_mWidth, _mHeight] field _startX:ubyte = 0 field _startY:ubyte = 0 field _posX:ubyte field _posY:ubyte field _mMax:int = ((_mWidth-1) * 0.5) * ((_mHeight-1)*0.5) field _mCount:int = 0 Method OnRender( canvas:Canvas ) Override' canvas.DrawText( "Hello World",Width/2,Height/2,.5,.5 ) local size:int = 25 local x:int local y:int local xp:int local yp:int canvas.Color = Color.Brick * 0.9 For y = 0 To _mHeight-1 xp = 0 For x = 0 To _mWidth-1 If _maze[x, y] Then Else canvas.DrawRect( xp, yp, size, size ) canvas.DrawFrame( xp, yp, size, size ) End if xp += size Next yp += size Next If _startX = 0 Then return canvas.Color = Color.Green canvas.DrawRect( _posX*size+2, _posY*size+2, size-4, size-4 ) End 'x and y MUST be odd and within borders method GetPosition() _posX = (int(Rnd((_mWidth-1) * 0.5))*2)+1 _posY = (int(Rnd((_mHeight-1) * 0.5))*2)+1 End method method ZeroMaze() local x:int local y:int For y = 0 To _mHeight-1 For x = 0 To _mWidth-1 _maze[x, y] = False Next Next _startX = 0 _startY = 0 _mCount = 0 End method method CreateMaze() 'first pick a start both MUST be odd and within borders Repeat If _startX = 0 And _startY = 0 Then GetPosition() _startX = _posX _startY = _posY Else 'pick a direction local dir:int = int(Rnd(4)) local newx:int = _posX local newy:int = _posY local newPos:bool = False' Print dir+" "+_mCount Select dir Case 0 'left newx = _posX-2 If newx > 0 And not _maze[ newx, _posY ] Then _maze[ _posX-1, _posY ] = true Else newPos = True End If Case 1 'right newx = _posX+2 If newx < _mWidth-1 And not _maze[ newx, _posY ] Then _maze[ _posX+1, _posY ] = True Else newPos = True End If Case 2 'up newy = _posY-2 If newy > 0 And not _maze[ _posX, newy ] Then _maze[ _posX, _posY-1 ] = True Else newPos = True End If Case 3 'down newy = _posY+2 If newy < _mHeight-1 And not _maze[ _posX, newy ] Then _maze[ _posX, _posY+1 ] = true Else newPos = True End If End Select 'check and repeat if not valid If newPos Then Repeat Repeat GetPosition() Until _maze[ _posX, _posY ] = True until Not (_maze[ _posX-1, _posY ] and _maze[ _posX+1, _posY ] and _maze[ _posX, _posY-1 ] and _maze[ _posX, _posY+1 ]) Else _posX = newx _posY = newy End If End If If Not _maze[ _posX, _posY ] Then _mCount += 1 _maze[ _posX, _posY ] = True Until _mCount = _mMax end method Method OnKeyEvent( event:KeyEvent ) Override Select event.Type case EventType.KeyDown ZeroMaze() CreateMaze() RequestRender() End select End methodEnd