SHOW:
|
|
- or go back to the newest paste.
| 1 | t = turtle | |
| 2 | function moveForward() | |
| 3 | if t.detect() then | |
| 4 | t.dig() | |
| 5 | t.forward() | |
| 6 | else | |
| 7 | t.forward() | |
| 8 | end | |
| 9 | end | |
| 10 | function moveUpward() | |
| 11 | if t.detectUp() then | |
| 12 | t.digUp() | |
| 13 | t.up() | |
| 14 | else | |
| 15 | t.up() | |
| 16 | end | |
| 17 | end | |
| 18 | function moveDownward() | |
| 19 | - | t.refuel(distance/80) |
| 19 | + | if t.detectDown() then |
| 20 | t.digDown() | |
| 21 | t.down() | |
| 22 | else | |
| 23 | t.down() | |
| 24 | end | |
| 25 | end | |
| 26 | function fuelTurtle(distance) | |
| 27 | t.refuel((distance/80)+1) | |
| 28 | end | |
| 29 | function moveDistanceForward(distance) | |
| 30 | while distance > 0 do | |
| 31 | moveForward() | |
| 32 | distance = distance - 1 | |
| 33 | end | |
| 34 | end | |
| 35 | function moveDistanceUpward(distance) | |
| 36 | while distance > 0 do | |
| 37 | moveUpward() | |
| 38 | distance = distance - 1 | |
| 39 | end | |
| 40 | end | |
| 41 | function moveDistanceDownward(distance) | |
| 42 | while distance > 0 do | |
| 43 | moveDownward() | |
| 44 | distance = distance - 1 | |
| 45 | end | |
| 46 | end | |
| 47 | function distanceInput() | |
| 48 | print("Input distance: ")
| |
| 49 | num = io.read() | |
| 50 | num = tonumber(num) | |
| 51 | return num | |
| 52 | - | print("Input distance: ")
|
| 52 | + | |
| 53 | function turnAround() | |
| 54 | t.turnLeft() | |
| 55 | t.turnLeft() | |
| 56 | - | t.refuel(1) |
| 56 | + | |
| 57 | function moveUp() | |
| 58 | if t.detectUp() then | |
| 59 | t.digUp() | |
| 60 | - | moveDistance(distance) |
| 60 | + | |
| 61 | else | |
| 62 | t.up() | |
| 63 | end | |
| 64 | - | print("Input distance: ")
|
| 64 | + | |
| 65 | --------------- | |
| 66 | function shaft() | |
| 67 | - | |
| 67 | + | |
| 68 | fuelTurtle(distance*2) | |
| 69 | moveDistanceForward(distance) | |
| 70 | moveUp() | |
| 71 | turnAround() | |
| 72 | moveDistanceForward(distance) | |
| 73 | end | |
| 74 | ||
| 75 | function hole() | |
| 76 | distance = distanceInput() | |
| 77 | print("Return? 0 = no, 1 = yes")
| |
| 78 | yon = tonumber(io.read()) | |
| 79 | fuelTurtle(distance) | |
| 80 | moveDistanceDownward(distance) | |
| 81 | fuelTurtle(distance) | |
| 82 | if not yon == 0 then | |
| 83 | moveDistanceUpward(distance) | |
| 84 | end | |
| 85 | end | |
| 86 | -------------- | |
| 87 | function main() | |
| 88 | print("1 = Shaft, 2 = Hole")
| |
| 89 | func = io.read() | |
| 90 | func = tonumber(func) | |
| 91 | if func == 1 then | |
| 92 | shaft() | |
| 93 | elif func == 2 then | |
| 94 | hole() | |
| 95 | else | |
| 96 | print("Please input a valid function")
| |
| 97 | end | |
| 98 | end | |
| 99 | ||
| 100 | main() |