--[[Local Variables]]--
local inMenu = true
local selectedItem = 1
--[[Moving methods]]--
function pulse(side, color, time)
rs.setBundledOutput(side, color, true)
sleep(time/2)
rs.setBundledOutput(side, 0)
sleep(time/2)
end
function forward(t)
term.clear()
term.setCursorPos(1,1)
write("How far forward ? ")
t = read()
for i=1,tonumber(t) do
pulse("bottom", colors.white, 0.8)
end
end
function back(t)
term.clear()
term.setCursorPos(1,1)
write("How far back ? ")
t = read()
for i=1,tonumber(t) do
pulse("bottom", colors.orange, 0.8)
end
end
function left(t)
term.clear()
term.setCursorPos(1,1)
write("How far left ? ")
t = read()
for i=1,tonumber(t) do
pulse("bottom", colors.magenta, 0.8)
end
end
function right(t)
term.clear()
term.setCursorPos(1,1)
write("How far right ? ")
t = read()
for i=1,tonumber(t) do
pulse("bottom", colors.lightBlue, 0.8)
end
end
function up(t)
term.clear()
term.setCursorPos(1,1)
write("How far up ? ")
t = read()
for i=1,tonumber(t) do
pulse("bottom", colors.yellow, 0.8)
end
end
function down(t)
term.clear()
term.setCursorPos(1,1)
write("How far down ? ")
t = read()
for i=1,tonumber(t) do
pulse("bottom", colors.lime, 0.8)
end
end
function exit()
inMenu = false
end
--[[Menu Definitions]]--
mainMenu = {
[1] = { text = "Forward", handler = forward },
[2] = { text = "Back", handler = back },
[3] = { text = "Left", handler = left },
[4] = { text = "Right", handler = right },
[5] = { text = "Up", handler = up },
[6] = { text = "Down", handler = down },
[7] = { text = "Exit", handler = exit }
}
--[[Printing Methods]]--
function printMenu( menu )
for i=1,#menu do
if i == selectedItem then
print(">> "..menu[i].text)
else
print(" "..menu[i].text)
end
end
end
--[[Handling Methods]]--
function onKeyPressed( key, menu )
if key == 28 then
onItemSelected(menu)
elseif key == 200 then
if selectedItem > 1 then
selectedItem = selectedItem - 1
end
elseif key == 208 then
if selectedItem < #menu then
selectedItem = selectedItem + 1
end
end
end
function onItemSelected( menu )
menu[selectedItem].handler()
end
--[[Main Method]]--
function main()
while inMenu do
term.clear()
term.setCursorPos(1,1)
printMenu(mainMenu)
event, key = os.pullEvent("key")
onKeyPressed(key,mainMenu)
end
end
main()