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