Advertisement
naej

test fonction

Sep 11th, 2013
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.35 KB | None | 0 0
  1. shell.run("clear")
  2. -- Controle des parametres
  3. local tArgs = { ... }
  4.  
  5. if #tArgs == 0 then
  6.   print("Hey biatch !! je vais ou ?")
  7.   print("Syntaxe: Commande <longueur> <nb_de_tunnels>")
  8.   return
  9. end
  10.  
  11. -- Declaration des variables
  12. local length = tonumber(tArgs[1])
  13. local width = tonumber(tArgs[2])
  14. local slotNum = 0
  15. local loop = 0
  16. local retry = 0
  17.  
  18. -- Plein d'energie
  19. if turtle.getFuelLevel() == 0 then
  20.   turtle.select(16)
  21.   print("Ajoutez du Carburant dans le dernier slot.")
  22.   print("Entree pour continuer")
  23.   ok  = read()
  24.   turtle.refuel()
  25.   if turtle.getFuelLevel() == 0 then
  26.     print("Boulay !! donne moi quelque chose a cramer pour avancer !!")
  27.     return
  28.   elseif turtle.getFuelLevel() == "unlimited" then
  29.     print("Pwoua trop cheater meme pas besoin de cramer quelque chose pour foncer !!")
  30.     return
  31.   end
  32. elseif turtle.getFuelLevel() > 0 then
  33.   print("Niveau de carburant : " .. turtle.getFuelLevel())
  34.   turtle.select(16)
  35.   print("Ajoutez du Carburant dans le dernier slot pour completer le plein.")
  36.   print("Entree pour continuer")
  37.   ok  = read()
  38.   turtle.refuel()
  39. end
  40. -- Blocs a ne pas miner
  41. print("Ajoutez des blocs a ne pas miner.")
  42. print("Entree pour continuer")
  43. ok = read()
  44.  
  45. -- Fonction gestion des bocages
  46. function moveForward()
  47.   if turtle.forward() == false then
  48.     while turtle.dig() do
  49.         end
  50.         if turtle.forward() == false then
  51.           print("Deplacement impossible")
  52.           return false
  53.         end
  54.   return true
  55.   end
  56. end
  57.  
  58. -- ContrΓ΄le nombre de slot poubelle
  59. function countJunkSlot()
  60.   junkSlots = 0
  61.   i = 0
  62.   while (i < 16) do
  63.     i = i + 1
  64.     if turtle.getItemCount(i) == 1 then
  65.       junkSlots = junkSlots + 1
  66.     end
  67.   end
  68. end
  69.  
  70. -- Fonction comparaison
  71. function compare()
  72.   isJunkDown = false
  73.   isJunkUp = false
  74.   for i = 1, junkSlots do
  75.     turtle.select(i)
  76.         if turtle.compareUp()==true then
  77.           isJunkUp = true
  78.         end
  79.         if turtle.compareDown()==true then
  80.           isJunkDown = true
  81.         end
  82.   end
  83. end
  84.  
  85. -- Fonction de minage
  86. function digger(n)
  87.   print("Debut de la phase de minage.")
  88.   purge = 0
  89.   while (n > 0) do
  90.     turtle.dig()
  91.     moveForward()
  92.     compare()
  93.     if isJunkUp == false then
  94.       turtle.digUp()
  95.       put()
  96.     end
  97.     if isJunkDown == false then
  98.       turtle.digDown()
  99.     end
  100.     --if purge == 10 then
  101.     --  invPurge()
  102.     --  purge = 0
  103.     --end
  104.     --purge = purge + 1
  105.     n = n - 1
  106.   end
  107.   print("")
  108. end
  109.  
  110. -- Fonction de retour sur la longueur
  111. function backL(n)
  112.   print("Retour au coffre.")
  113.   turtle.turnLeft()
  114.   turtle.turnLeft()
  115.   while (n > 0) do
  116.     moveForward()
  117.         n = n - 1
  118.   end
  119. end
  120.  
  121. -- Fonction de retour sur la largeur
  122. function backW(n)
  123.   turtle.turnRight()
  124.   while (n > 0)do
  125.     moveForward()
  126.         n = n - 1
  127.   end
  128.   turtle.turnLeft()
  129. end
  130.  
  131. -- Fonction purge inventaire
  132. function invPurge()
  133.   j = junkSlots
  134.   while (j < 16) do
  135.     j = j + 1
  136.         for k = 1, junkSlots do
  137.           turtle.select(j)
  138.           if turtle.compareTo(k) == true then
  139.             turtle.dropDown()
  140.           end
  141.         end
  142.   end
  143. end
  144.  
  145. -- Fonction repose de blocs
  146. function put()
  147.   l = junkSlots
  148.   place = false
  149.   while (place == false) do
  150.     l = l + 1
  151.       --for m = 1, junkSlots do
  152.         turtle.select(l)
  153.         if turtle.compareTo(1) == true then
  154.           turtle.placeUp()
  155.           place = true
  156.         end
  157.       --end
  158.   end
  159. end
  160.  
  161. -- Fonction vidage dans le coffre
  162. function drop()
  163.   invPurge()
  164.   i = junkSlots
  165.   while (i < 16) do
  166.     i = i + 1
  167.     turtle.select(i)
  168.     turtle.drop()
  169.   end
  170. end
  171.  
  172. -- Fonction placement pour la ligne suivante
  173. function nextLine(n)
  174.   turtle.turnLeft()
  175.   while (n > 0) do
  176.     turtle.dig()
  177.         moveForward()
  178.         turtle.digUp()
  179.         n = n - 1
  180.   end
  181.   turtle.turnLeft()
  182. end
  183.  
  184. -- Programme principal
  185.  
  186. print("+--------------------------+")
  187. print("|     Debut du minage      |")
  188. print("+--------------------------+")
  189. print("")
  190. print("longueur des tunnels : " .. length)
  191. print("nombre de tunnels : " .. width)
  192. print("")
  193.  
  194. countJunkSlot()
  195. digger(length)
  196. backL(length)
  197. drop()
  198.  
  199. width = width - 1
  200.  
  201. while (loop < width) do
  202.   loop = loop + 1
  203.   nextLine(loop)
  204.   digger(length)
  205.   backL(length)
  206.   backW(loop)
  207.   drop()
  208. end
  209.  
  210. print("+--------------------------+")
  211. print("|      Fin du minage       |")
  212. print("+--------------------------+")
  213. print("")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement