Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tChoices = {}
- tChoices[0] = 'Squelette'
- tChoices[0] = 'Golem de fer'
- tChoices[0] = 'Blaze'
- tChoices[0] = 'Spider'
- tChoices[0] = 'Pigmen'
- tChoices[0] = 'Enderman'
- tChoices[0] = 'Zombie'
- tChoices[0] = 'Mouton'
- table.insert(tChoices, 'Shutdown')
- local nTermX, nTermY = term.getSize()
- local sSeperator = ("-"):rep(nTermX)
- local tActions = {}
- tActions[0] = function()
- term.clear()
- term.setCursorPos(1, 1)
- print(sSeperator)
- print("| Terminal Password |")
- print(sSeperator)
- print("Attention")
- term.setCursorPos(1, nTermY) -- envoi le curseur en haut
- write(" [appuyez sur entrer pour une autre selection]")
- read()
- end
- table.insert(tActions, os.shutdown) -- Insert the shutdown function at the end to compliment the "Shutdown" menu item :)
- -- Do the above for the remaining
- local nSelection = 0 -- The current selection defaults at 0
- repeat
- term.setCursorPos(1, 1)
- term.clear()
- print(sSeperator)
- print("| FantomQc pour vous servir! |")
- print(sSeperator)
- for nLine = 0, #tChoices do -- Iterate through the possible potions, and print them, marking the chosen one
- local sLine = " "
- if nSelection == nLine then
- sLine = ">"
- end
- local sLineNum = tostring(nLine)
- if #sLineNum < 2 then
- sLineNum = "0" .. sLineNum -- Prepend a 0 if it's too short
- end
- sLine = sLine .. "[" .. sLineNum .. "]" .. " " .. tChoices[nLine] -- Construct the string we're printing
- print(sLine) -- Print it
- end
- -- os.pullEvent keys: up - 200, down - 208, enter - 28
- local sEvent, nKey = os.pullEvent("key") -- Using the 1.3 filtering; this will mean only "key" events will pass
- if nKey == 200 or nKey == 17 then -- Up/w key: move up the menu
- if tChoices[nSelection - 1] then -- Check if we can move up
- nSelection = nSelection - 1
- end
- -- Ignore it otherwise
- elseif nKey == 208 or nKey == 31 then -- Down/s key: move down the menu
- if tChoices[nSelection + 1] then -- Check if we can move down
- nSelection = nSelection + 1
- end
- elseif nKey == 28 then -- Enter key: Selecting a choice
- if tActions[nSelection] then
- tActions[nSelection]() -- Run the function associated with the action.
- else
- print("Error: Selection out of bounds: ", nSelection)
- read() -- This error is recoverable.
- end
- end
- until false -- Run this loop forever :)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement