KapitanWalnut

BuildWall v0.1.1

Mar 7th, 2014
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.13 KB | None | 0 0
  1. --BuildWall by KapitanWalnut
  2. --Version 0.1.1   3/7/2014
  3. --Will build a wall of specific size
  4.  
  5. -- Config
  6. version = "0.1.1"
  7. topY = 10
  8. botY =0
  9. leftSide = 0
  10. rightSide = 10
  11. placedValue = 0
  12. minedValue = 0
  13. heightQuestion = true
  14. widthQuestion = true
  15. stacksQuestion = true
  16. stacksQuestion2 = true
  17.  
  18. -- Functions
  19. function getVersion() --returns version number
  20.     return version
  21. end
  22.  
  23. function regWrite(string, columnVar, rowVar) --write a string to specified coords
  24.     term.setCursorPos(columnVar, rowVar)
  25.     write(string)
  26. end
  27.  
  28. function arcWrite(number, columnVar, rowVar) --writes a number to specified coords, takes digits into account
  29.     digits = math.ceil(math.log10(number))
  30.     if 10^digits == number then
  31.         digits = digits + 1
  32.     end
  33.     term.setCursorPos(columnVar, rowVar)
  34.     while digits > 1 do
  35.         digits = digits - 1
  36.         columnVar = columnVar - 1
  37.         term.setCursorPos(columnVar, rowVar)
  38.     end
  39.     write(number)
  40. end
  41.  
  42. function clearScreen() --clears screen and prints version, author
  43.     term.clear()
  44.     regWrite("BuildWall", 15, 1)
  45.     regWrite(getVersion(), 3, 12)
  46.     regWrite("by KapitanWalnut", 20, 12)
  47.     term.setCursorPos(1, 3)
  48. end
  49.  
  50. function drawTable() --prints a table on screen display infor during run time
  51. clearScreen()
  52. print([[
  53.  +--------------------------------+
  54.  |Blocks Placed:                0 |
  55.  |Blocks Mined:                 0 |
  56.  +--------------------------------+
  57.  |             Status             |
  58.  |[                              ]|
  59.  |                0%              |
  60.  +--------------------------------+
  61. ]] )
  62. placedValue = 0
  63. minedValue = 0
  64. end
  65.  
  66. function updateTable() --updates table during runtime
  67.     --Update Blocks
  68.     arcWrite(placedValue, 33, 4)
  69.     arcWrite(minedValue, 33, 5)
  70.  
  71.     --Update Percentage
  72.     if height > 0 then
  73.         area = (height * width)
  74.     else
  75.         area = placedValue
  76.     end
  77.     percentage = math.ceil((placedValue / area) * 100)
  78.     arcWrite(percentage, 19, 9)
  79.  
  80.     --Update Percentage Bar
  81.     percentageBar = math.floor(percentage * 0.3)
  82.     columnVar = 4
  83.     while percentageBar > 0 do
  84.         regWrite("=", columnVar, 8)
  85.         percentageBar = percentageBar - 1
  86.         columnVar = columnVar + 1
  87.     end
  88. end
  89.  
  90. --Digging Functions
  91. function digDown() --Dig Down and update table
  92.     if turtle.detectDown() then
  93.         turtle.digDown()
  94.         minedValue = minedValue + 1
  95.     end
  96.     updateTable()
  97. end
  98.  
  99. function digUp() -- Dig up and update table
  100.     while turtle.detectUp() do
  101.         turtle.digUp()
  102.         sleep(0.4)
  103.         minedValue = minedValue + 1
  104.     end
  105.     updateTable()
  106. end
  107.  
  108. function digForward() --Dig Forward and update table
  109.     while turtle.detect() do
  110.         turtle.dig()
  111.         sleep(0.4)
  112.         minedValue = minedValue + 1
  113.     end
  114.     updateTable()
  115. end
  116.  
  117. --Movement Functions
  118. function moveForward()--Move forward no digging
  119.     moved = false
  120.     repeat
  121.         if turtle.forward() then
  122.             moved = true
  123.         else
  124.             moved = false
  125.         end
  126.     until moved == true
  127. end
  128.  
  129. function moveDown()--Move down no digging
  130.     moved = false
  131.     repeat
  132.         if turtle.down() then
  133.             moved = true
  134.         else
  135.             moved = false
  136.         end
  137.     until moved == true
  138. end
  139.  
  140. function moveUp()--Move forward no digging
  141.     moved = false
  142.     repeat
  143.         if turtle.up() then
  144.             moved = true
  145.         else
  146.             moved = false
  147.         end
  148.     until moved == true
  149. end
  150.  
  151. --Questions
  152. function askQuestions() --asks Questions
  153.    
  154.     --Get Height
  155.     clearScreen()
  156.     while heightQuestion == true do
  157.         print("Height of wall?")
  158.         height = tonumber(read())
  159.         clearScreen()
  160.         if height == nil then
  161.             print("Must be a number.")
  162.         elseif height >= 2 then
  163.             heightQuestion = false
  164.         else
  165.             print("Wall must be taller then one.")
  166.         end
  167.     end
  168.  
  169.     --Get Width
  170.     clearScreen()
  171.     while widthQuestion == true do
  172.         print("Width of Wall?")
  173.         width = tonumber(read())
  174.         clearScreen()
  175.         if width == nil then
  176.             print("Must be a number.")
  177.         elseif width > 0 then
  178.             widthQuestion = false
  179.         else
  180.             print("Width must be greater then 0")
  181.         end
  182.     end
  183.  
  184.     --make sure enough blocks are in inv
  185.     clearScreen()
  186.     while stacksQuestion == true do
  187.         stacksQuestion2 = true
  188.         area = width * height
  189.         stackNum = math.ceil(area/64)
  190.         if stackNum > 16 then --too big, reask questions
  191.             print("Area is too big!")
  192.             print("Requires ", stackNum, " stacks!")
  193.             print("Can only hold 16 stacks!")
  194.             print("")
  195.             print("Press Enter to reinput size...")
  196.             dummy = read()
  197.             heightQuestion = true
  198.             widthQuestion = true
  199.             stacksQuestion = true
  200.             stacksQuestion2 = true
  201.             askQuestions()
  202.         else
  203.             print("Do I have ", stackNum, " stacks?")
  204.             answer = string.lower(read())
  205.             clearScreen()
  206.             if answer == ('yes') then
  207.                 stacksQuestion = false
  208.             elseif answer == ('no') then
  209.                 while stacksQuestion2 == true do
  210.                     print("Well, should I abort the program then?")
  211.                     answer2 = string.lower(read())
  212.                     if answer2 == ('yes') then
  213.                         stacksQuestion2 = false
  214.                         term.clear()
  215.                         term.setCursorPos(1, 1)
  216.                         error("User Terminated Program")
  217.                     elseif answer2 == ('no') then
  218.                         print("Okay. I'll wait.")
  219.                         stacksQuestion2 = false
  220.                     else
  221.                         print("Please answer yes or no.")
  222.                     end
  223.                 end
  224.             else
  225.                 print("Please answer yes or no.")
  226.             end
  227.         end
  228.     end
  229. end
  230.  
  231. --main function
  232. function main()
  233.     askQuestions()
  234.     drawTable()
  235. end
  236.  
  237. --run main function
  238. main()
Advertisement
Add Comment
Please, Sign In to add comment