use Libraries.Robots.Lego.Button use Libraries.Robots.Lego.Motor use Libraries.Robots.Lego.TouchSensor use Libraries.Robots.Lego.Screen use Libraries.Robots.Lego.ColorSensor use Libraries.Robots.Lego.Sound use Libraries.Containers.Array class Main private Array menu private constant integer maxLines = 7 private integer top = 0 private integer bottom = 0 action Main Button button Beep beep Left360 left360 Right360 right360 StopOnBlack stopOnBlack StopOnTouch stopOnTouch menu:Add(beep) menu:Add(left360) menu:Add(right360) menu:Add(stopOnBlack) menu:Add(stopOnTouch) bottom = menu:GetSize() - 1 if bottom > maxLines bottom = maxLines end integer selected = 0 repeat until button:IsButtonPressed(button:ESCAPE_BUTTON) PrintMenu(selected) button:WaitForButtonPress() if button:IsButtonPressed(button:UP_BUTTON) selected = selected - 1 elseif button:IsButtonPressed(button:DOWN_BUTTON) selected = selected + 1 elseif button:IsButtonPressed(button:CENTER_BUTTON) Screen screen screen:Clear() screen:OutputCenter("Running...", 1) Program program = menu:Get(selected) program:Run() end // Handle wrapping around the list if selected < 0 selected = menu:GetSize() - 1 bottom = menu:GetSize() - 1 top = bottom - maxLines if top < 0 top = 0 end elseif selected = menu:GetSize() selected = 0 top = 0 bottom = menu:GetSize() - 1 if bottom > maxLines bottom = maxLines end end end end action PrintMenu(integer selected) Screen screen screen:Clear() // Scroll screen up or down as needed if selected > bottom top = top + 1 bottom = bottom + 1 elseif selected < top top = top - 1 bottom = bottom - 1 end integer i = top repeat while i <= bottom Program program = menu:Get(i) text prefix = " " if i = selected prefix = " > " end screen:Output(prefix + program:GetTitle(), i - top) i = i + 1 end end end