Advertisement
Fulgar

Costruisci quadrato

Apr 3rd, 2015
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.88 KB | None | 0 0
  1. local t = turtle
  2. local c = true
  3.  
  4. write("Lunghezza lato: ")
  5. local square = tonumber(read())
  6. local gira = "right"
  7. write("Altezza: ")
  8. local altezza = tonumber(read())
  9. altezza = altezza + 1 -- Aumento di 1 perché piazzo blocchi anche a livello pavimento
  10. local lati = 4 -- Lati del quadrato
  11.  
  12. local slot = 16
  13.  
  14. local function selectSlot(n)
  15.     c = 1
  16.     for i = 1,n do
  17.         if turtle.getItemCount(c) == 0 then
  18.             c = c + 1
  19.             if c == 17 then
  20.                 print("Materiali finiti. In attesa di essere rifornita di materiali. Il controllo ripartira' tra 10 secondi")
  21.                 c = 1
  22.                 i = 1
  23.                 sleep(10)
  24.             end
  25.             turtle.select(c)
  26.         end
  27.     end
  28. end
  29.    
  30.  
  31. local function piazza(n)
  32.     selectSlot(slot)
  33.     for i = 1,n do
  34.         selectSlot(slot)
  35.         t.dig()
  36.         t.forward()
  37.         t.digDown()
  38.         t.placeDown()
  39.     end
  40. end
  41.  
  42. local function lato(n)
  43.     selectSlot(slot)
  44.     n = n + 1
  45.     for i = 1,n do
  46.         selectSlot(slot)
  47.         t.digDown()
  48.         t.placeDown()
  49.         t.dig()
  50.         t.forward()
  51.     end
  52. end
  53.  
  54. while c do
  55.     selectSlot(slot)
  56.     -- Pavimentazione
  57.     for i2 = 1,square do
  58.         piazza(square)
  59.         t.dig()
  60.         t.forward()
  61.         if gira == "right" then
  62.             t.turnRight()
  63.             t.dig()
  64.             t.forward()
  65.             t.turnRight()
  66.             gira = "left"
  67.         else
  68.             t.turnLeft()
  69.             t.dig()
  70.             t.forward()
  71.             t.turnLeft()
  72.             gira = "right"
  73.         end
  74.     end
  75.  
  76.  
  77.     -- Lato
  78.     for i5 = 1,altezza do
  79.  
  80.         for i4 = 1,lati do
  81.             lato(square)
  82.             if gira == "right" then -- deve cambiare senso
  83.                 t.turnLeft()
  84.             else
  85.                 t.turnRight()
  86.             end
  87.         end
  88.            
  89.         if i5 == altezza then
  90.  
  91.             t.back()
  92.  
  93.             for i = 1,altezza-1 do
  94.                 t.digDown()
  95.                 t.down()
  96.             end
  97.  
  98.             if gira == "right" then -- deve cambiare senso
  99.                 t.turnLeft()
  100.             else
  101.                 t.turnRight()
  102.             end
  103.  
  104.             for i = 1,square do
  105.                 t.dig()
  106.                 t.forward()
  107.             end
  108.            
  109.             if gira == "right" then
  110.                 t.turnRight()
  111.             else
  112.                 t.turnLeft()
  113.             end
  114.  
  115.         else
  116.             t.digUp()
  117.             t.up()
  118.  
  119.         end
  120.  
  121.     end
  122.  
  123.     c = false
  124. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement