SHOW:
|
|
- or go back to the newest paste.
| 1 | - | securityId = 1 |
| 1 | + | securityId = 0 |
| 2 | ||
| 3 | diskDrive = peripheral.wrap("bottom")
| |
| 4 | monitor = peripheral.wrap("top")
| |
| 5 | modem = peripheral.wrap("right")
| |
| 6 | radar = peripheral.wrap("left")
| |
| 7 | ||
| 8 | file = fs.open("reward","r")
| |
| 9 | if file then | |
| 10 | reward = file.readAll() | |
| 11 | file.close() | |
| 12 | else | |
| 13 | reward = "minecraft:coal" | |
| 14 | end | |
| 15 | ||
| 16 | - | file = fs.open("rewardCount","r")
|
| 16 | + | |
| 17 | if file then | |
| 18 | - | rewardCount = file.readAll() |
| 18 | + | |
| 19 | file.close() | |
| 20 | else | |
| 21 | - | rewardCount = 0 |
| 21 | + | |
| 22 | end | |
| 23 | ||
| 24 | file = fs.open("tokenCount","r")
| |
| 25 | if file then | |
| 26 | tokenCount = file.readAll() | |
| 27 | file.close() | |
| 28 | else | |
| 29 | tokenCount = 0 | |
| 30 | end | |
| 31 | ||
| 32 | --orientation | |
| 33 | while turtle.inspect() do | |
| 34 | turtle.turnRight() | |
| 35 | end | |
| 36 | ||
| 37 | local rewardCount = 0 | |
| 38 | ||
| 39 | playSide = "left" | |
| 40 | ||
| 41 | winRate = .4 | |
| 42 | winAmount = 2 | |
| 43 | ||
| 44 | adminScreen = false | |
| 45 | ||
| 46 | monitor.setTextScale(.5) | |
| 47 | ||
| 48 | local function checkRewards() | |
| 49 | file = fs.open("rewardCount","w")
| |
| 50 | ||
| 51 | turtle.turnRight() | |
| 52 | ||
| 53 | chest = peripheral.find("ironchest:crystal_chest")
| |
| 54 | ||
| 55 | items = chest.list() | |
| 56 | ||
| 57 | for _, item in ipairs(items) do | |
| 58 | if item.name == reward then | |
| 59 | rewardCount = rewardCount + item.count | |
| 60 | end | |
| 61 | end | |
| 62 | ||
| 63 | print("rewards: "..rewardCount)
| |
| 64 | ||
| 65 | file.write(rewardCount) | |
| 66 | file.close() | |
| 67 | - | monitor.write("Win!")
|
| 67 | + | |
| 68 | turtle.turnLeft() | |
| 69 | end | |
| 70 | ||
| 71 | checkRewards() | |
| 72 | ||
| 73 | local function checkWins(values) | |
| 74 | local wins = 0 | |
| 75 | ||
| 76 | for i=1,3 do | |
| 77 | if (values[i] == "X" and values[i+3] == "X" and values[i+6] == "X") then | |
| 78 | wins = wins + 1 | |
| 79 | end | |
| 80 | end | |
| 81 | ||
| 82 | return wins | |
| 83 | end | |
| 84 | ||
| 85 | local function doDisplay(values, win, credits) | |
| 86 | monitor.clear() | |
| 87 | ||
| 88 | monitor.setCursorPos(5,1) | |
| 89 | ||
| 90 | if win then | |
| 91 | monitor.write("You Win!")
| |
| 92 | boardShowsWin = false | |
| 93 | else | |
| 94 | monitor.write("You Lose")
| |
| 95 | boardShowsWin = true | |
| 96 | end | |
| 97 | ||
| 98 | local valuePool = {"O","O","O","O","O","O","X","X","X","X"}
| |
| 99 | ||
| 100 | local values = {}
| |
| 101 | ||
| 102 | while ((win and not boardShowsWin) or (not win and boardShowsWin)) and #values ~= 9 do | |
| 103 | for i=1,10 do | |
| 104 | values[i] = valuePool[math.random(1, 10)] | |
| 105 | end | |
| 106 | ||
| 107 | if checkWins(values) == 1 then | |
| 108 | boardShowsWin = true | |
| 109 | elseif checkWins(values) == 0 then | |
| 110 | boardShowsWin = false | |
| 111 | end | |
| 112 | end | |
| 113 | ||
| 114 | monitor.setCursorPos(5,3) | |
| 115 | monitor.write("+-+-+-+")
| |
| 116 | monitor.setCursorPos(5,4) | |
| 117 | monitor.write("|"..values[1].."|"..values[4].."|"..values[7].."|")
| |
| 118 | monitor.setCursorPos(5,5) | |
| 119 | monitor.write("+-+-+-+")
| |
| 120 | monitor.setCursorPos(5,6) | |
| 121 | monitor.write("|"..values[2].."|"..values[5].."|"..values[8].."|")
| |
| 122 | monitor.setCursorPos(5,7) | |
| 123 | monitor.write("+-+-+-+")
| |
| 124 | monitor.setCursorPos(5,8) | |
| 125 | monitor.write("|"..values[3].."|"..values[6].."|"..values[9].."|")
| |
| 126 | - | rewardCount = rewardCount - 1 |
| 126 | + | |
| 127 | monitor.write("+-+-+-+")
| |
| 128 | ||
| 129 | monitor.setCursorPos(1,10) | |
| 130 | - | local function screenSaver(credits) |
| 130 | + | |
| 131 | end | |
| 132 | ||
| 133 | - | monitor.write("Token:")
|
| 133 | + | |
| 134 | random = math.random(1, 10); | |
| 135 | - | i = string.find(token, ":") |
| 135 | + | |
| 136 | - | monitor.write(string.sub(token, i + 1)) |
| 136 | + | |
| 137 | ||
| 138 | if (random - 1 < 10 * winRate) then | |
| 139 | win = true | |
| 140 | end | |
| 141 | - | --i = string.find(reward, ":") |
| 141 | + | |
| 142 | - | --monitor.write(string.sub(reward, i + 1)) |
| 142 | + | |
| 143 | - | monitor.write("2 Coal Blocks")
|
| 143 | + | |
| 144 | if win then | |
| 145 | - | monitor.setCursorPos(3,6) |
| 145 | + | |
| 146 | turtle.suck(winAmount) | |
| 147 | turtle.turnLeft(1) | |
| 148 | turtle.drop(winAmount) | |
| 149 | - | monitor.setCursorPos(3,8) |
| 149 | + | |
| 150 | - | monitor.write("Add credits", 1)
|
| 150 | + | rewardCount = rewardCount - winAmount |
| 151 | ||
| 152 | file = fs.open("rewardCount","w")
| |
| 153 | file.write(rewardCount) | |
| 154 | file.close() | |
| 155 | end | |
| 156 | end | |
| 157 | ||
| 158 | local function screenSaver(credits) | |
| 159 | monitor.clear() | |
| 160 | monitor.setCursorPos(1,1) | |
| 161 | monitor.setTextColor(colors.yellow) | |
| 162 | monitor.write("Reward: "..rewardCount)
| |
| 163 | monitor.setTextColor(colors.white) | |
| 164 | monitor.setCursorPos(1,2) | |
| 165 | i = string.find(reward, ":") | |
| 166 | monitor.write(winAmount.." "..string.sub(reward, i + 1)) | |
| 167 | ||
| 168 | monitor.setCursorPos(3,5) | |
| 169 | monitor.write("Credits: "..credits, 0)
| |
| 170 | ||
| 171 | if (credits == 0) then | |
| 172 | tokenLen = #token | |
| 173 | ||
| 174 | if tokenLen > 8 and tokenLen < 12 then | |
| 175 | monitor.setCursorPos(1,7) | |
| 176 | elseif tokenLen > 11 then | |
| 177 | monitor.setCursorPos(7,7) | |
| 178 | else | |
| 179 | monitor.setCursorPos(3,7) | |
| 180 | end | |
| 181 | i = string.find(token, ":") | |
| 182 | monitor.write("Add ")
| |
| 183 | monitor.setTextColor(colors.yellow) | |
| 184 | ||
| 185 | if tokenLen > 11 then | |
| 186 | monitor.setCursorPos(1,8) | |
| 187 | end | |
| 188 | ||
| 189 | parsedToken = string.sub(token, i + 1) | |
| 190 | ||
| 191 | monitor.write(parsedToken) | |
| 192 | ||
| 193 | if tokenLen > 15 then | |
| 194 | monitor.setCursorPos(1,9) | |
| 195 | monitor.write(string.sub(parsedToken, 15)) | |
| 196 | end | |
| 197 | end | |
| 198 | ||
| 199 | if (credits > 0) then | |
| 200 | monitor.setCursorPos(1,8) | |
| 201 | monitor.write("Pull the lever")
| |
| 202 | monitor.setCursorPos(1,9) | |
| 203 | monitor.write("to play -->")
| |
| 204 | end | |
| 205 | end | |
| 206 | ||
| 207 | adminMenu = {
| |
| 208 | "Collect Tokens", | |
| 209 | "Change Token", | |
| 210 | "Add Reward", | |
| 211 | "Change Reward", | |
| 212 | "Exit" | |
| 213 | } | |
| 214 | ||
| 215 | selectedItem = 1; | |
| 216 | ||
| 217 | local function showAdminMenu() | |
| 218 | for i=1,#adminMenu do | |
| 219 | if (i == selectedItem) then | |
| 220 | monitor.setTextColor(colors.yellow) | |
| 221 | end | |
| 222 | monitor.setCursorPos(1,2+i) | |
| 223 | monitor.write(adminMenu[i]) | |
| 224 | monitor.setTextColor(colors.white) | |
| 225 | end | |
| 226 | end | |
| 227 | ||
| 228 | local function showAdminScreen() | |
| 229 | monitor.clear() | |
| 230 | monitor.setCursorPos(2,1) | |
| 231 | monitor.setTextColor(colors.red) | |
| 232 | monitor.write("Welcome Admin")
| |
| 233 | monitor.setTextColor(colors.white) | |
| 234 | monitor.setCursorPos(1,2) | |
| 235 | ||
| 236 | showAdminMenu() | |
| 237 | ||
| 238 | monitor.setCursorPos(1,9) | |
| 239 | monitor.write("Submit:")
| |
| 240 | monitor.setCursorPos(1,10) | |
| 241 | monitor.write("Insert Card")
| |
| 242 | end | |
| 243 | ||
| 244 | local function addReward() | |
| 245 | turtle.suckDown() | |
| 246 | turtle.drop() | |
| 247 | ||
| 248 | monitor.clear() | |
| 249 | monitor.setCursorPos(1,1) | |
| 250 | monitor.write("Add Reward:")
| |
| 251 | monitor.setCursorPos(1,2) | |
| 252 | monitor.write(reward) | |
| 253 | ||
| 254 | monitor.setCursorPos(1,4) | |
| 255 | monitor.write("Current Stock:")
| |
| 256 | monitor.setCursorPos(1,5) | |
| 257 | monitor.write(rewardCount) | |
| 258 | ||
| 259 | monitor.setCursorPos(1,7) | |
| 260 | monitor.write("Pull Lever")
| |
| 261 | monitor.setCursorPos(1,8) | |
| 262 | monitor.write("to Exit")
| |
| 263 | end | |
| 264 | ||
| 265 | local function collect(tokenChest) | |
| 266 | turtle.turnRight(1) | |
| 267 | ||
| 268 | if tokenChest then | |
| 269 | turtle.turnRight(1) | |
| 270 | end | |
| 271 | ||
| 272 | max = 16 | |
| 273 | ||
| 274 | while max == 16 do | |
| 275 | for i=1,max do | |
| 276 | turtle.suck() | |
| 277 | ||
| 278 | if turtle.getItemCount(i) ~= 0 and max ~= 16 then | |
| 279 | max = max + 1 | |
| 280 | end | |
| 281 | end | |
| 282 | ||
| 283 | turtle.turnLeft(1) | |
| 284 | ||
| 285 | if tokenChest then | |
| 286 | turtle.turnLeft(1) | |
| 287 | end | |
| 288 | ||
| 289 | emptySpace = turtle.getItemSpace() | |
| 290 | ||
| 291 | for i=1,max do | |
| 292 | turtle.select(i) | |
| 293 | turtle.drop() | |
| 294 | end | |
| 295 | ||
| 296 | max = emptySpace | |
| 297 | ||
| 298 | turtle.select(1) | |
| 299 | end | |
| 300 | end | |
| 301 | ||
| 302 | local function changeToken() | |
| 303 | turtle.suckDown() | |
| 304 | turtle.drop() | |
| 305 | ||
| 306 | monitor.clear() | |
| 307 | monitor.setCursorPos(1,1) | |
| 308 | monitor.write("Change Token")
| |
| 309 | monitor.setCursorPos(1,3) | |
| 310 | monitor.write("Drop the item")
| |
| 311 | ||
| 312 | monitor.setCursorPos(1,5) | |
| 313 | monitor.write("Current Token:")
| |
| 314 | monitor.setCursorPos(1,6) | |
| 315 | monitor.write(token) | |
| 316 | ||
| 317 | os.sleep(2) | |
| 318 | end | |
| 319 | ||
| 320 | local function changeReward() | |
| 321 | turtle.suckDown() | |
| 322 | turtle.drop() | |
| 323 | ||
| 324 | monitor.clear() | |
| 325 | monitor.setCursorPos(1,1) | |
| 326 | monitor.write("Change Reward")
| |
| 327 | monitor.setCursorPos(1,3) | |
| 328 | monitor.write("Drop the item")
| |
| 329 | ||
| 330 | monitor.setCursorPos(1,5) | |
| 331 | monitor.write("Current Reward:")
| |
| 332 | monitor.setCursorPos(1,6) | |
| 333 | monitor.write(reward) | |
| 334 | ||
| 335 | os.sleep(2) | |
| 336 | end | |
| 337 | ||
| 338 | local function addCredits() | |
| 339 | turtle.select(1) | |
| 340 | if (turtle.suck(64)) then | |
| 341 | item = turtle.getItemDetail(1) | |
| 342 | ||
| 343 | print(item.name) | |
| 344 | ||
| 345 | if (selectedItem == 2) and (item.name ~= "computercraft:disk") then | |
| 346 | tokenFile = fs.open("token",'w')
| |
| 347 | tokenFile.write(item.name) | |
| 348 | tokenFile.close() | |
| 349 | tokenCountFile = fs.open("tokenCount",'w')
| |
| 350 | tokenCountFile.write(0) | |
| 351 | tokenCountFile.close() | |
| 352 | ||
| 353 | token = item.name | |
| 354 | ||
| 355 | monitor.clear() | |
| 356 | monitor.setCursorPos(1,5) | |
| 357 | monitor.write("Token set:")
| |
| 358 | monitor.setCursorPos(1,6) | |
| 359 | monitor.write(item.name) | |
| 360 | ||
| 361 | os.sleep(2) | |
| 362 | ||
| 363 | collect(true) | |
| 364 | ||
| 365 | selectedItem = 1 | |
| 366 | adminScreen = false | |
| 367 | elseif (selectedItem == 3) then | |
| 368 | if rs.getInput(playSide) then | |
| 369 | monitor.clear() | |
| 370 | showAdminScreen() | |
| 371 | elseif (item.name == reward) then | |
| 372 | turtle.turnRight(1) | |
| 373 | turtle.drop(64) | |
| 374 | turtle.turnLeft(1) | |
| 375 | ||
| 376 | rewardCount = rewardCount + item.count | |
| 377 | ||
| 378 | rewardCountFile = fs.open("rewardCount",'w')
| |
| 379 | rewardCountFile.write(rewardCount) | |
| 380 | rewardCountFile.close() | |
| 381 | ||
| 382 | addReward() | |
| 383 | else | |
| 384 | addReward() | |
| 385 | end | |
| 386 | - | modem.transmit(816, 714, securityId..": "..diskDrive.getDiskID().."="..password) |
| 386 | + | |
| 387 | rewardFile = fs.open("reward","w")
| |
| 388 | rewardFile.write(item.name) | |
| 389 | rewardFile.close() | |
| 390 | rewardCountFile = fs.open("rewardCount",'w')
| |
| 391 | rewardCountFile.write(0) | |
| 392 | rewardCountFile.close() | |
| 393 | ||
| 394 | reward = item.name | |
| 395 | rewardCount = 0 | |
| 396 | ||
| 397 | monitor.clear() | |
| 398 | monitor.setCursorPos(1,5) | |
| 399 | monitor.write("Reward set:")
| |
| 400 | monitor.setCursorPos(1,6) | |
| 401 | monitor.write(item.name) | |
| 402 | ||
| 403 | os.sleep(2) | |
| 404 | ||
| 405 | turtle.drop() | |
| 406 | ||
| 407 | collect(false) | |
| 408 | ||
| 409 | selectedItem = 1 | |
| 410 | adminScreen = false | |
| 411 | elseif (item.name == token) then | |
| 412 | count = item.count | |
| 413 | ||
| 414 | turtle.turnRight(1) | |
| 415 | turtle.turnRight(1) | |
| 416 | turtle.drop(64) | |
| 417 | turtle.turnLeft(1) | |
| 418 | turtle.turnLeft(1) | |
| 419 | ||
| 420 | tokenCount = tokenCount + count | |
| 421 | ||
| 422 | credits = credits + count | |
| 423 | ||
| 424 | screenSaver(credits) | |
| 425 | elseif (item.name == "computercraft:disk") then | |
| 426 | monitor.clear() | |
| 427 | monitor.setCursorPos(1,5) | |
| 428 | monitor.setTextColor(colors.yellow) | |
| 429 | monitor.write("Authenticating...")
| |
| 430 | ||
| 431 | turtle.dropDown() | |
| 432 | file = fs.open("disk/keycard", "r")
| |
| 433 | ||
| 434 | if file then | |
| 435 | password = file.readAll() | |
| 436 | file.close() | |
| 437 | ||
| 438 | modem.open(714) | |
| 439 | modem.transmit(816, 714, securityId..":"..diskDrive.getDiskID().."="..password) | |
| 440 | event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
| |
| 441 | ||
| 442 | if message then | |
| 443 | turtle.suckDown() | |
| 444 | turtle.drop() | |
| 445 | ||
| 446 | if not adminScreen then | |
| 447 | showAdminScreen() | |
| 448 | adminScreen = true | |
| 449 | - | if (turtle.suck()) then |
| 449 | + | |
| 450 | - | addCredits() |
| 450 | + | |
| 451 | elseif selectedItem == 3 then | |
| 452 | addReward() | |
| 453 | elseif selectedItem == 2 then | |
| 454 | changeToken() | |
| 455 | elseif selectedItem == 1 then | |
| 456 | collect(true) | |
| 457 | else | |
| 458 | adminScreen = false | |
| 459 | selectedItem = 1 | |
| 460 | end | |
| 461 | else | |
| 462 | monitor.clear() | |
| 463 | monitor.setCursorPos(1,5) | |
| 464 | monitor.setTextColor(colors.red) | |
| 465 | monitor.write("Non-Owner Key.")
| |
| 466 | end | |
| 467 | end | |
| 468 | ||
| 469 | turtle.suckDown() | |
| 470 | end | |
| 471 | turtle.drop() | |
| 472 | os.sleep(2) | |
| 473 | end | |
| 474 | end | |
| 475 | - | |
| 475 | + | |
| 476 | local function main() | |
| 477 | credits = 0 | |
| 478 | ||
| 479 | players = radar.getPlayersInRange(2) | |
| 480 | ||
| 481 | if #players > 0 then | |
| 482 | player = players[1] | |
| 483 | rs.setOutput("bottom", true)
| |
| 484 | --print(player) | |
| 485 | else | |
| 486 | rs.setOutput("bottom", false)
| |
| 487 | end | |
| 488 | ||
| 489 | if adminScreen then | |
| 490 | if rs.getInput(playSide) then | |
| 491 | if selectedItem == #adminMenu then | |
| 492 | selectedItem = 1 | |
| 493 | else | |
| 494 | selectedItem = selectedItem + 1 | |
| 495 | end | |
| 496 | ||
| 497 | showAdminScreen() | |
| 498 | os.sleep(1) | |
| 499 | end | |
| 500 | else | |
| 501 | screenSaver(credits) | |
| 502 | end | |
| 503 | ||
| 504 | addCredits() | |
| 505 | ||
| 506 | while credits > 0 do | |
| 507 | addCredits() | |
| 508 | ||
| 509 | os.pullEvent("redstone")
| |
| 510 | ||
| 511 | if (rs.getInput(playSide) and credits > 0) then | |
| 512 | ||
| 513 | play(credits) | |
| 514 | ||
| 515 | credits = credits - 1 | |
| 516 | ||
| 517 | if (credits == 0) then | |
| 518 | os.sleep(5) | |
| 519 | end | |
| 520 | end | |
| 521 | ||
| 522 | if (credits == 0 and not adminScreen) then | |
| 523 | screenSaver(0) | |
| 524 | end | |
| 525 | end | |
| 526 | end | |
| 527 | ||
| 528 | while true do | |
| 529 | main() | |
| 530 | end |