Advertisement
ccgrffdy

test Client

Jan 15th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.98 KB | None | 0 0
  1. rednet.open("back")
  2. local termWidth, termHeight = term.getSize()
  3. local selectedItem = 1
  4. local onMainMenu = true
  5.  
  6. function Choice1()
  7. term.clear()
  8. term.setCursorPos(1,1)
  9. print("Traitement des données ...")
  10. print("Patientez S.V.P ...")
  11. rednet.send(83, "If10")
  12. local senderId, message, protocol = rednet.receive(6)
  13. print("Stone : " ..message)
  14. rednet.send(83, "If30")
  15. local senderId, message, protocol = rednet.receive(6)
  16. print("Emeraude : " ..message)
  17. rednet.send(83, "If40")
  18. local senderId, message, protocol = rednet.receive(6)
  19. print("Diamand : " ..message)
  20. rednet.send(83, "If50")
  21. local senderId, message, protocol = rednet.receive(6)
  22. print("Sable : " ..message)
  23. rednet.send(83, "If100")
  24. local senderId, message, protocol = rednet.receive(6)
  25. print("Glass : " ..message)
  26. rednet.send(83, "If90")
  27. local senderId, message, protocol = rednet.receive(6)
  28. print("Clear Glass: " ..message)
  29. print("----------------------" .."Inser OK to Exit")
  30. dd= read()
  31. end
  32.  
  33. function Choice2()
  34. term.clear()
  35. term.setCursorPos(1,1)
  36. print("CHOICE 2")
  37. sleep(1)
  38. end
  39.  
  40. function Exit()
  41. onMainMenu = false
  42. end
  43.  
  44. mainMenu = {
  45. [1] = { text = "Statut des Service", handler = Choice1 },
  46. [2] = { text = "Choice 2", handler = Choice2 },
  47. [3] = { text = "Exit", handler = Exit },
  48. }
  49.  
  50. function printMenu( menu )
  51.  for i=1,#menu do
  52.   if i == selectedItem then
  53.    print(">> "..menu[i].text)
  54.   else
  55.    print("   "..menu[i].text)
  56.   end
  57.  end
  58. end
  59.  
  60. function onKeyPressed( key, menu )
  61.  if key == keys.enter then
  62.   onItemSelected(menu)
  63.  elseif key == keys.up then
  64.   if selectedItem > 1 then
  65.    selectedItem = selectedItem - 1
  66.   end
  67.  elseif key == keys.down then
  68.   if selectedItem < #menu then
  69.    selectedItem = selectedItem + 1
  70.   end
  71.  end
  72. end
  73.  
  74. function onItemSelected( menu )
  75.  menu[selectedItem].handler()
  76. end
  77.  
  78. function main()
  79.  while onMainMenu do
  80.   term.clear()
  81.   term.setCursorPos(1,1)
  82.   printMenu(mainMenu)
  83.   event, key = os.pullEvent("key")
  84.   onKeyPressed(key,mainMenu)
  85.  end
  86. end
  87.  
  88. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement