我试图给我的Small Basic程序一个随机背景:
If File.ReadContents(Program.Directory + "\Turtle.settings") = "" Then
Reset()
EndIf
Background = File.ReadLine(Program.Directory + "\Turtle.settings", 1)
Color = File.ReadLine(Program.Directory + "\Turtle.settings", 2)
Distance = File.ReadLine(Program.Directory + "\Turtle.settings", 3)
Mode = File.ReadLine(Program.Directory + "\Turtle.settings", 4)
Speed = File.ReadLine(Program.Directory + "\Turtle.settings", 5)
Width = File.ReadLine(Program.Directory + "\Turtle.settings", 6)
Controls.ButtonClicked = ButtonClicked
GraphicsWindow.KeyDown = KeyDown
GraphicsWindow.PenColor = Color
GraphicsWindow.PenWidth = Width
GraphicsWindow.Title = "Turtle"
Turtle.Speed = Speed
TextBoxOne = Controls.AddTextBox(10, 10)
Controls.SetTextBoxText(TextBoxOne, "Maximize the window")
Start = Controls.AddButton ("OK", 180, 8)
Sub KeyDown
EndSub
Sub ButtonClicked
If Controls.LastClickedButton = Start Then
Controls.Remove(TextBoxOne)
Controls.Remove(Start)
Turtle.X = GraphicsWindow.Width / 2
Turtle.Y = GraphicsWindow.Height / 2
Turtle.Show()
If Background = 1 Then
For I = 1 To 400
X = Math.GetRandomNumber(GraphicsWindow.Width)
Y = Math.GetRandomNumber(GraphicsWindow.Height)
Z = Math.GetRandomNumber(1)
GraphicsWindow.BrushColor = GraphicsWindow.GetRandomColor()
GraphicsWindow.FillEllipse(X, Y, 20, 20)
EndFor
EndIf
Menu()
EndIf
EndSub
Sub Reset
File.WriteLine(Program.Directory + "\Turtle.settings", 1, "1")
File.WriteLine(Program.Directory + "\Turtle.settings", 2, "#000000")
File.WriteLine(Program.Directory + "\Turtle.settings", 3, "100")
File.WriteLine(Program.Directory + "\Turtle.settings", 4, "0")
File.WriteLine(Program.Directory + "\Turtle.settings", 5, "10")
File.WriteLine(Program.Directory + "\Turtle.settings", 6, "3")
EndSub
Sub Menu
EndSub
结果如下:
如您所见,有时点位于随机位置,但其他点按颜色排序。我之间没有对代码进行任何更改。
将Z = Math.GetRandomNumber(1)
更改为Z = 1
会阻止点显示有序,即使Z
的值保持不变。
删除所有File.ReadLine()
命令也有效。如果删除命令,则总是随机放置点。我仍然想要使用这些,所以我需要另一个解决方案。
删除Turtle.Y = GraphicsWindow.Height / 2
或将其移到背景制作代码后面,也可确保随机放置点。我将此作为临时解决方案,但我仍在寻找真正的解决方案。
如果我在后台制作代码之前和之后放置Turtle.Y = GraphicsWindow.Height / 2
,程序将崩溃。我假设这是由于Small Basic本身的错误,这也是造成我问题的原因。
答案 0 :(得分:0)
错误是由Small Basic本身的问题引起的。因此,如果不编辑程序就无法纠正它。唯一可行的解决方案是删除Turtle.Y = GraphicsWindow.Height / 2
或将其移到后台制作代码后面。