我的目标是使用VB.net在VS中创建一个迷宫,我目前已设法创建一个随机生成器,使其成为“迷宫”,并显示最后一面墙的位置。
Horizontalwalls = Randomizer.Next(60, 91) 'Makes 60 - 90 Horizontal Walls
VirticalWalls = Randomizer.Next(60, 91) 'Makes 60 -90 Vertical Walls
Dim HLoops = 0 'counter for Horizontal walls
Dim VLoops = 0
lbxHorizontal.Items.Clear() 'empties the list box i have which stores the walls location
lbxvertical.Items.Clear()
Do While HLoops < (Horizontalwalls)
HLoops += 1 'adds to the counter
lbxHorizontal.Items.Insert(0, Randomizer.Next(0, 10))
lbxHorizontal.Items.Insert(0, Randomizer.Next(0, 10))
'Attempt at making visable walls
pbxhorizontalwall.Top = (lbxHorizontal.Items.Item(0) * GridSize - 2) 'This and next line puts the wall in desired location
pbxhorizontalwall.Left = (lbxHorizontal.Items.Item(1) * GridSize - 2)
Loop
然而,我所知道的让所有墙壁可见的唯一方法是制作90张水平墙图片,然后将它们全部命名,然后GLaaa ...必须有一种更简单的方法来复制同一图像在屏幕上理想位置。
目前,我真正想知道的是复制图像的代码行(也许是在重置迷宫时大规模清除它们的方法)然后我会弄清楚如何获取它到位...
答案 0 :(得分:0)
首先使用以下方法创建图像列表:
Dim imageList As New List(Of Bitmap)
imageList.Add("image to add") 'do it for all the images you have
然后创建一个位图:
Dim bitmapWall as Bitmap = New Bitmap(widthOfbitmap, heightofbitmap, Drawing.Imaging.PixelFormat.Format24bppRgb)
将图像列表绘制到bimap:
Dim objGraphics As Graphics = Graphics.FromImage(bitmapWall)
For i = 0 To imageList.Count
objGraphics.DrawImage(imageList(i), x, y, imageList(i).Width, imageList(i).Height)
Next
objGraphics.Dispose()
x,y是绘制图像的坐标(您应该在每次迭代时更改它们)
最后:
Me.BackgroundImage = bitmapWall
Me.Invalidate()
不要忘记最后处理列表和位图。
瓦尔特