Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local nbPuit = 0
- local nbPuitsTotal = 0
- local profondeur = 0
- local items = {}
- local idChannel = 123
- local fuelLevel = 0
- local fuelItem = 0
- local message = "attente"
- -- Fonction pour diviser une chaîne de caractères en fonction d'un motif donné
- function split(str, pat)
- local t = {}
- local fpat = "(.-)" .. pat
- local last_end = 1
- local s, e, cap = str:find(fpat, 1)
- while s do
- if s ~= 1 or cap ~= "" then
- table.insert(t, cap)
- end
- last_end = e + 1
- s, e, cap = str:find(fpat, last_end)
- end
- if last_end <= #str then
- cap = str:sub(last_end)
- table.insert(t, cap)
- end
- return t
- end
- -- Configuration de l'affichage
- term.setBackgroundColor(colors.blue)
- local monitor = peripheral.find("monitor")
- monitor.setTextScale(0.5)
- --ajout
- monitor.setBackgroundColor(colors.blue)
- monitor.clear()
- monitor.setCursorPos(1, 1)
- --ajout
- -- Fonction pour afficher l'état actuel sur le moniteur
- function affiche_etat()
- term.clear()
- term.setCursorPos(1, 4)
- if message == "attente" then
- monitor.setTextColor(colors.yellow)
- print("En attente de la tortue...")
- elseif message == "encours" then
- monitor.setTextColor(colors.green)
- print("Avancement du minage : " .. nbPuit .. " / " .. nbPuitsTotal .. " Puits.")
- term.setCursorPos(1, 6)
- if profondeur == 0 then
- print("Profondeur : +" .. profondeur .. " Fuel: " .. fuelLevel .. " Charbonslot: " .. fuelItem)
- else
- print("Profondeur : -" .. profondeur .. " Fuel: " .. fuelLevel .. " Charbonslot: " .. fuelItem)
- end
- term.setCursorPos(1, 10)
- for i = 1, #items do
- if items[i] then
- monitor.setTextColor(colors.white)
- print(i .. "-" .. items[i].name .. " x" .. items[i].count)
- end
- end
- elseif message == "vidage" then
- term.setCursorPos(1, 4)
- monitor.setTextColor(colors.orange)
- print("Avancement du minage : " .. nbPuit .. " / " .. nbPuitsTotal .. " Puits.")
- term.setCursorPos(1, 6)
- if profondeur == 0 then
- print("Profondeur : +" .. profondeur .. " Fuel: " .. fuelLevel .. " Charbonslot: " .. fuelItem)
- else
- print("Profondeur : -" .. profondeur .. " Fuel: " .. fuelLevel .. " Charbonslot: " .. fuelItem)
- end
- term.setCursorPos(1, 8)
- print("La tortue vient vider son inventaire")
- term.setCursorPos(1, 10)
- for i = 1, #items do
- if items[i] then
- monitor.setTextColor(colors.white)
- print(i .. "-" .. items[i].name .. " x" .. items[i].count)
- end
- end
- elseif message == "charbon" then
- term.setCursorPos(1, 4)
- monitor.setTextColor(colors.red)
- print("Avancement du minage : " .. nbPuit .. " / " .. nbPuitsTotal .. " Puits.")
- term.setCursorPos(1, 6)
- if profondeur == 0 then
- print("Profondeur : +" .. profondeur .. " Fuel: " .. fuelLevel .. " Charbonslot: " .. fuelItem)
- else
- print("Profondeur : -" .. profondeur .. " Fuel: " .. fuelLevel .. " Charbonslot: " .. fuelItem)
- end
- term.setCursorPos(1, 8)
- print("La tortue revient se charger en charbon")
- term.setCursorPos(1, 10)
- for i = 1, #items do
- if items[i] then
- monitor.setTextColor(colors.white)
- print(i .. "-" .. items[i].name .. " x" .. items[i].count)
- end
- end
- elseif message == "retour" then
- term.setCursorPos(1, 4)
- monitor.setTextColor(colors.orange)
- print("Avancement du minage : " .. nbPuit .. " / " .. nbPuitsTotal .. " Puits.")
- term.setCursorPos(1, 6)
- if profondeur == 0 then
- print("Profondeur : +" .. profondeur .. " Fuel: " .. fuelLevel .. " Charbonslot: " .. fuelItem)
- else
- print("Profondeur : -" .. profondeur .. " Fuel: " .. fuelLevel .. " Charbonslot: " .. fuelItem)
- end
- term.setCursorPos(1, 8)
- print("Minage terminee, retour au point de depart...")
- term.setCursorPos(1, 10)
- for i = 1, #items do
- if items[i] then
- monitor.setTextColor(colors.white)
- print(i .. "-" .. items[i].name .. " x" .. items[i].count)
- end
- end
- elseif message == "fin" then
- term.setCursorPos(1, 4)
- monitor.setTextColor(colors.magenta)
- print("Avancement du minage : " .. nbPuit .. " / " .. nbPuitsTotal .. " Puits.")
- term.setCursorPos(1, 6)
- if profondeur == 0 then
- print("Profondeur : +" .. profondeur .. " Fuel: " .. fuelLevel .. " Charbonslot: " .. fuelItem)
- else
- print("Profondeur : -" .. profondeur .. " Fuel: " .. fuelLevel .. " Charbonslot: " .. fuelItem)
- end
- term.setCursorPos(1, 8)
- print("Minage terminee !")
- print("En attente de la tortue...")
- --term.setCursorPos(1, 12)
- --for i = 1, #items do
- -- if items[i] then
- -- monitor.setTextColor(colors.white)
- -- print(i .. "-" .. items[i].name .. " x" .. items[i].count)
- -- end
- --end
- end
- end
- --rednet.open("right")
- modem = peripheral.find("modem")
- affiche_etat()
- while true do
- modem.open(idChannel)
- event, modemSide, senderChannel, replyChannel, text, senderDistance = os.pullEvent("modem_message")
- local data = textutils.unserialise(text)
- if data then
- items = data
- print("ok")
- --monitor.setCursorPos(1,1)
- --print("Données reçues de la tortue :")
- --print(text)
- else
- local tab = split(text, ":")
- if tab[1] == "etat" then message = tab[2] end
- if tab[1] == "nbPuitsTotal" then nbPuitsTotal = tab[2] end --if tab[1] == "nbPuitsTotal" then nbPuitsTotal = tonumber(tab[2]) end
- if tab[1] == "nbPuits" then nbPuit = tab[2] end --if tab[1] == "nbPuits" then nbPuit = tonumber(tab[2]) end
- if tab[1] == "profondeur" then profondeur = tab[2] end --if tab[1] == "profondeur" then profondeur = tonumber(tab[2]) end
- if tab[1] == "fuel" then fuelLevel = tab[2] end --tonumber(tab[2]) end
- if tab[1] == "fuelItem" then fuelItem = tab[2] end --tonumber(tab[2]) end
- end
- affiche_etat()
- --modem.close(idChannel)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement