surferpup

Minecraft Tank Building Turtle

Jan 9th, 2014
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 22.70 KB | None | 0 0
  1. --  Build-a-Tank Turtle v. 2.0
  2. --  Will build a tank (iron or steel)
  3. --  by Surferpup
  4. --  Creative Commons License
  5. --  Build Date January 8, 2014
  6.  
  7. local version="2.0"
  8. local menu ={" Help "," Set Tank Size "," Move Turtle "," Refuel "," Start Building "," Quit & Power Off "}
  9. local selectedOption = 1
  10. local length = 3
  11. local width = 3
  12. local height = 4
  13. local maxOption = 6
  14. local quit = 0
  15. local wallSlot=1
  16. local wallSlotLimit = 4
  17. local guageSlot=5
  18. local guageSlotLimit = 8
  19. local valveSlot=9
  20. local valveSlotLimit = 12
  21. local readyToBuild = 0
  22. local progress = 0
  23. local goal = 0
  24. local level = "Bottom"
  25. local needWall=0
  26. local needGuage=0
  27. local needValve=0
  28. local needFuel=0
  29. local placedWall=0
  30. local placedGuage=0
  31. local placedValve=0
  32. local usedFuel = 0
  33.  
  34. -- MOVE FUNCTIONS
  35.  
  36. function forward(arg)
  37.     arg = arg or 0
  38.     local success = 1
  39.     while not turtle.forward() do
  40.         if turtle.getFuelLevel()==0 then
  41.             success=0
  42.             refuel("Please add more fuel.")
  43.         elseif arg == -1 then
  44.             break
  45.         end
  46.     end
  47.     printNeed()
  48.     if success==0 then
  49.         if arg==0 then
  50.             drawBuildDisplay()
  51.             updateProgress(0)
  52.             printNeed()
  53.         elseif arg==-1 then
  54.             displayMove()
  55.         end
  56.     end
  57. end
  58. function back(arg)
  59.     arg = arg or 0
  60.     local success = 1
  61.     while not turtle.back() do
  62.         if turtle.getFuelLevel()==0 then
  63.             success=0
  64.             refuel("Please add more fuel.")
  65.         elseif arg == -1 then
  66.             break
  67.         end
  68.     end
  69.     printNeed()
  70.     if success==0 then
  71.         if arg==0 then
  72.             drawBuildDisplay()
  73.             updateProgress(0)
  74.             printNeed()
  75.         elseif arg==-1 then
  76.             displayMove()
  77.         end
  78.     end
  79. end
  80. function up(arg)
  81.     arg = arg or 0
  82.     local success = 1
  83.     while not turtle.up() do
  84.         if turtle.getFuelLevel()==0 then
  85.             success=0
  86.             refuel("Please add more fuel.")
  87.         elseif arg == -1 then
  88.             break
  89.         end
  90.     end
  91.     printNeed()
  92.     if success==0 then
  93.         if arg==0 then
  94.             drawBuildDisplay()
  95.             updateProgress(0)
  96.             printNeed()
  97.         elseif arg==-1 then
  98.             displayMove()
  99.         end
  100.     end
  101. end
  102. function down(arg)
  103.     arg = arg or 0
  104.     local success = 1
  105.     while (not turtle.down()) do
  106.         if turtle.getFuelLevel()==0 then
  107.             success=0
  108.             refuel("Please add more fuel.")
  109.         elseif arg == -1 then
  110.             break
  111.         end
  112.     end
  113.     printNeed()
  114.     if success==0 then  
  115.         if arg==0 then
  116.             drawBuildDisplay()
  117.             updateProgress(0)
  118.             printNeed()
  119.         elseif arg==-1 then
  120.             displayMove()
  121.         end
  122.     end
  123. end
  124. function turnRight()
  125.     repeat
  126.     until turtle.turnRight()
  127. end
  128. function turnLeft()
  129.     repeat
  130.     until turtle.turnLeft()
  131. end
  132.  
  133. -- USER MOVE
  134.     term.setBackgroundColor(colors.black)
  135.     term.setTextColor(colors.white)
  136.    
  137.    
  138. function move()
  139.     repeat
  140.         local event,key = os.pullEvent("key")
  141.         term.setCursorPos(36,1)
  142.         term.write(key)
  143.         if key == 17 then --w
  144.             term.setBackgroundColor(colors.white)
  145.             term.setTextColor(colors.black)
  146.             term.setCursorPos(8,4)
  147.             term.write("Forward")
  148.             forward(-1)
  149.             term.setBackgroundColor(colors.black)
  150.             term.setTextColor(colors.white)
  151.             term.setCursorPos(8,4)
  152.             term.write("Forward")
  153.             printNeed()
  154.         elseif key == 30 then --a
  155.             term.setBackgroundColor(colors.white)
  156.             term.setTextColor(colors.black)
  157.             term.setCursorPos(7,6)
  158.             term.write("L")
  159.             turnLeft()
  160.             os.sleep(.05)
  161.             term.setBackgroundColor(colors.black)
  162.             term.setTextColor(colors.white)
  163.             term.setCursorPos(7,6)
  164.             term.write("L")
  165.         elseif key == 31 then --s
  166.             term.setBackgroundColor(colors.white)
  167.             term.setTextColor(colors.black)
  168.             term.setCursorPos(10,8)
  169.             term.write("Back")
  170.             back(-1)
  171.             term.setBackgroundColor(colors.black)
  172.             term.setTextColor(colors.white)
  173.             term.setCursorPos(10,8)
  174.             term.write("Back")
  175.             printNeed()
  176.         elseif key == 32 then --d
  177.             term.setBackgroundColor(colors.white)
  178.             term.setTextColor(colors.black)
  179.             term.setCursorPos(15,6)
  180.             term.write("R")
  181.             turnRight()
  182.             os.sleep (.05)
  183.             term.setBackgroundColor(colors.black)
  184.             term.setTextColor(colors.white)
  185.             term.setCursorPos(15,6)
  186.             term.write("R")
  187.         elseif key == 57 or key==200 then --space or up arrow
  188.             term.setBackgroundColor(colors.white)
  189.             term.setTextColor(colors.black)
  190.             term.setCursorPos(20,4)
  191.             term.write("Up")
  192.             up(-1)
  193.             term.setBackgroundColor(colors.black)
  194.             term.setTextColor(colors.white)
  195.             term.setCursorPos(20,4)
  196.             term.write("Up")
  197.             printNeed()
  198.         elseif key == 42 or key==208 then --shift or down arrow
  199.             term.setBackgroundColor(colors.white)
  200.             term.setTextColor(colors.black)
  201.             term.setCursorPos(18,8)
  202.             term.write("Down")
  203.             down(-1)
  204.             term.setBackgroundColor(colors.black)
  205.             term.setTextColor(colors.white)
  206.             term.setCursorPos(18,8)
  207.             term.write("Down")
  208.             printNeed()
  209.         end
  210.     until (key == 28) --enter
  211.     drawBox(0)
  212. end
  213.            
  214. -- BUILD FUNCTIONS
  215.  
  216. function place(slot,limit)
  217.     while(turtle.getItemCount(slot) == 0) do
  218.         slot=slot+1
  219.         if slot > limit then
  220.             break
  221.         end
  222.     end
  223.     if slot > limit then
  224.         print ("Out of material")
  225.         return -1
  226.     else
  227.         turtle.select(slot)
  228.         turtle.placeDown()
  229.         printNeed()
  230.         updateProgress()
  231.     end
  232.     return slot
  233. end
  234. function buildTop(length,width)
  235.     for i=1,length do
  236.         for j=1,width do
  237.             if (i == math.ceil(length/2) and j == math.ceil(width/2)) then
  238.                 placedValve=placedValve+1
  239.                 valveSlot=place(valveSlot,valveSlotLimit)
  240.             else
  241.                 placedWall=placedWall+1
  242.                 wallSlot=place(wallSlot,wallSlotLimit)
  243.             end
  244.             if j<width then
  245.                 usedFuel=usedFuel+1
  246.                 forward()
  247.             end
  248.         end
  249.         if i<length then
  250.             if (math.floor(i/2)==math.ceil(i/2)) then
  251.                 turnRight()
  252.                 usedFuel=usedFuel+1
  253.                 forward()
  254.                 turnRight()
  255.             else
  256.                 turnLeft()
  257.                 usedFuel=usedFuel+1
  258.                 forward()
  259.                 turnLeft()
  260.             end
  261.         else
  262.             turnRight()
  263.         end
  264.     end    
  265. end
  266. function placeWallSegment(distance)
  267.     placedWall=placedWall+1
  268.     wallSlot=place(wallSlot,wallSlotLimit)    
  269.     if wallSlot<0 then return end
  270.     for i=1,distance-2 do
  271.         usedFuel=usedFuel+1
  272.         forward()
  273.         placedGuage=placedGuage+1
  274.         guageSlot=place(guageSlot,guageSlotLimit)
  275.     end
  276.     usedFuel=usedFuel+1
  277.     forward()
  278. end
  279. function refuel(arg)
  280.     drawBox(1)
  281.     displayMessage("Refueling ...",nil,-1,nil)
  282.     fuelStart = turtle.getFuelLevel()
  283.     for i = 1,16 do
  284.         turtle.select(i)
  285.         turtle.refuel()
  286.     end
  287.     if fuelStart == turtle.getFuelLevel() then
  288.         displayMessage("No Fuel in Inventory","ERROR",0,arg)
  289.         term.setBackgroundColor(colors.black)
  290.         term.setTextColor(colors.white)
  291.     end
  292.     drawBox(0)
  293. end
  294. function build()
  295.     progress=0
  296.     placedWall=0
  297.     placedGuage=0
  298.     placedValve=0
  299.     usedFuel=0
  300.     level="Bottom"
  301.     goal = needWall+needGuage+2
  302.     drawBuildDisplay()
  303.     usedFuel=usedFuel+1
  304.     up()
  305.     updateProgress(0)
  306.     buildTop(length,width)
  307.    
  308.     for i=1,height-2 do
  309.         level = string.format("%1d of %1d",i+1,height)
  310.         updateProgress(0)
  311.         usedFuel=usedFuel+1
  312.         up()
  313.         placeWallSegment(length)
  314.         turnRight()
  315.         placeWallSegment(width)
  316.         turnRight()
  317.         placeWallSegment(length)
  318.         turnRight()
  319.         placeWallSegment(width)
  320.         if i<height-2 then
  321.             turnRight()
  322.         end
  323.     end
  324.     turnRight()
  325.     turnRight()
  326.     usedFuel=usedFuel+1
  327.     up()
  328.     level = "Top   "
  329.     updateProgress(0)
  330.     buildTop(length,width)
  331.     turnRight()
  332.     drawBox(0)
  333.     placedWall=0
  334.     placedGuage=0
  335.     placedValve=0
  336.     usedFuel=0
  337.     printNeed()
  338. end
  339.  
  340. -- USER INTERFACE AND CONTROL FUNCTIONS
  341.  
  342. function updateProgress(arg)
  343.     arg = arg or 1
  344.     progress = progress+arg
  345.     term.setCursorPos(7,6)
  346.     term.write("On Level: "..level)
  347.     term.setCursorPos(7,8)
  348.     temp=string.format("Placed %d of %d",progress,goal)
  349.     term.setCursorPos(6+11-math.floor((#(temp))/2),8)
  350.     term.write(temp)
  351.     term.setBackgroundColor(colors.white)
  352.     term.setCursorPos(7,7)
  353.     term.write(string.rep(" ",math.floor((progress/goal)*100/5)))
  354.     term.setBackgroundColor(colors.black)
  355. end
  356.  
  357. function centerPrint(text,ypos,highlight)
  358.     text = text or ""
  359.     ypos = ypos or 1
  360.     highlight = highlight or 0
  361.     term.setCursorPos(39/2-(#text)/2,ypos)
  362.     if highlight==1 then
  363.         term.setBackgroundColor(colors.white)
  364.         term.setTextColor(colors.black)
  365.     else
  366.         term.setBackgroundColor(colors.black)
  367.         term.setTextColor(colors.white)
  368.     end
  369.     term.write(text)
  370.     term.setBackgroundColor(colors.black)
  371.     term.setTextColor(colors.white)
  372. end        
  373. function menuOptionPrint(number,text,xpos,highlight)
  374.     number = number or 1
  375.     text = text or ""
  376.     xpos = xpos or 1
  377.     highlight = highlight or 0
  378.     term.setCursorPos(5,xpos)
  379.     term.write(tostring(number)..")")
  380.     term.setCursorPos(8,xpos)
  381.     if highlight==1 then
  382.         term.setBackgroundColor(colors.white)
  383.         term.setTextColor(colors.black)
  384.     else
  385.         term.setBackgroundColor(colors.black)
  386.         term.setTextColor(colors.white)
  387.     end
  388.     term.write(text)
  389.     term.setBackgroundColor(colors.black)
  390.     term.setTextColor(colors.white)
  391. end
  392. function displaySizes(argLength,argHeight,column)
  393.     argLength = argLength or 3
  394.     argHeight = argHeight or 6
  395.     column = column or 1
  396.    
  397.     for i = 1,4 do
  398.         term.setBackgroundColor(colors.black)
  399.         term.setTextColor(colors.white)
  400.         term.setCursorPos(7,i+3)
  401.         if argLength==(i*2+1) then
  402.             term.write(">   <")
  403.         else
  404.             term.write("     ")
  405.         end
  406.         if argLength==(i*2+1) and column == 1 then
  407.             term.setBackgroundColor(colors.white)
  408.             term.setTextColor(colors.black)
  409.         else
  410.             term.setBackgroundColor(colors.black)
  411.             term.setTextColor(colors.white)
  412.         end
  413.         term.setCursorPos(8,i+3)
  414.         term.write(string.format("%1dx%1d",i*2+1,i*2+1))
  415.     end
  416.     term.setBackgroundColor(colors.black)
  417.     term.setTextColor(colors.white)
  418.     term.setCursorPos(13,5)
  419.     term.write("X")
  420.     for i = 1,5 do
  421.         term.setBackgroundColor(colors.black)
  422.         term.setTextColor(colors.white)
  423.         term.setCursorPos(15,i+3)
  424.         if argHeight==(i+3) then
  425.             term.write("> <")
  426.         else
  427.             term.write("   ")
  428.         end
  429.         if argHeight==(i+3) and column == 2 then
  430.             term.setBackgroundColor(colors.white)
  431.             term.setTextColor(colors.black)
  432.         else
  433.             term.setBackgroundColor(colors.black)
  434.             term.setTextColor(colors.white)
  435.         end
  436.         term.setCursorPos(16,i+3)
  437.         term.write(string.format("%1d",i+3))
  438.     end
  439.     term.setBackgroundColor(colors.black)
  440.     term.setTextColor(colors.white)
  441.     term.setCursorPos(19,5)
  442.     term.write("Press")
  443.     term.setCursorPos(19,6)
  444.     term.write("\"Enter\"")
  445.     term.setCursorPos(19,7)
  446.     term.write("when")
  447.     term.setCursorPos(19,8)
  448.     term.write("done.")
  449. end
  450. function rollSize(argLength,argHeight,argColumn,argKey)
  451.     argLength = argLength or 3
  452.     argHeight = argHeight or 4
  453.     argHeight = argHeight or 1
  454.     argKey = argKey or 203
  455.     if (argKey == 200 or argKey==208) then
  456.         if argColumn==1 then
  457.             if argKey==200 then
  458.                 argLength = argLength-2
  459.             else
  460.                 argLength = argLength+2
  461.             end
  462.             if math.floor((argLength-1)/2)<1 then
  463.                 argLength = 9
  464.             elseif math.floor((argLength-1)/2)>4 then
  465.                 argLength = 3
  466.             end
  467.         else
  468.             if argKey==200 then
  469.                 argHeight = argHeight-1
  470.             else
  471.                 argHeight = argHeight+1
  472.             end
  473.             if argHeight > 8 then
  474.                 argHeight = 4
  475.             elseif argHeight < 4 then
  476.                 argHeight = 8
  477.             end
  478.         end
  479.     elseif (argKey == 203 or argKey==205 or argKey == 15) then
  480.         if argColumn == 1 then
  481.             argColumn = 2
  482.         else
  483.             argColumn = 1
  484.         end
  485.     end
  486.     length = argLength
  487.     width = argLength
  488.     height = argHeight
  489.     return argColumn
  490. end
  491. function printMenu(option)
  492.     option = option or selectedOption
  493.     selectedOption = option
  494.     if selectedOption < 1 then
  495.         selectedOption = maxOption
  496.     elseif selectedOption>maxOption then
  497.         selectedOption = 1
  498.     end
  499.     for i=1,#menu do
  500.         if i == selectedOption then highlight = 1 else highlight = 0 end
  501.         menuOptionPrint(i,menu[i],2+i,highlight)
  502.     end
  503. end
  504. function printNeed()
  505.     readyToBuild=1
  506.     --usedFuel=0
  507.     needWall = (length*width*2-2)+((height-2)*4)-placedWall
  508.     needGuage = 2*(length-2 + width - 2)*(height-2)-placedGuage
  509.     needFuel = 2*(length*width + 1) + (length+width-2)*2*(height-2)
  510.    
  511.     currentWall=0
  512.     for i=1,4 do
  513.         currentWall=currentWall+turtle.getItemCount(i)
  514.     end
  515.     term.setCursorPos(9,12)
  516.     term.write(string.format("%3d",needWall))
  517.     term.setCursorPos(9,13)
  518.     if (currentWall>=needWall) then
  519.         term.setBackgroundColor(colors.white)
  520.         term.setTextColor(colors.black)
  521.         wallString=" OK"
  522.     else
  523.         readyToBuild = 0
  524.         wallString=string.format("%3d",currentWall)
  525.     end
  526.     term.write(wallString)
  527.     term.setBackgroundColor(colors.black)
  528.     term.setTextColor(colors.white)
  529.     currentGuage=0
  530.     for i=5,8 do
  531.         currentGuage=currentGuage+turtle.getItemCount(i)
  532.     end
  533.     term.setCursorPos(17,12)
  534.     term.write(string.format("%3d",needGuage))
  535.     term.setCursorPos(17,13)
  536.     if (currentGuage>=needGuage) then
  537.         term.setBackgroundColor(colors.white)
  538.         term.setTextColor(colors.black)
  539.         guageString=" OK"
  540.     else
  541.         readyToBuild = 0
  542.         guageString=string.format("%3d",currentGuage)
  543.     end
  544.     term.write(guageString)
  545.     term.setBackgroundColor(colors.black)
  546.     term.setTextColor(colors.white)
  547.     currentValve=0
  548.     term.setCursorPos(25,12)
  549.     term.write(string.format("%3d",2-placedValve))
  550.     term.setCursorPos(25,13)
  551.     for i=9,12 do
  552.         currentValve=currentValve+turtle.getItemCount(i)
  553.     end
  554.     if (currentValve>=2-placedValve) then
  555.         term.setBackgroundColor(colors.white)
  556.         term.setTextColor(colors.black)
  557.         valveString=" OK"
  558.     else
  559.         readyToBuild = 0
  560.         valveString=string.format("%3d",currentValve)
  561.     end
  562.     term.write(valveString)
  563.     term.setBackgroundColor(colors.black)
  564.     term.setTextColor(colors.white)
  565.     currentFuelLevel = turtle.getFuelLevel()
  566.     term.setCursorPos(33,12)
  567.     term.write(string.format("%3d",needFuel-usedFuel))
  568.     term.setCursorPos(33,13)
  569.     if (currentFuelLevel>=needFuel-usedFuel) then
  570.         term.setBackgroundColor(colors.white)
  571.         term.setTextColor(colors.black)
  572.         fuelString=" OK"
  573.     else
  574.         readyToBuild = 0
  575.         fuelString=string.format("%3d",currentFuelLevel)
  576.     end
  577.     term.write(fuelString)
  578.     term.setBackgroundColor(colors.black)
  579.     term.setTextColor(colors.white)
  580. end
  581. function printSelectedSize()
  582.     term.setCursorPos(34,3)
  583.     term.write("Size=")
  584.     term.setCursorPos(34,4)
  585.     term.write(string.format("%1dx%1dx%1d",length,width,height))
  586.     term.setCursorPos(34,5)
  587.     term.write("L W H")
  588. end
  589. function printMainScreen()
  590.     term.clear()
  591.     centerPrint(" Build-a-Tank Turtle v. "..version,1,1)
  592.     printMenu(selectedOption)
  593.     printSelectedSize()
  594.     term.setCursorPos(1,11)
  595.     term.write("       Wall   Guage   Valve    Fuel")
  596.     term.setCursorPos(1,12)
  597.     term.write("NEED:")
  598.     term.setCursorPos(1,13)
  599.     term.write("HAVE:")
  600.     printNeed()
  601. end
  602. function printKey(arg)
  603.     term.setCursorPos(36,13)
  604.     term.write(string.format("%3d",arg))
  605. end
  606. function drawBuildDisplay()
  607.     drawBox(1)
  608.     local temp = string.format("Building %1dx%1dx%1d Tank",length,width,height)
  609.     term.setCursorPos(6+11-math.floor((#(temp))/2),4)
  610.     term.write(temp)
  611. end
  612. function rollMenu(arg)
  613.     if arg==200 then
  614.         selectedOption = selectedOption-1
  615.     else
  616.         selectedOption=selectedOption+1
  617.     end
  618.     printMenu()
  619. end
  620. function selectSize()
  621.     local result = 1
  622.     drawBox(1)
  623.     displaySizes(length,height,1)
  624.     while true do
  625.         local event,key = os.pullEvent("key")
  626.         if key == 28 then
  627.             return
  628.         end
  629.         result = rollSize(length,height,result,key)
  630.         printNeed()
  631.         printSelectedSize()
  632.         displaySizes(length,height,result)
  633.     end
  634.     drawBox(0)
  635. end
  636. function doMenu(arg)
  637.     if arg==1 then
  638.         displayHelp()
  639.         printMainScreen()
  640.         printMenu()
  641.         printNeed()
  642.     elseif arg==2 then
  643.         selectSize()
  644.         printMainScreen()
  645.         printMenu()
  646.         printNeed()
  647.     elseif arg==3 then
  648.         displayMove()
  649.         move()
  650.         printMenu()
  651.     elseif arg == 4 then
  652.         refuel()
  653.         printMenu()
  654.         printNeed()
  655.     elseif arg == 5 then
  656.         if readyToBuild == 1 then
  657.             build()
  658.             printMenu()
  659.         else
  660.             displayMessage("Need Items/Fuel","ERROR",0)
  661.             printMenu()
  662.         end
  663.     elseif arg == 6 then
  664.         term.clear()
  665.         term.setCursorPos(math.floor(39/2 - #"Shutting down turtle ..."/2),6)
  666.         textutils.slowWrite("Shutting down turtle ...", 10)
  667.         os.shutdown()
  668.         return 1
  669.     else
  670.         displayHelp()
  671.         printMainScreen()
  672.         printMenu()
  673.         printNeed()
  674.     end
  675.     return 0
  676. end
  677. function drawBox(arg)
  678.     arg = arg or 1
  679.     if arg== 1 then -- Draw box
  680.         term.setCursorPos(5,3)
  681.         term.setBackgroundColor(colors.white)
  682.         term.write(string.rep(" ",24))
  683.         for i = 1,6 do
  684.             term.setBackgroundColor(colors.white)
  685.             term.setCursorPos(5,3+i)
  686.             term.write(" ")
  687.             term.setCursorPos(28,3+i)
  688.             term.write(" ")
  689.             term.setCursorPos(6,3+i)
  690.             term.setBackgroundColor(colors.black)
  691.             term.write(string.rep(" ",22))    
  692.         end
  693.         term.setCursorPos(5,10)
  694.         term.setBackgroundColor(colors.white)
  695.         term.write(string.rep(" ",24))
  696.         term.setBackgroundColor(colors.black)
  697.     else -- Erase box
  698.         for i = 3,10 do
  699.             term.setCursorPos(5,i)
  700.             term.write(string.rep(" ",24))
  701.         end
  702.     end
  703.     term.setBackgroundColor(colors.black)
  704.     term.setTextColor(colors.white)
  705. end
  706. function displayMessage(message,title,timeout,message2)
  707.     title = title or ""
  708.     title = string.sub(title,1,22):find'^%s*$' and '' or string.sub(title,1,22):match'^%s*(.*%S)'
  709.     message = message or " 1 2 3 4 5 6 7 8 9 0 1 2 3 4 "
  710.     message = string.sub(message,1,22):find'^%s*$' and '' or string.sub(message,1,22):match'^%s*(.*%S)'
  711.     message2 = message2 or ""
  712.     message2 = string.sub(message2,1,22):find'^%s*$' and '' or string.sub(message2,1,22):match'^%s*(.*%S)'
  713.     timeout = timeout or 0
  714.     drawBox(1)
  715.     term.setCursorPos(6+11-math.floor((#(title))/2),4)
  716.     term.write(title)
  717.     term.setCursorPos(6+11-math.floor((#(message))/2),6)
  718.     term.write(message)
  719.     term.setCursorPos(6+11-math.floor((#(message2))/2),7)
  720.     term.write(message2)
  721.     if timeout == 0 then
  722.         term.setCursorPos(8,9)
  723.         term.write("(Press any key ...)")
  724.         os.pullEvent("key")
  725.         drawBox(0)
  726.     elseif timeout>0 then
  727.         os.sleep(timeout)
  728.         drawBox(0)
  729.     end
  730. end
  731.  
  732. function displayMove()
  733.     drawBox()
  734.     term.setBackgroundColor(colors.black)
  735.     term.setTextColor(colors.white)
  736.     term.setCursorPos(8,4)
  737.     term.write("Forward")
  738.     term.setCursorPos(20,4)
  739.     term.write("Up")
  740.     term.setCursorPos(7,6)
  741.     term.write("L")
  742.     term.setCursorPos(15,6)
  743.     term.write("R")
  744.     term.setCursorPos(10,8)
  745.     term.write("Back")
  746.     term.setCursorPos(18,8)
  747.     term.write("Down")
  748.     term.setCursorPos(6,9)
  749.     term.write("(Return key when done)")
  750.     term.setBackgroundColor(colors.white)
  751.     term.setTextColor(colors.black)
  752.     term.setCursorPos(10,5)
  753.     term.write(" W ")
  754.     term.setCursorPos(16,5)
  755.     term.write(" Up Arrow ")
  756.     term.setCursorPos(9,6)
  757.     term.write(" A ")
  758.     term.setCursorPos(12,6)
  759.     term.write("D ")
  760.     term.setCursorPos(10,7)
  761.     term.write(" S ")
  762.     term.setCursorPos(16,7)
  763.     term.write(" Dn Arrow ")
  764.     term.setBackgroundColor(colors.black)
  765.     term.setTextColor(colors.white)
  766. end
  767.  
  768. function displayHelp()
  769.     term.clear()
  770.     term.setCursorPos(5,1)
  771.     print("This turtle will build an iron or steel tank for you of any legal size. "..
  772.            "Building starts from its current position and continues forward and to the left. "..
  773.            "The turtle must be stocked with enough items and fuel to build the selected tank size (amounts are shown).")
  774.     term.setCursorPos(5,8)
  775.     print("Stock Inventory slots 1-4 with walls, 5-8 with walls or guages, 9-12 with valves and 13-16 with fuel items. "..
  776.         "You can set the tank size, position the turtle or refuel it as necessary.")
  777.     centerPrint("Press any key to return to menu.",13,1)
  778.     os.pullEvent(key)
  779.     term.clear()
  780. end
  781. --Begin Main Program
  782.  
  783. printMainScreen()
  784. while quit==0 do
  785.     local event, key = os.pullEvent("key")
  786.     printNeed()
  787.     if key==2 then
  788.         printMenu(1)
  789.     elseif key==3 then
  790.         printMenu(2)
  791.     elseif key==4 then
  792.         printMenu(3)
  793.     elseif key==5 then
  794.         printMenu(4)
  795.     elseif key==6 or key == 16 then
  796.         printMenu(5)
  797.     elseif key == 200 or key == 208 then
  798.         rollMenu(key)
  799.     elseif key == 28 then
  800.         quit = doMenu(selectedOption)
  801.    
  802.     end  
  803. end
Advertisement
Add Comment
Please, Sign In to add comment