Advertisement
ccgrffdy

test Client 4

Jan 16th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.68 KB | None | 0 0
  1. rednet.open("back")
  2. local termWidth, termHeight = term.getSize()
  3. local selectedItem = 1
  4. local onMainMenu = true
  5. SERV = 83
  6. function StatSERV()
  7. term.clear()
  8. term.setCursorPos(1,1)
  9. print("Traitement des donnees ...")
  10. print("Patientez S.V.P ...")
  11. rednet.send(SERV, "If10")
  12. local senderId, message, protocol = rednet.receive(6)
  13. if message == "ON" then
  14. term.setTextColors(colors.green)
  15. print("Stone : " ..message)
  16. elseif message == "OFF" then
  17.  
  18. print("Stone : " ..message)
  19. end
  20. rednet.send(SERV, "If30")
  21. local senderId, message, protocol = rednet.receive(6)
  22. if message == "ON" then
  23. print("Emeraude : " ..message)
  24. elseif message == "OFF" then
  25. print("Emeraude : " ..message)
  26. end
  27. rednet.send(SERV, "If40")
  28. local senderId, message, protocol = rednet.receive(6)
  29. if message == "ON" then
  30. print("Diamand : " ..message)
  31. elseif message == "OFF" then
  32. print("Diamand : " ..message)
  33. end
  34. rednet.send(SERV, "If50")
  35. local senderId, message, protocol = rednet.receive(6)
  36. if message == "ON" then
  37. print("Sable : " ..message)
  38. elseif message == "OFF" then
  39. print("Sable : " ..message)
  40. end
  41. rednet.send(SERV, "If100")
  42. local senderId, message, protocol = rednet.receive(6)
  43. if message == "ON" then
  44. print("Glass : " ..message)
  45. elseif message == "OFF" then
  46. print("Glass : " ..message)
  47. end
  48. rednet.send(SERV, "If90")
  49. local senderId, message, protocol = rednet.receive(6)
  50. if message == "ON" then
  51. print("Clear Glass: " ..message)
  52. elseif message == "OFF" then
  53. print("Clear Glass: " ..message)
  54. end
  55. rednet.send(SERV, "If60")
  56. local senderId, message, protocol = rednet.receive(6)
  57. if message == "ON" then
  58. print("Sugar canes: " ..message)
  59. elseif message == "OFF" then
  60. print("Sugar canes: " ..message)
  61. end
  62. print("----------------------" .."Enter to Exit")
  63. print("Enter to Exit")
  64. dd= read()
  65. end
  66.  
  67. function GSERV()
  68. term.clear()
  69. term.setCursorPos(1,1)
  70. print("+-----------+-----------+")
  71. print("|Name       |      ID   |")
  72. print("+-----------+-----------+")
  73. print("|All        |///////////|")
  74. print("|Sugar Canes|      0    |")
  75. print("|Clear Glass|      1    |")
  76. print("|Diamand    |      2    |")
  77. print("|Emeraude   |      3    |")
  78. print("|Glass      |      4    |")
  79. print("|Sable      |      5    |")
  80. print("|Stone      |      6    |")
  81. print("+-----------+-----------+")
  82. print("|Exit       |      E    |")
  83. print("+-----------+-----------+")
  84. ID = read()
  85. if ID == "1" then
  86. print("Clear Glass  ON / OFF ")
  87. ONF = read()
  88. if ONF == "ON" then
  89. print("ON")
  90. rednet.send(SERV, "90")
  91. elseif ONF == "OFF" then
  92. print("OFF")
  93. rednet.send(SERV, "97")
  94. end
  95. elseif ID == "2" then
  96. print("Diamand  ON / OFF ")
  97. ONF = read()
  98. if ONF == "ON" then
  99. print("ON")
  100. rednet.send(SERV, "50")
  101. elseif ONF == "OFF" then
  102. print("OFF")
  103. rednet.send(SERV, "7")
  104. end
  105. elseif ID == "3" then
  106. print("Emeraude  ON / OFF ")
  107. ONF = read()
  108. if ONF == "ON" then
  109. print("ON")
  110. rednet.send(SERV, "30")
  111. elseif ONF == "OFF" then
  112. print("OFF")
  113. rednet.send(SERV, "37")
  114. end
  115. elseif ID == "4" then
  116. print("Glass  ON / OFF ")
  117. ONF = read()
  118. if ONF == "ON" then
  119. print("ON")
  120. rednet.send(SERV, "100")
  121. elseif ONF == "OFF" then
  122. print("OFF")
  123. rednet.send(SERV, "107")
  124. end
  125. elseif ID == "5" then
  126. print("Sable  ON / OFF ")
  127. ONF = read()
  128. if ONF == "ON" then
  129. print("ON")
  130. rednet.send(SERV, "50")
  131. elseif ONF == "OFF" then
  132. print("OFF")
  133. rednet.send(SERV, "57")
  134. end
  135. elseif ID == "6" then
  136. print("Stone  ON / OFF ")
  137. ONF = read()
  138. if ONF == "ON" then
  139. print("ON")
  140. rednet.send(SERV, "10")
  141. elseif ONF == "OFF" then
  142. print("OFF")
  143. rednet.send(SERV, "17")
  144. end
  145. elseif ID == "E" then
  146. print("Exit")
  147. sleep(1)
  148. elseif ID == "0" then
  149. print("Sugar canes  ON / OFF ")
  150. ONF = read()
  151. if ONF == "ON" then
  152. end
  153. print("ON")
  154. rednet.send(SERV, "60")
  155. elseif ONF == "OFF" then
  156. print("OFF")
  157. rednet.send(SERV, "67")
  158. end
  159. sleep(1)
  160. end
  161.  
  162. function Exit()
  163. onMainMenu = false
  164. end
  165.  
  166. mainMenu = {
  167. [1] = { text = "Statut des Services", handler = StatSERV },
  168. [2] = { text = "Geree les Services", handler = GSERV },
  169. [3] = { text = "Exit", handler = Exit },
  170. }
  171.  
  172. function printMenu( menu )
  173.  for i=1,#menu do
  174.   if i == selectedItem then
  175.    print(">> "..menu[i].text)
  176.   else
  177.    print("   "..menu[i].text)
  178.   end
  179.  end
  180. end
  181.  
  182. function onKeyPressed( key, menu )
  183.  if key == keys.enter then
  184.   onItemSelected(menu)
  185.  elseif key == keys.up then
  186.   if selectedItem > 1 then
  187.    selectedItem = selectedItem - 1
  188.   end
  189.  elseif key == keys.down then
  190.   if selectedItem < #menu then
  191.    selectedItem = selectedItem + 1
  192.   end
  193.  end
  194. end
  195.  
  196. function onItemSelected( menu )
  197.  menu[selectedItem].handler()
  198. end
  199.  
  200. function main()
  201.  while onMainMenu do
  202.   term.clear()
  203.   term.setCursorPos(1,1)
  204.   printMenu(mainMenu)
  205.   event, key = os.pullEvent("key")
  206.   onKeyPressed(key,mainMenu)
  207.  end
  208. end
  209.  
  210. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement