Advertisement
mapokapo

Turtle Miner

Mar 24th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.12 KB | None | 0 0
  1. programs = {"stairs", "strip", "exit"}
  2.  
  3. function contains(table, element)
  4.   for _, value in pairs(table) do
  5.     if value == element then
  6.       return true
  7.     end
  8.   end
  9.   return false
  10. end
  11.  
  12. function threeRound(num)
  13.   if num > 0 then
  14.     return math.ceil(num/3.0) * 3;
  15.   elseif num < 0 then
  16.     return math.floor(num/3.0) * 3;
  17.   else
  18.     return 3;
  19.   end
  20. end
  21.  
  22. function stairs()
  23.   print("stairs - test")
  24. end
  25.  
  26. function strip()
  27.   print("Enter length of tunnel: ")
  28.   len = threeRound(tonumber(read()))
  29.   print(len)
  30.   if len > 0 then
  31.     turtle.digUp()
  32.     turtle.up()
  33.     for i = 1, len do
  34.       if i % 3 == 0 then
  35.         turtle.turnLeft()
  36.         for j = 1, 5 do
  37.           turtle.dig()
  38.           turtle.forward()
  39.           if j == 5 then
  40.             turtle.turnRight()
  41.             turtle.turnRight()
  42.             for k = 0, j-1 do
  43.               turtle.forward()
  44.             end
  45.           end
  46.         end
  47.         for j = 1, 5 do
  48.           turtle.dig()
  49.           turtle.forward()
  50.           if j == 5 then
  51.             turtle.turnRight()
  52.             turtle.turnRight()
  53.             for k = 0, j-1 do
  54.               turtle.forward()
  55.             end
  56.           end
  57.         end
  58.         turtle.turnRight()
  59.       end
  60.       if i % 6 == 0 then
  61.         turtle.placeDown()
  62.       end
  63.       turtle.dig()
  64.       turtle.forward()
  65.       turtle.digDown()
  66.     end
  67.   else
  68.     print("Length of tunnel must be bigger than 0")
  69.     strip()
  70.   end
  71. end
  72.  
  73. function getProg()
  74.   input = read()
  75.   if contains(programs, input) then
  76.     if input == "stairs" then
  77.         stairs()
  78.     elseif input == "strip" then
  79.         strip()
  80.     elseif input == "exit" then
  81.         print("Goodbye")
  82.     end
  83.   else
  84.     print("Invalid program!")
  85.     getProg()
  86.   end
  87. end
  88.  
  89. function start()
  90.   print("Enter password: ")
  91.     pass = read()
  92.     if pass == "dw20" then
  93.         print("Correct password!")
  94.         print("Type the name of a program to start:")
  95.         for program in pairs(programs) do
  96.             print(program .. ". - " .. programs[program])
  97.         end
  98.         getProg()
  99.     else
  100.         print("Wrong password!")
  101.         start()
  102.     end
  103. end
  104.  
  105. start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement