Advertisement
Vodka51200

affichageturtlemine

May 24th, 2014 (edited)
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.39 KB | None | 0 0
  1. local nbPuit = 0
  2. local nbPuitsTotal = 0
  3. local profondeur = 0
  4. local items = {}
  5. local idChannel = 123
  6. local fuelLevel = 0
  7. local fuelItem = 0
  8. local message = "attente"
  9.  
  10. -- Fonction pour diviser une chaîne de caractères en fonction d'un motif donné
  11. function split(str, pat)
  12.     local t = {}
  13.     local fpat = "(.-)" .. pat
  14.     local last_end = 1
  15.     local s, e, cap = str:find(fpat, 1)
  16.     while s do
  17.         if s ~= 1 or cap ~= "" then
  18.             table.insert(t, cap)
  19.         end
  20.         last_end = e + 1
  21.         s, e, cap = str:find(fpat, last_end)
  22.     end
  23.     if last_end <= #str then
  24.         cap = str:sub(last_end)
  25.         table.insert(t, cap)
  26.     end
  27.     return t
  28. end
  29.  
  30. -- Configuration de l'affichage
  31. term.setBackgroundColor(colors.blue)
  32. local monitor = peripheral.find("monitor")
  33. monitor.setTextScale(0.5)
  34. --ajout
  35. monitor.setBackgroundColor(colors.blue)
  36. monitor.clear()
  37. monitor.setCursorPos(1, 1)
  38. --ajout
  39.  
  40. -- Fonction pour afficher l'état actuel sur le moniteur
  41. function affiche_etat()
  42.     term.clear()
  43.     term.setCursorPos(1, 4)
  44.     if message == "attente" then
  45.         monitor.setTextColor(colors.yellow)
  46.         print("En attente de la tortue...")
  47.     elseif message == "encours" then
  48.         monitor.setTextColor(colors.green)
  49.         print("Avancement du minage : " .. nbPuit .. " / " .. nbPuitsTotal .. " Puits.")
  50.         term.setCursorPos(1, 6)
  51.         if profondeur == 0 then
  52.             print("Profondeur : +" .. profondeur .. " Fuel: " .. fuelLevel .. " Charbonslot: " .. fuelItem)
  53.         else
  54.             print("Profondeur : -" .. profondeur .. " Fuel: " .. fuelLevel .. " Charbonslot: " .. fuelItem)
  55.         end
  56.         term.setCursorPos(1, 10)
  57.         for i = 1, #items do
  58.             if items[i] then
  59.                 monitor.setTextColor(colors.white)
  60.                 print(i .. "-" .. items[i].name .. " x" .. items[i].count)
  61.             end
  62.         end
  63.     elseif message == "vidage" then
  64.         term.setCursorPos(1, 4)
  65.         monitor.setTextColor(colors.orange)
  66.         print("Avancement du minage : " .. nbPuit .. " / " .. nbPuitsTotal .. " Puits.")
  67.         term.setCursorPos(1, 6)
  68.         if profondeur == 0 then
  69.             print("Profondeur : +" .. profondeur .. " Fuel: " .. fuelLevel .. " Charbonslot: " .. fuelItem)
  70.         else
  71.             print("Profondeur : -" .. profondeur .. " Fuel: " .. fuelLevel .. " Charbonslot: " .. fuelItem)
  72.         end
  73.         term.setCursorPos(1, 8)
  74.         print("La tortue vient vider son inventaire")
  75.         term.setCursorPos(1, 10)
  76.         for i = 1, #items do
  77.             if items[i] then
  78.                 monitor.setTextColor(colors.white)
  79.                 print(i .. "-" .. items[i].name .. " x" .. items[i].count)
  80.             end
  81.         end
  82.     elseif message == "charbon" then
  83.         term.setCursorPos(1, 4)
  84.         monitor.setTextColor(colors.red)
  85.         print("Avancement du minage : " .. nbPuit .. " / " .. nbPuitsTotal .. " Puits.")
  86.         term.setCursorPos(1, 6)
  87.         if profondeur == 0 then
  88.             print("Profondeur : +" .. profondeur .. " Fuel: " .. fuelLevel .. " Charbonslot: " .. fuelItem)
  89.         else
  90.             print("Profondeur : -" .. profondeur .. " Fuel: " .. fuelLevel .. " Charbonslot: " .. fuelItem)
  91.         end
  92.         term.setCursorPos(1, 8)
  93.         print("La tortue revient se charger en charbon")
  94.         term.setCursorPos(1, 10)
  95.         for i = 1, #items do
  96.             if items[i] then
  97.                 monitor.setTextColor(colors.white)
  98.                 print(i .. "-" .. items[i].name .. " x" .. items[i].count)
  99.             end
  100.         end
  101.     elseif message == "retour" then
  102.         term.setCursorPos(1, 4)
  103.         monitor.setTextColor(colors.orange)
  104.         print("Avancement du minage : " .. nbPuit .. " / " .. nbPuitsTotal .. " Puits.")
  105.         term.setCursorPos(1, 6)
  106.         if profondeur == 0 then
  107.             print("Profondeur : +" .. profondeur .. " Fuel: " .. fuelLevel .. " Charbonslot: " .. fuelItem)
  108.         else
  109.             print("Profondeur : -" .. profondeur .. " Fuel: " .. fuelLevel .. " Charbonslot: " .. fuelItem)
  110.         end
  111.         term.setCursorPos(1, 8)
  112.         print("Minage terminee, retour au point de depart...")
  113.         term.setCursorPos(1, 10)
  114.         for i = 1, #items do
  115.             if items[i] then
  116.                 monitor.setTextColor(colors.white)
  117.                 print(i .. "-" .. items[i].name .. " x" .. items[i].count)
  118.             end
  119.         end
  120.     elseif message == "fin" then
  121.         term.setCursorPos(1, 4)
  122.         monitor.setTextColor(colors.magenta)
  123.         print("Avancement du minage : " .. nbPuit .. " / " .. nbPuitsTotal .. " Puits.")
  124.         term.setCursorPos(1, 6)
  125.         if profondeur == 0 then
  126.             print("Profondeur : +" .. profondeur .. " Fuel: " .. fuelLevel .. " Charbonslot: " .. fuelItem)
  127.         else
  128.             print("Profondeur : -" .. profondeur .. " Fuel: " .. fuelLevel .. " Charbonslot: " .. fuelItem)
  129.         end
  130.         term.setCursorPos(1, 8)
  131.         print("Minage terminee !")
  132.         print("En attente de la tortue...")
  133.         --term.setCursorPos(1, 12)
  134.         --for i = 1, #items do
  135.         --    if items[i] then
  136.         --      monitor.setTextColor(colors.white)
  137.         --        print(i .. "-" .. items[i].name .. " x" .. items[i].count)
  138.         --    end
  139.         --end
  140.     end
  141. end
  142.  
  143. --rednet.open("right")
  144. modem = peripheral.find("modem")
  145. affiche_etat()
  146.  
  147. while true do
  148.     modem.open(idChannel)
  149.     event, modemSide, senderChannel, replyChannel, text, senderDistance = os.pullEvent("modem_message")
  150.     local data = textutils.unserialise(text)
  151.     if data then
  152.         items = data
  153.         print("ok")
  154.         --monitor.setCursorPos(1,1)
  155.         --print("Données reçues de la tortue :")
  156.         --print(text)
  157.     else
  158.         local tab = split(text, ":")
  159.         if tab[1] == "etat" then message = tab[2] end
  160.         if tab[1] == "nbPuitsTotal" then nbPuitsTotal = tab[2] end --if tab[1] == "nbPuitsTotal" then nbPuitsTotal = tonumber(tab[2]) end
  161.         if tab[1] == "nbPuits" then nbPuit = tab[2] end --if tab[1] == "nbPuits" then nbPuit = tonumber(tab[2]) end
  162.         if tab[1] == "profondeur" then profondeur = tab[2] end --if tab[1] == "profondeur" then profondeur = tonumber(tab[2]) end
  163.         if tab[1] == "fuel" then fuelLevel = tab[2] end --tonumber(tab[2]) end
  164.         if tab[1] == "fuelItem" then fuelItem = tab[2] end --tonumber(tab[2]) end
  165.     end
  166.     affiche_etat()
  167.     --modem.close(idChannel)
  168. end
  169.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement