Advertisement
Kiliandeca

Test1 - Prog

Aug 9th, 2016
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.39 KB | None | 0 0
  1. shell.run("clear")
  2. print("Pocket")
  3. rednet.open("back")
  4.  
  5. xmax = 4
  6. ymax = 4
  7.  
  8. function keytostop()
  9.     print(phase, " en cours, appuyez sur une touche pour stop")
  10.     os.pullEvent("key")
  11. end
  12.  
  13. function placement()
  14.  
  15.     local sID, msg, prot = rednet.receive("New Slave", 60)
  16.  
  17.     if msg == nil then
  18.         print("Error: Slave not responding")
  19.         return false
  20.     elseif msg == "New Slave" then
  21.         print("Send Master Instruction")
  22.         rednet.send(sID, {"Master", xmax, ymax}, "New Slave Wait")
  23.     end
  24. end
  25.  
  26. function minage(distance)
  27.  
  28.     rednet.broadcast({"Mining", distance}, "Instruction")
  29.  
  30. end
  31.  
  32. function config()
  33.     print("X max ?")
  34.     xmax = tonumber(io.read())
  35.     print("Y max ?")
  36.     ymax = tonumber(io.read())
  37. end
  38.  
  39.  
  40. function main()
  41.  
  42.     while true do
  43.         shell.run("clear")
  44.         print("Placement: p")
  45.         print("Mining: m")
  46.         print("Looting: l")
  47.         print("Recuperation: r")   
  48.         print("Config: c")
  49.         input = io.read()
  50.  
  51.  
  52.         if input == "p" then
  53.             phase = "Placement"
  54.             parallel.waitForAny(placement, keytostop)
  55.         elseif input == "m" then
  56.             phase = "Minage"
  57.             print("Quelle distance ?")
  58.             minage(tonumber(io.read()))
  59.         elseif input == "l" then
  60.             rednet.broadcast({"Looting"},"Instruction")
  61.         elseif input == "r" then
  62.             rednet.broadcast({"Recup"},"Instruction")
  63.         elseif input == "s" then
  64.             rednet.broadcast({"Shutdown"},"Instruction")
  65.         elseif input == "c" then
  66.             config()
  67.         end
  68.  
  69.     end
  70.  
  71.  
  72. end
  73.  
  74. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement