Advertisement
CaptainSpaceCat

Spaceteam - Latest Stable Version

Jun 1st, 2015
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 25.18 KB | None | 0 0
  1. if not fs.exists("space.nfp") then
  2.   oFile = fs.open("space.nfp", "w")
  3.   oFile.writeLine(" 000000")
  4.   oFile.writeLine(" 00 00")
  5.   oFile.writeLine("000 00")
  6.   oFile.flush()
  7.   oFile.close()
  8. end
  9.  
  10. if not fs.exists("dial.nfp") then
  11.   oFile = fs.open("dial.nfp", "w")
  12.   oFile.writeLine(" 777 ")
  13.   oFile.writeLine("77777")
  14.   oFile.writeLine("77777")
  15.   oFile.writeLine(" 777 ")
  16.   oFile.flush()
  17.   oFile.close()
  18. end
  19.  
  20. if not fs.exists("buttonOn.nfp") then
  21.   oFile = fs.open("buttonOn.nfp", "w")
  22.   oFile.writeLine("77777")
  23.   oFile.writeLine("7eee7")
  24.   oFile.writeLine("7eee7")
  25.   oFile.writeLine("77777")
  26.   oFile.flush()
  27.   oFile.close()
  28. end
  29.  
  30. if not fs.exists("buttonOff.nfp") then
  31.   oFile = fs.open("buttonOff.nfp", "w")
  32.   oFile.writeLine("77777")
  33.   oFile.writeLine("78887")
  34.   oFile.writeLine("78887")
  35.   oFile.writeLine("77777")
  36.   oFile.flush()
  37.   oFile.close()
  38. end
  39.  
  40. if not fs.exists("sliderX.nfp") then
  41.   oFile = fs.open("sliderX.nfp", "w")
  42.   oFile.writeLine("878")
  43.   oFile.flush()
  44.   oFile.close()
  45. end
  46.  
  47. if not fs.exists("sliderY.nfp") then
  48.   oFile = fs.open("sliderY.nfp", "w")
  49.   oFile.writeLine("8")
  50.   oFile.writeLine("7")
  51.   oFile.writeLine("8")
  52.   oFile.flush()
  53.   oFile.close()
  54. end
  55.  
  56. rednet.open("back")
  57. function spacewrite(string, x, y, txtcol, bakcol)
  58.   if txtcol then
  59.     term.setTextColor(txtcol)
  60.   end
  61.   if bakcol then
  62.     term.setBackgroundColor(bakcol)
  63.   end
  64.   term.setCursorPos(x, y)
  65.   term.write(string)
  66. end
  67. w, h = term.getSize()
  68. term.setBackgroundColor(colors.black)
  69. term.clear()
  70. local logo = paintutils.loadImage("space.nfp")
  71. local dial = paintutils.loadImage("dial.nfp")
  72. local sliderX = paintutils.loadImage("sliderX.nfp")
  73. local sliderY = paintutils.loadImage("sliderY.nfp")
  74. local buttonOn = paintutils.loadImage("buttonOn.nfp")
  75. local buttonOff = paintutils.loadImage("buttonOff.nfp")
  76. paintutils.drawImage(logo, 10, 2)
  77. spacewrite("SpaceTeam", 9, 5, colors.white, colors.black)
  78. --spacewrite("Start Game", 9, h, colors.white, colors.black)
  79. local start = false
  80. local x = nil
  81. local y = nil
  82. local tempX = nil
  83. local tempY = nil
  84. clickables = {}
  85.  
  86. ------======DEFINES DIALS======------
  87. function defDial(dialX, dialY, dialName)
  88.   term.setTextColor(colors.white)
  89.   clickables[#clickables + 1] = {}
  90.     clickables[#clickables][1] = dialX
  91.     clickables[#clickables][2] = dialY
  92.     clickables[#clickables][3] = dialName
  93.     clickables[#clickables][4] = "Dial"
  94.     clickables[#clickables][5] = 1
  95.   paintutils.drawImage(dial, dialX, dialY)
  96.   term.setCursorPos(dialX, dialY + 3)
  97.   term.setBackgroundColor(colors.lightGray)
  98.   term.write("/")
  99.   term.setBackgroundColor(colors.black)
  100.   term.setCursorPos(dialX - 1, dialY + 4)
  101.   term.write("1")
  102.   term.setCursorPos(dialX - 2, dialY + 1)
  103.   term.write("2")
  104.   term.setCursorPos(dialX - 1, dialY - 1)
  105.   term.write("3")
  106.   term.setCursorPos(dialX + 2, dialY - 2)
  107.   term.write("4")
  108.   term.setCursorPos(dialX + 5, dialY - 1)
  109.   term.write("5")
  110.   term.setCursorPos(dialX + 6, dialY + 1)
  111.   term.write("6")
  112.   term.setCursorPos(dialX + 5, dialY + 4)
  113.   term.write("7")
  114.   term.setCursorPos(dialX - #dialName / 2 + 3, dialY + 5)
  115.   term.write(dialName)
  116. end
  117.  
  118.  
  119. ------======DEFINES SWITCHES======------
  120. function defSwitch(switchX, switchY, switchDir, switchState, switchName)
  121.   clickables[#clickables + 1] = {}
  122.     clickables[#clickables][1] = switchX
  123.     clickables[#clickables][2] = switchY
  124.     clickables[#clickables][3] = switchName
  125.     clickables[#clickables][4] = "Switch"
  126.     clickables[#clickables][5] = switchState
  127.     clickables[#clickables][6] = switchDir
  128.   term.setCursorPos(switchX, switchY)
  129.   term.setBackgroundColor(colors.gray)
  130.   term.write(" ")
  131.   term.setBackgroundColor(colors.lightGray)
  132.   if switchDir == "X" then
  133.     if switchState == true then
  134.       term.setCursorPos(switchX + 1, switchY)
  135.       term.write("   ")
  136.     else
  137.       term.setCursorPos(switchX - 3, switchY)
  138.       term.write("   ")
  139.     end
  140.     term.setBackgroundColor(colors.black)
  141.     term.setTextColor(colors.white)
  142.     term.setCursorPos(switchX + 4, switchY)
  143.     term.write("O")
  144.     term.setCursorPos(switchX - 4, switchY)
  145.     term.write("X")
  146.     term.setCursorPos(switchX - #switchName / 2 + 1, switchY + 1)
  147.     term.write(switchName)
  148.   elseif switchDir == "Y" then
  149.     if switchState == true then
  150.       for i = 3, 1, -1 do
  151.         term.setCursorPos(switchX, switchY - i)
  152.         term.write(" ")
  153.       end
  154.     else
  155.       for i = 1, 3 do
  156.         term.setCursorPos(switchX, switchY + i)
  157.         term.write(" ")
  158.       end
  159.     end
  160.     term.setBackgroundColor(colors.black)
  161.     term.setTextColor(colors.white)
  162.     term.setCursorPos(switchX, switchY - 4)
  163.     term.write("O")
  164.     term.setCursorPos(switchX, switchY + 4)
  165.     term.write("X")
  166.     term.setCursorPos(switchX - #switchName / 2 + 1, switchY + 5)
  167.     term.write(switchName)
  168.   end
  169. end
  170.  
  171. ------======DEFINES BUTTONS======------
  172. function defButton(butX, butY, butState, butName)
  173.   term.setBackgroundColor(colors.black)
  174.   term.setTextColor(colors.white)
  175.   clickables[#clickables + 1] = {}
  176.     clickables[#clickables][1] = butX
  177.     clickables[#clickables][2] = butY
  178.     clickables[#clickables][3] = butName
  179.     clickables[#clickables][4] = "Button"
  180.     clickables[#clickables][5] = butState
  181.   term.setCursorPos(butX - #butName / 2 + 3, butY + 5)
  182.   term.write(butName)
  183.   if butState == true then
  184.     paintutils.drawImage(buttonOn, butX, butY)
  185.   else
  186.     paintutils.drawImage(buttonOff, butX, butY)
  187.   end
  188. end
  189.  
  190. ------======DEFINES SLIDERS======------
  191. function defSlider(slideX, slideY, slideDir, slideName)
  192.   term.setBackgroundColor(colors.black)
  193.   term.setTextColor(colors.white)
  194.   clickables[#clickables + 1] = {}
  195.     clickables[#clickables][1] = slideX
  196.     clickables[#clickables][2] = slideY
  197.     clickables[#clickables][3] = slideName
  198.     clickables[#clickables][4] = "Slider"
  199.     clickables[#clickables][5] = 0
  200.     clickables[#clickables][6] = slideDir
  201.   if slideDir == "X" then
  202.     for i = 0, 6 do
  203.       term.setCursorPos(slideX + i, slideY)
  204.       term.write("-")
  205.     end
  206.     for c = 0, 3 do
  207.       term.setCursorPos(slideX + c * 2, slideY - 1)
  208.       if c == 0.0 then
  209.         term.write(0)
  210.       elseif c == 1.0 then
  211.         term.write(1)
  212.       elseif c == 2.0 then
  213.         term.write(2)
  214.       elseif c == 3.0 then
  215.         term.write(3)
  216.       end
  217.     end
  218.     paintutils.drawImage(sliderX, slideX - 1, slideY)
  219.     term.setBackgroundColor(colors.black)
  220.     term.setTextColor(colors.white)
  221.     term.setCursorPos(slideX, slideY + 1)
  222.     term.write(slideName)
  223.   elseif slideDir == "Y" then
  224.     for i = 0, 6 do
  225.       term.setCursorPos(slideX, slideY + i)
  226.       term.write("|")
  227.     end
  228.     for i = 0, 3 do
  229.       term.setCursorPos(slideX - 1, slideY + 6 - i * 2)
  230.       term.write(i)
  231.     end
  232.     paintutils.drawImage(sliderY, slideX, slideY + 5)
  233.     term.setBackgroundColor(colors.black)
  234.     term.setTextColor(colors.white)
  235.     term.setCursorPos(slideX - #slideName / 2 + 1, slideY + 8)
  236.     term.write(slideName)
  237.   end
  238. end
  239.  
  240. ------======CHECKS SWITCHES======------
  241. function checkSwitch(switchX, switchY)
  242.   if e == "mouse_click" then
  243.     tempX = x
  244.     tempY = y
  245.   end
  246.   if clickables[num][6] == "X" then
  247.     if clickables[num][5] == true then
  248.       if m == 1 and (tempX >= switchX + 1 and tempX <= switchX + 3 and tempY == switchY) and (x >= switchX - 3 and x <= switchX - 1 and y == switchY) then
  249.         clickables[num][5] = false
  250.         response = false
  251.       end
  252.     else
  253.       if m == 1 and (tempX >= switchX - 3 and tempX <= switchX - 1 and tempY == switchY) and (x >= switchX + 1 and x <= switchX + 3 and y == switchY) then
  254.         clickables[num][5] = true
  255.         response = true
  256.       end
  257.     end
  258.     term.setCursorPos(switchX - 3, switchY)
  259.     if clickables[num][5] == true then
  260.       term.setBackgroundColor(colors.black)
  261.     else
  262.       term.setBackgroundColor(colors.lightGray)
  263.     end
  264.     term.write("   ")
  265.     term.setCursorPos(switchX + 1, switchY)
  266.     if clickables[num][5] == true then
  267.       term.setBackgroundColor(colors.lightGray)
  268.     else
  269.       term.setBackgroundColor(colors.black)
  270.     end
  271.     term.write("   ")
  272.   elseif clickables[num][6] == "Y" then
  273.     if clickables[num][5] == true then
  274.       if m == 1 and (tempY >= switchY - 3 and tempY <= switchY - 1 and tempX == switchX) and (y >= switchY + 1 and y <= switchY + 3 and x == switchX) then
  275.         clickables[num][5] = false
  276.         response = false
  277.       end
  278.     else
  279.       if m == 1 and (tempY >= switchY + 1 and tempY <= switchY + 3 and tempX == switchX) and (y >= switchY - 3 and y <= switchY - 1 and x == switchX) then
  280.         clickables[num][5] = true
  281.         response = true
  282.       end
  283.     end
  284.     if clickables[num][5] == true then
  285.       term.setBackgroundColor(colors.lightGray)
  286.     else
  287.       term.setBackgroundColor(colors.black)
  288.     end
  289.     for i = 3, 1, -1 do
  290.       term.setCursorPos(switchX, switchY - i)
  291.       term.write(" ")
  292.     end
  293.     if clickables[num][5] == true then
  294.       term.setBackgroundColor(colors.black)
  295.     else
  296.       term.setBackgroundColor(colors.lightGray)
  297.     end
  298.     for i = 1, 3 do
  299.       term.setCursorPos(switchX, switchY + i)
  300.       term.write(" ")
  301.     end
  302.   end
  303. end
  304.  
  305. ------======CHECKS BUTTONS======------
  306. function checkButton(butX, butY)
  307.   if clickables[num][5] == true then
  308.     clickables[num][5] = false
  309.     term.setCursorPos(butX, butY)
  310.     paintutils.drawImage(buttonOff, butX, butY)
  311.     response = false
  312.   else
  313.     clickables[num][5] = true
  314.     term.setCursorPos(butX, butY)
  315.     paintutils.drawImage(buttonOn, butX, butY)
  316.     response = true
  317.   end
  318. end
  319.  
  320. ------======CHECKS SLIDERS======------
  321. function checkSlider(slideX, slideY)
  322.   term.setBackgroundColor(colors.black)
  323.   if clickables[num][6] == "X" and m == 1 and (x >= clickables[num][1] + clickables[num][5] * 2 - 1 and x <= clickables[num][1] + clickables[num][5] * 2 + 1) and (x >= clickables[num][1] and x <= clickables[num][1] + 6) and y == clickables[num][2] and e == "mouse_drag" then
  324.     for i = 0, 6 do
  325.       term.setCursorPos(slideX + i, slideY)
  326.       term.write("-")
  327.     end
  328.     term.setCursorPos(slideX - 1, slideY)
  329.     term.write(" ")
  330.     term.setCursorPos(slideX + 7, slideY)
  331.     term.write(" ")
  332.     paintutils.drawImage(sliderX, x - 1, y)
  333.     clickables[num][5] = (x - slideX) / 2
  334.     response = (x - slideX) / 2
  335.   elseif clickables[num][6] == "Y" and m == 1 and (y <= clickables[num][2] + 6 - (clickables[num][5] * 2 - 1) and y >= clickables[num][2] + 6 - (clickables[num][5] * 2 + 1)) and (y >= clickables[num][2] and y <= clickables[num][2] + 6) and x == clickables[num][1] and e == "mouse_drag" then
  336.     for i = 0, 6 do
  337.       term.setCursorPos(slideX, slideY + i)
  338.       term.write("|")
  339.     end
  340.     term.setCursorPos(slideX, slideY - 1)
  341.     term.write(" ")
  342.     term.setCursorPos(slideX, slideY + 7)
  343.     term.write(" ")
  344.     paintutils.drawImage(sliderY, x, y - 1)
  345.     clickables[num][5] = (slideY + 6 - y) / 2
  346.     response = (slideY + 6 - y) / 2
  347.   end
  348. end
  349.  
  350. ------======CHECKS DIALS======------
  351. function checkDial(dialX, dialY)
  352.   term.setBackgroundColor(colors.black)
  353.   term.setCursorPos(dialX, dialY + 3)
  354.   term.write(" ")
  355.   term.setCursorPos(dialX - 1, dialY + 2)
  356.   term.write(" ")
  357.   term.setCursorPos(dialX - 1, dialY + 1)
  358.   term.write(" ")
  359.   term.setCursorPos(dialX, dialY)
  360.   term.write(" ")
  361.   term.setCursorPos(dialX + 1, dialY - 1)
  362.   term.write(" ")
  363.   term.setCursorPos(dialX + 2, dialY - 1)
  364.   term.write(" ")
  365.   term.setCursorPos(dialX + 3, dialY - 1)
  366.   term.write(" ")
  367.   term.setCursorPos(dialX + 4, dialY)
  368.   term.write(" ")
  369.   term.setCursorPos(dialX + 5, dialY + 1)
  370.   term.write(" ")
  371.   term.setCursorPos(dialX + 5, dialY + 2)
  372.   term.write(" ")
  373.   term.setCursorPos(dialX + 4, dialY + 3)
  374.   term.write(" ")
  375.   if x <= dialX and y >= dialY + 3 then
  376.     xPos, yPos = dialX, dialY + 3
  377.     mark = "/"
  378.     clickables[num][5] = 1
  379.     response = 1
  380.   elseif x < dialX and y > dialY and y < dialY + 3 then
  381.     xPos, yPos = dialX - 1, y
  382.     mark = "-"
  383.     clickables[num][5] = 2
  384.     response = 2
  385.   elseif x <= dialX and y <= dialY then
  386.     xPos, yPos = dialX, dialY
  387.     mark = "\\"
  388.     clickables[num][5] = 3
  389.     response = 3
  390.   elseif x > dialX and x < dialX + 4 and y < dialY then
  391.     xPos, yPos = x, dialY - 1
  392.     mark = "|"
  393.     clickables[num][5] = 4
  394.     response = 4
  395.   elseif x >= dialX + 4 and y <= dialY then
  396.     xPos, yPos = dialX + 4, dialY
  397.     mark = "/"
  398.     clickables[num][5] = 5
  399.     response = 5
  400.   elseif x > dialX + 4 and y < dialY + 3 then
  401.     xPos, yPos = dialX + 5, y
  402.     mark = "-"
  403.     clickables[num][5] = 6
  404.     response = 6
  405.   elseif x >= dialX + 4 and y >= dialY + 3 then
  406.     xPos, yPos = dialX + 4, dialY + 3
  407.     mark = "\\"
  408.     clickables[num][5] = 7
  409.     response = 7
  410.   end
  411.   term.setBackgroundColor(colors.lightGray)
  412.   term.setCursorPos(xPos, yPos)
  413.   term.write(mark)
  414. end
  415.  
  416. ------======CHECKS ALL 4 TYPES EVERY TIME THERE IS A CLICK======------
  417. function clickCheck()
  418.   response = nil
  419.   --print(x, " ", y, " ", m, " ", i)
  420.   if m == 1 and x >= clickables[num][1] - 1 and x <= clickables[num][1] + 5 and y >= clickables[num][2] - 1 and y <= clickables[num][2] + 4 then
  421.     if clickables[num][4] == "Dial" and e == "mouse_drag" then
  422.       checkDial(clickables[num][1], clickables[num][2])
  423.     elseif clickables[num][4] == "Button" and e == "mouse_click" then
  424.       checkButton(clickables[num][1], clickables[num][2])
  425.     end
  426.   end
  427.   if clickables[num][4] == "Switch" then
  428.     checkSwitch(clickables[num][1], clickables[num][2])
  429.   elseif clickables[num][4] == "Slider" and e == "mouse_drag" then
  430.     checkSlider(clickables[num][1], clickables[num][2])
  431.   end
  432. end
  433.  
  434. function click()
  435.   e, m, x, y = os.pullEvent("mouse_click")
  436. end
  437.  
  438. function drag()
  439.   e, m, x, y = os.pullEvent("mouse_drag")
  440. end
  441.  
  442. ------======START MENU======------
  443. --defSwitch(5, 11, "X", false, "StartX")
  444. --defSwitch(11, 10, "Y", true, "StartY")
  445. --defSlider(11, 8, "X", "StartX")
  446. --defSlider(11, 12, "Y", "StartY")
  447. --defButton(11, 10, false, "Start")
  448. defDial(11, 10, "Start")
  449. while not start do
  450.   e, m, x, y = nil, nil, nil, nil
  451.   parallel.waitForAny(click, drag)
  452.   num = 1
  453.   for i = 1, #clickables do
  454.     clickCheck()
  455.     num = num + 1
  456.     if response == 7 then
  457.       start = true
  458.     end
  459.   end
  460. end
  461.  
  462. sleep(.3)
  463. term.setBackgroundColor(colors.black)
  464. term.clear()
  465. sleep(.3)
  466. term.setBackgroundColor(colors.gray)
  467. term.clear()
  468. sleep(.3)
  469. term.setBackgroundColor(colors.lightGray)
  470. term.clear()
  471. sleep(.3)
  472. term.setBackgroundColor(colors.white)
  473. term.clear()
  474. sleep(.3)
  475.  
  476.  
  477. ------======COMPUTERS CONNECT======------
  478. term.setBackgroundColor(colors.black)
  479. term.clear()
  480. spacewrite("Searching for signals...", 2, 1, colors.white, colors.black)
  481. clickables = {}
  482. response = nil
  483. local id = nil
  484. local host = nil
  485. local cast = "ping"
  486. local connected = false
  487. while not connected do
  488.   rednet.broadcast(cast)
  489.   spacewrite("Searching for signals...", 2, 1, colors.white, colors.black)
  490.   local randX = math.random(1, w)
  491.   local randY = math.random(2, h)
  492.   local randMark = math.random(1, 2)
  493.   if randMark == 1 then
  494.     spacewrite("*", randX, randY, colors.white, colors.black)
  495.   else
  496.     spacewrite(" ", randX, randY, colors.white, colors.black)
  497.   end
  498.   --print(cast .. "...")
  499.   otherID, response = rednet.receive(.01)
  500.   if response == "ping" or response == "ready" then
  501.     id = otherID
  502.     host = true
  503.     --print("Ping Recieved")
  504.   end
  505.   if id then cast = "ready" end
  506.   if response == "ready" and id then
  507.     rednet.broadcast("ready")
  508.     connected = true
  509.     term.clear()
  510.     term.setCursorPos(1, 1)
  511.     --print("Connected to id: " ..id)
  512.   end
  513. end
  514.  
  515. term.setBackgroundColor(colors.black)
  516. term.clear()
  517. for i = w, -8, -1 do
  518.   term.setBackgroundColor(colors.white)
  519.   term.clear()
  520.   spacewrite("Team Up!", i, 10, colors.lightBlue, colors.white)
  521.   sleep(.01)
  522.   term.setBackgroundColor(colors.black)
  523.   term.clear()
  524.   spacewrite("Team Up!", i, 10, colors.orange, colors.black)
  525.   sleep(.01)
  526. end
  527.  
  528. function receive()
  529.   e, id, message = os.pullEvent("rednet_message")
  530. end
  531.  
  532. function key()
  533.   e, string = os.pullEvent("char")
  534.   --rednet.send(id, string)
  535. end
  536.  
  537. local toggle = false
  538. function w8()
  539.   sleep(.1)
  540.   countnum = countnum - .1
  541.   spacewrite("  ", done + 2, 1, colors.white, colors.lightGray)
  542.   if toggle then
  543.     toggle = false
  544.     term.setBackgroundColor(colors.blue)
  545.   else
  546.     toggle = true
  547.     term.setBackgroundColor(colors.lightBlue)
  548.   end
  549.   term.setCursorPos(done + 1, 1)
  550.   term.write(" ")
  551.   rednet.send(id, taskwrite)
  552. end
  553.  
  554.  
  555. ------======PANEL GENERATOR======------
  556. names = {"Quark", "Zions", "Alias", "Zen", "Quigo", "Zefyr", "Plag", "Swurt", "Fork", "Arp", "Dilk", "Frazz"}
  557. function generateConsole()
  558. local genX = 2
  559. local genY = 7
  560. local genW = 0
  561. local genH = 0
  562. local genDir = 0
  563. local genDirMax = 0
  564. local genName = nil
  565. local genState = nil
  566. local topGenW = 0
  567.   term.setBackgroundColor(colors.black)
  568.   term.clear()
  569.   clickables = {}
  570.   while true do
  571.     genName = math.random(1, #names)
  572.     genName = names[genName]
  573.     genMax = 0
  574.     if w - genX >= 11 then
  575.       genMax = 4
  576.     elseif w - genX >= 7 then
  577.       genMax = 3
  578.     elseif w - genX < 7 then
  579.       --generation completed
  580.       break
  581.     end
  582.     if w - genX < 9 then
  583.       genDirMax = 1
  584.     else
  585.       genDirMax = 2
  586.     end
  587.     type = math.random(1, genMax)
  588.     if type == 1 then
  589.       type = "Button"
  590.       genW = 7
  591.       genH = 8
  592.       genState = math.random(0, 1)
  593.       if genState == 1 then
  594.         genState = true
  595.       elseif genState == 0 then
  596.         genState = false
  597.       end
  598.     elseif type == 2 then
  599.       type = "Slider"
  600.       genDir = math.random(1, genDirMax)
  601.       if genDir == 1 then
  602.         genDir = "Y"
  603.         genW = 7
  604.         genH = 11
  605.       elseif genDir == 2 then
  606.         genDir = "X"
  607.         genW = 9
  608.         genH = 5
  609.       end
  610.     elseif type == 3 then
  611.       type = "Switch"
  612.       genDir = math.random(1, 2)
  613.       if genDir == 1 then
  614.         genDir = "Y"
  615.         genW = 7
  616.         genH = 13
  617.       elseif genDir == 2 then
  618.         genDir = "X"
  619.         genW = 11
  620.         genH = 5
  621.       end
  622.       genState = math.random(0, 1)
  623.       if genState == 1 then
  624.         genState = true
  625.       elseif genState == 0 then
  626.         genState = false
  627.       end
  628.     elseif type == 4 then
  629.       type = "Dial"
  630.       genW = 11
  631.       genH = 10
  632.     end
  633.     if genY == 7 then
  634.       topGenW = genW
  635.     end
  636.     if genY + genH > h then
  637.       genX = genX + topGenW
  638.       genY = 7
  639.     else
  640.       if type == "Button" then
  641.         defButton(genX + 1, genY + 1, genState, genName)
  642.       elseif type == "Slider" then
  643.         if genDir == "X" then
  644.           defSlider(genX + 1, genY + 2, genDir, genName)
  645.         elseif genDir == "Y" then
  646.           defSlider(genX + 3, genY + 1, genDir, genName)
  647.         end
  648.       elseif type == "Switch" then
  649.         if genDir == "X" then
  650.           defSwitch(genX + 5, genY + 2, genDir, genState, genName)
  651.         elseif genDir == "Y" then
  652.           defSwitch(genX + 3, genY + 5, genDir, genState, genName)
  653.         end
  654.       elseif type == "Dial" then
  655.         defDial(genX + 3, genY + 3, genName)
  656.       end
  657.       --term.setCursorPos(genX, genY)
  658.       --term.write("x")
  659.       --genX = genX + genW
  660.       genY = genY + genH
  661.       --term.setCursorPos(genX, genY)
  662.       --term.write("y")
  663.     end
  664.   end
  665. end
  666.  
  667. ------======ACTUAL GAME======------
  668. keys = {"q","w","e","r","r","t","y","u","i","o","p","a","s","d","f","g","h","j","k","l","z","x","c","v","b","n","m"}
  669. done = 0
  670. sector = 1
  671. countnum = nil
  672. newtask = nil
  673. taskwrite = nil
  674. local alive = true
  675. initialized = false
  676. countnum = 13 - sector
  677. generateConsole()
  678. while alive do
  679.   taskwrite = nil
  680.   task = math.random(1, #clickables + 1)
  681.   if task == #clickables + 1 then
  682.     task = keys[math.random(1, 26)]
  683.     taskwrite = "Press " .. task
  684.     clickablenum = nil
  685.   else
  686.     clickablenum = task
  687.     if clickables[task][4] == "Button" then
  688.       if clickables[task][5] == false then
  689.         taskwrite = "Engage " .. clickables[task][3]
  690.         task = true
  691.       else
  692.         taskwrite = "Disengage " .. clickables[task][3]
  693.         task = false
  694.       end
  695.     elseif clickables[task][4] == "Slider" then
  696.       taskRand = math.random(0, 3)
  697.       while clickables[task][5] == taskRand do
  698.         taskRand = math.random(0, 3)
  699.       end
  700.       taskwrite = "Set " .. clickables[task][3] .. " to " .. tostring(taskRand)
  701.       task = taskRand
  702.     elseif clickables[task][4] == "Switch" then
  703.       if clickables[task][5] == false then
  704.         taskwrite = "Activate " .. clickables[task][3]
  705.         task = true
  706.       else
  707.         taskwrite = "Deactivate " .. clickables[task][3]
  708.         task = false
  709.       end
  710.     elseif clickables[task][4] == "Dial" then
  711.       taskRand = math.random(1, 7)
  712.       while clickables[task][5] == taskRand do
  713.         taskRand = math.random(1, 7)
  714.       end
  715.       taskwrite = "Set " .. clickables[task][3] .. " to " .. tostring(taskRand)
  716.       task = taskRand
  717.     end
  718.   end
  719.   rednet.send(id, taskwrite)
  720.   cast = taskwrite
  721.   while not initialized do
  722.     response = nil
  723.     rednet.broadcast(cast)
  724.     otherID, response = rednet.receive(.01)
  725.     if response and response ~= "complete" and response ~= "init" and response ~= "dead" and response ~= "nextsector" and response ~= "go" then
  726.       newtask = response
  727.       cast = "init"
  728.     end
  729.     if response == "init" and newtask then
  730.       rednet.broadcast("init")
  731.       initialized = true
  732.     end
  733.   end
  734.   --spacewrite(tostring(done) .. " tasks completed...", 1, 3, colors.white, colors.black)
  735.   complete = false
  736.   while not complete do
  737.     spacewrite("Sector: " .. tostring(sector), 9, 2, colors.white, colors.black)
  738.     spacewrite("                          ", 1, 4, colors.white, colors.black)
  739.     newtask = assert(newtask, "ERROR: newtask is nil")
  740.     spacewrite(newtask, 1, 4, colors.white, colors.black)
  741.     spacewrite("                          ", 1, 5)
  742.     if (countnum / (13 - sector)) > .75 then
  743.       term.setBackgroundColor(colors.lime)
  744.     elseif (countnum / (13 - sector)) > .5 then
  745.       term.setBackgroundColor(colors.yellow)
  746.     elseif (countnum / (13 - sector)) > .25 then
  747.       term.setBackgroundColor(colors.orange)
  748.     else
  749.       term.setBackgroundColor(colors.red)
  750.     end
  751.     term.setCursorPos(1, 5)
  752.     for i = 1, (countnum / (13 - sector)) * w do
  753.       term.write(" ")
  754.     end
  755.     --term.setCursorPos(1, h)
  756.     --term.write(countnum)
  757.     e, m, x, y, string, message = nil, nil, nil, nil, nil, nil
  758.     parallel.waitForAny(receive, key, w8, click, drag)
  759.     num = 1
  760.     if message and message ~= "complete" and message ~= "init" and message ~= "dead" and message ~= "nextsector" and message ~= "go" then
  761.       newtask = message
  762.     end
  763.     if x and y then
  764.       for i = 1, #clickables do
  765.         clickCheck()
  766.         num = num + 1
  767.         if clickablenum and clickables[clickablenum][5] == task then
  768.           rednet.send(id, "complete")
  769.           complete = true
  770.           done = done + 1
  771.           term.setCursorPos(done, 1)
  772.           term.setBackgroundColor(colors.black)
  773.           term.write(" ")
  774.         end
  775.       end
  776.     end
  777.     if not clickablenum and string == task then
  778.       rednet.send(id, "complete")
  779.       complete = true
  780.       done = done + 1
  781.       term.setCursorPos(done, 1)
  782.       term.setBackgroundColor(colors.black)
  783.       term.write(" ")
  784.     end
  785.     if message == "complete" then
  786.       countnum = 13 - sector
  787.       --otherID, newtask = rednet.receive(.1)
  788.       done = done + 1
  789.       term.setCursorPos(done, 1)
  790.       term.setBackgroundColor(colors.black)
  791.       term.write(" ")
  792.       spacewrite("                          ", 1, 4, colors.white, colors.lime)
  793.       sleep(.01)
  794.       spacewrite("                          ", 1, 4, colors.white, colors.black)
  795.     end
  796.     if done >= 24 or message == "nextsector" then
  797.       movingon = false
  798.       ready = false
  799.       cast = "nextsector"
  800.       while not movingon do
  801.         response = nil
  802.         rednet.broadcast(cast)
  803.         otherID, response = rednet.receive(.01)
  804.         if response == "nextsector" or response == "go" then
  805.           cast = "go"
  806.           ready = true
  807.         end
  808.         if response == "go" and ready then
  809.           rednet.broadcast("nextsector")
  810.           rednet.broadcast("go")
  811.           movingon = true
  812.         end
  813.       end
  814.       term.setCursorPos(1, 1)
  815.       term.setBackgroundColor(colors.white)
  816.       term.setTextColor(colors.black)
  817.       textutils.slowPrint("       HYPERSPACE!!!      ")
  818.       sleep(.3)
  819.       term.setBackgroundColor(colors.white)
  820.       term.clear()
  821.       sleep(.3)
  822.       term.setBackgroundColor(colors.lightGray)
  823.       term.clear()
  824.       sleep(.3)
  825.       term.setBackgroundColor(colors.gray)
  826.       term.clear()
  827.       sleep(.3)
  828.       term.setBackgroundColor(colors.black)
  829.       term.clear()
  830.       sleep(.3)
  831.       term.setTextColor(colors.white)
  832.       sector = sector + 1
  833.       initialized = false
  834.       done = 0
  835.       newtask = nil
  836.       taskwrite = nil
  837.       countnum = 13 - sector
  838.       spacewrite("  ", 25, 1, colors.white, colors.black)
  839.       generateConsole()
  840.       complete = true
  841.     end
  842.     if countnum <= 0 or message == "dead" then
  843.       term.setCursorPos(1, h)
  844.       term.setBackgroundColor(colors.red)
  845.       rednet.send(id, "dead")
  846.       textutils.slowPrint("Critical Failiure...")
  847.       alive = false
  848.       break
  849.     end
  850.   end
  851. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement