Null_Cat

MSCC v1.01

Apr 12th, 2019
377
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 20.49 KB | None | 0 0
  1. -- some very nice minesweep
  2. -- Last update: 4/18/2019 2:36:59 AM
  3. -- Finished! (ver 1.01)
  4. -- Made using the ComputerCraft emulator by GravityScore and 1lann
  5. -- https://www.computercraft.info/wiki/Category:Lua_Core_Functions and https://www.computercraft.info/wiki/Category:APIs
  6. -- Part of the Minesweeper Project [https://pastebin.com/Yftb7QWL]
  7.  
  8. local inputArgs = {...} -- Hey lets, you know, allow people to use it with preset parameters.
  9.  
  10. if inputArgs[1] then
  11.     if inputArgs[1]:lower() == "help" or inputArgs[1]:lower() == "?" then
  12.         print("Syntax: mine [difficulty]")
  13.         print("        mine custom <width> <height> <mines>")
  14.         return
  15.     end
  16. end
  17.  
  18. term.clear()
  19. local board = {} -- Holds everything
  20. local boardSettings = {} -- {Width, Height, MineCount, Difficulty}
  21.  
  22. local difficulty
  23. local inputWidth
  24. local inputHeight
  25. local inputMines
  26.  
  27. if inputArgs[1] then
  28.     difficulty = inputArgs[1]
  29.     if difficulty == "easy" then
  30.         inputWidth = 8
  31.         inputHeight = 8
  32.         inputMines = 10
  33.     elseif difficulty == "normal"  then
  34.         inputWidth = 16
  35.         inputHeight = 16
  36.         inputMines = 40
  37.     elseif difficulty == "hard" then
  38.         inputWidth = 32
  39.         inputHeight = 16
  40.         inputMines = 99
  41.     elseif difficulty == "custom" then
  42.         inputWidth = tonumber(inputArgs[2])
  43.         if inputWidth == nil or inputWidth <= 0 then inputWidth = nil end
  44.         inputHeight = tonumber(inputArgs[3])
  45.         if inputHeight == nil or inputHeight <= 0 then inputHeight = nil end
  46.         inputMines = tonumber(inputArgs[4])
  47.         if inputMines == nil then if inputMines <= 0 or inputMines >= boardArea then inputMines = nil end end
  48.     else
  49.         difficulty = nil
  50.     end
  51. end
  52.  
  53. local ready = false
  54.  
  55. while not ready do
  56.     while not difficulty do
  57.         term.setCursorPos(1,1)
  58.         term.setTextColor(colors.white)
  59.         print("Difficulty: Easy, Normal, Hard, Custom?")
  60.         difficulty = read():lower()
  61.         if difficulty == "easy" then
  62.             inputWidth = 8
  63.             inputHeight = 8
  64.             inputMines = 10
  65.         elseif difficulty == "normal"  then
  66.             inputWidth = 16
  67.             inputHeight = 16
  68.             inputMines = 40
  69.         elseif difficulty == "hard" then
  70.             inputWidth = 32
  71.             inputHeight = 16
  72.             inputMines = 99
  73.         elseif difficulty ~= "custom" then
  74.             difficulty = nil
  75.             term.clear()
  76.             term.setTextColor(colors.orange)
  77.             print("Please set a vaild difficulty.")
  78.         end
  79.     end
  80.     term.clear()
  81.     while not inputWidth do
  82.         term.setCursorPos(1,1)
  83.         term.setTextColor(colors.white)
  84.         print("Input Width of Board")
  85.         inputWidth = tonumber(read():lower())
  86.         if inputWidth == nil then
  87.             inputWidth = nil
  88.             term.clear()
  89.             term.setTextColor(colors.orange)
  90.             print("Please input a valid number.")
  91.         elseif inputWidth <= 3 then
  92.             inputWidth = nil
  93.             term.clear()
  94.             term.setTextColor(colors.orange)
  95.             print("Please input a positive number of at least 4.")
  96.         end
  97.     end
  98.     term.clear()
  99.     while not inputHeight do
  100.         term.setCursorPos(1,1)
  101.         term.setTextColor(colors.white)
  102.         print("Input Height of Board")
  103.         inputHeight = tonumber(read():lower())
  104.         if inputHeight == nil then
  105.             inputHeight = nil
  106.             term.clear()
  107.             term.setTextColor(colors.orange)
  108.             print("Please input a valid number.")
  109.         elseif inputHeight <= 3 then
  110.             inputHeight = nil
  111.             term.clear()
  112.             term.setTextColor(colors.orange)
  113.             print("Please input a positive number of at least 4.")
  114.         end
  115.     end
  116.  
  117.     local boardArea = inputWidth * inputHeight
  118.     term.clear()
  119.     while not inputMines do
  120.         term.setCursorPos(1,1)
  121.         term.setTextColor(colors.white)
  122.         print("Input Mine Count")
  123.         inputMines = tonumber(read():lower())
  124.         if inputMines == nil then
  125.             inputMines = nil
  126.             term.clear()
  127.             term.setTextColor(colors.orange)
  128.             print("Please input a valid number.")
  129.         elseif inputMines <= 0 or inputMines >= boardArea then
  130.             term.clear()
  131.             term.setTextColor(colors.orange)
  132.             if inputMines <= 0 then
  133.                 print("Please input a positive number.")
  134.             elseif inputMines >= boardArea - 8 then
  135.                 print("Please input a number lower than the area of the board minus 8.")
  136.             end
  137.             inputMines = nil
  138.         end
  139.     end
  140.  
  141.     ready = nil
  142.     term.clear()
  143.    
  144.     while ready == nil do
  145.         term.setCursorPos(1,1)
  146.         term.setTextColor(colors.white)
  147.         print("Review Settings:\n"..inputWidth.."x"..inputHeight.."\n"..inputMines.." Mines.\nDifficulty: "..difficulty:gsub("^%l", string.upper))
  148.         print("Is this correct?")
  149.         ready = read():lower()
  150.         if ready ~= "y" and ready ~= "n" then
  151.             ready = nil
  152.             term.clear()
  153.             term.setTextColor(colors.orange)
  154.             print("Please insert Y or N.")
  155.         elseif ready == "y" then
  156.             ready = true
  157.             boardSettings = {["Width"] = inputWidth, ["Height"] = inputHeight, ["MineCount"] = inputMines, ["Difficulty"] = difficulty}
  158.         elseif ready == "n" then
  159.             ready = false
  160.             inputMines = nil
  161.             inputWidth = nil
  162.             inputHeight = nil
  163.             difficulty = nil
  164.             term.clear()
  165.         end
  166.     end
  167. end
  168.  
  169. -- Everything above this was literally just giving the settings for the board.
  170. -- Below is generating the board and everything
  171. -- jeez
  172.  
  173. term.setBackgroundColor(colors.gray)
  174. term.clear()
  175. local boardWindow = window.create(term.current(), 1, 2, boardSettings["Width"], boardSettings["Height"])
  176. local boardWindowSX, boardWindowSY = boardWindow.getSize()
  177. local bg = term.current()
  178. local flagged = boardSettings["MineCount"]
  179. boardWindow.setBackgroundColor(colors.lightGray)
  180. term.redirect(boardWindow)
  181. paintutils.drawFilledBox(1,1,boardWindowSX,boardWindowSY)
  182. local firstMoveForControls = false
  183. local firstMove = false
  184. local mineBoard
  185. local boardWindowX, boardWindowY
  186. local invertCam
  187.  
  188. -- Ripped from Roblox Ver. [https://pastebin.com/aNSNrvvF]
  189. function createBoardArray(startPos, width, height, mineCount)
  190.     --This will help with RNG
  191.     math.randomseed(os.time())
  192.     --Generating the Array. First step towards the board generation
  193.     local board = {}
  194.     for i = 1, height do
  195.         local newRow = {} -- This is an array for each new row
  196.         for j = 1, width do
  197.             if mineCount > 0 then -- If there is still meant to be mines
  198.                 if math.random(1,10) == 1 and not ( -- Go through with RNG.
  199.                         (startPos.y == i or (startPos.y + 1 == i or startPos.y - 1 == i)) and
  200.                         (startPos.x == j or (startPos.x + 1 == j or startPos.x - 1 == j))) then
  201.                         table.insert(newRow,j,10)
  202.                         mineCount = mineCount - 1
  203.                 else -- If RNG fails, don't place a mine.
  204.                     table.insert(newRow,j,0)
  205.                 end
  206.             else -- If there shouldn't be anymore mines, just place an empty space
  207.                 table.insert(newRow,j,0)
  208.             end
  209.         end
  210.         table.insert(board,i,newRow) -- Insert the generated mode into the board. Repeat this "height" times
  211.     end
  212.   --If there still needs to be mines, it'll create them here.
  213.     while mineCount ~= 0 do
  214.         for n,i in ipairs(board) do
  215.             for m,j in ipairs(board[n]) do
  216.                 if board[n][m] ~= 10 and board[n][m] ~= 9 then -- Check if the space is not a mine already
  217.                     if math.random(1,15) == 1 and not ( -- If not, go through with RNG. Tougher this time.
  218.                         (startPos.y == n or (startPos.y + 1 == n or startPos.y - 1 == n)) and
  219.                         (startPos.x == m or (startPos.x + 1 == m or startPos.x - 1 == m))) then
  220.                             board[n][m] = 10 -- Replaces board[n][m] with a mine.
  221.                             mineCount = mineCount - 1
  222.                     end
  223.                 end
  224.                 if mineCount == 0 then
  225.                     break
  226.                 end
  227.             end
  228.             if mineCount == 0 then -- Double break because one break only stops part of it
  229.                 break
  230.             end
  231.         end    
  232.     end
  233.     -- Check for Mines and put numbers next to them
  234.     for n,i in ipairs(board) do
  235.         for m,j in ipairs(board[n]) do
  236.             if board[n][m] == 10 then -- If there is a mine, execute all of the following. Each direction shows where it goes towards below.
  237.                 --Left
  238.                 if m-1 ~= 0 then
  239.                     if board[n][m-1] ~= 10 then
  240.                         board[n][m-1] = board[n][m-1] + 1
  241.                     end
  242.                 end
  243.                 --Right
  244.                 if m+1 <= width then
  245.                     if board[n][m+1] ~= 10 then
  246.                         board[n][m+1] = board[n][m+1] + 1
  247.                     end
  248.                 end
  249.                 --Up
  250.                 if n-1 ~= 0 then
  251.                     if board[n-1][m] ~= 10 then
  252.                         board[n-1][m] = board[n-1][m] + 1
  253.                     end
  254.                 end
  255.                 --Down
  256.                 if n+1 <= height then
  257.                     if board[n+1][m] ~= 10 then
  258.                         board[n+1][m] = board[n+1][m] + 1
  259.                     end
  260.                 end
  261.                
  262.                 --Up Left
  263.                 if n-1 ~= 0 and m-1 ~= 0 then
  264.                     if board[n-1][m-1] ~= 10 then
  265.                         board[n-1][m-1] = board[n-1][m-1] + 1
  266.                     end
  267.                 end
  268.                 --Up Right
  269.                 if n-1 ~= 0 and m+1 <= width then
  270.                     if board[n-1][m+1] ~= 10 then
  271.                         board[n-1][m+1] = board[n-1][m+1] + 1
  272.                     end
  273.                 end
  274.                 --Down Left
  275.                 if n+1 <= height and m-1 ~= 0 then
  276.                     if board[n+1][m-1] ~= 10 then
  277.                         board[n+1][m-1] = board[n+1][m-1] + 1
  278.                     end
  279.                 end
  280.                 --Down Right
  281.                 if n+1 <= height and m+1 <= width then
  282.                     if board[n+1][m+1] ~= 10 then
  283.                         board[n+1][m+1] = board[n+1][m+1] + 1
  284.                     end
  285.                 end
  286.             end
  287.         end
  288.     end
  289.    
  290.     return board
  291. end
  292.  
  293. function onUncoverDo(X, Y)
  294.     if X > boardWindowX - 1 and X < boardWindowSX + (boardWindowX) and Y > boardWindowY - 1 and Y < boardWindowSY + (boardWindowY) then
  295.         if not firstMove then
  296.             firstMove = true
  297.             paintutils.drawPixel(X - (boardWindowX - 1), Y - (boardWindowY - 1), colors.black)
  298.             mineBoard = createBoardArray({["y"] = X - (boardWindowX - 1), ["x"] = Y - (boardWindowY - 1)}, boardSettings["Height"], boardSettings["Width"], boardSettings["MineCount"])
  299.             mineBoard[X - (boardWindowX - 1)][Y - (boardWindowY - 1)] = 99
  300.             removeSurround(X, Y)
  301.         elseif mineBoard[X - (boardWindowX - 1)][Y - (boardWindowY - 1)] ~= 99 then
  302.             local spaceToUncover = mineBoard[X - (boardWindowX - 1)][Y - (boardWindowY - 1)]
  303.             if spaceToUncover == 0 then
  304.                 paintutils.drawPixel(X - (boardWindowX - 1), Y - (boardWindowY - 1), colors.black)
  305.                 mineBoard[X - (boardWindowX - 1)][Y - (boardWindowY - 1)] = 99
  306.                 removeSurround(X, Y)
  307.             elseif spaceToUncover == 1 then
  308.                 paintutils.drawPixel(X - (boardWindowX - 1), Y - (boardWindowY - 1), colors.blue)
  309.                 term.setCursorPos(X - (boardWindowX - 1), Y - (boardWindowY - 1))
  310.                 term.write("1")
  311.                 mineBoard[X - (boardWindowX - 1)][Y - (boardWindowY - 1)] = 99
  312.             elseif spaceToUncover == 2 then
  313.                 paintutils.drawPixel(X - (boardWindowX - 1), Y - (boardWindowY - 1), colors.green)
  314.                 term.setCursorPos(X - (boardWindowX - 1), Y - (boardWindowY - 1))
  315.                 term.write("2")
  316.                 mineBoard[X - (boardWindowX - 1)][Y - (boardWindowY - 1)] = 99
  317.             elseif spaceToUncover == 3 then
  318.                 paintutils.drawPixel(X - (boardWindowX - 1), Y - (boardWindowY - 1), colors.orange)
  319.                 term.setCursorPos(X - (boardWindowX - 1), Y - (boardWindowY - 1))
  320.                 term.write("3")
  321.                 mineBoard[X - (boardWindowX - 1)][Y - (boardWindowY - 1)] = 99
  322.             elseif spaceToUncover == 4 then
  323.                 paintutils.drawPixel(X - (boardWindowX - 1), Y - (boardWindowY - 1), colors.purple)
  324.                 term.setCursorPos(X - (boardWindowX - 1), Y - (boardWindowY - 1))
  325.                 term.write("4")
  326.                 mineBoard[X - (boardWindowX - 1)][Y - (boardWindowY - 1)] = 99
  327.             elseif spaceToUncover == 5 then
  328.                 paintutils.drawPixel(X - (boardWindowX - 1), Y - (boardWindowY - 1), colors.red)
  329.                 term.setCursorPos(X - (boardWindowX - 1), Y - (boardWindowY - 1))
  330.                 term.write("5")
  331.                 mineBoard[X - (boardWindowX - 1)][Y - (boardWindowY - 1)] = 99
  332.             elseif spaceToUncover == 6 then
  333.                 paintutils.drawPixel(X - (boardWindowX - 1), Y - (boardWindowY - 1), colors.cyan)
  334.                 term.setCursorPos(X - (boardWindowX - 1), Y - (boardWindowY - 1))
  335.                 term.write("6")
  336.                 mineBoard[X - (boardWindowX - 1)][Y - (boardWindowY - 1)] = 99
  337.             elseif spaceToUncover == 7 then
  338.                 paintutils.drawPixel(X - (boardWindowX - 1), Y - (boardWindowY - 1), colors.white)
  339.                 term.setCursorPos(X - (boardWindowX - 1), Y - (boardWindowY - 1))
  340.                 term.write("7")
  341.                 mineBoard[X - (boardWindowX - 1)][Y - (boardWindowY - 1)] = 99
  342.             elseif spaceToUncover == 8 then
  343.                 paintutils.drawPixel(X - (boardWindowX - 1), Y - (boardWindowY - 1), colors.gray)
  344.                 term.setCursorPos(X - (boardWindowX - 1), Y - (boardWindowY - 1))
  345.                 term.write("8")
  346.                 mineBoard[X - (boardWindowX - 1)][Y - (boardWindowY - 1)] = 99
  347.             elseif spaceToUncover == 10 then
  348.                 paintutils.drawPixel(X - (boardWindowX - 1), Y - (boardWindowY - 1), colors.yellow)
  349.                 term.setCursorPos(X - (boardWindowX - 1), Y - (boardWindowY - 1))
  350.                 term.setTextColor(colors.black)
  351.                 term.write("X")
  352.                 term.setTextColor(colors.white)
  353.                 mineBoard[X - (boardWindowX - 1)][Y - (boardWindowY - 1)] = 99
  354.                 exploded = true
  355.             end
  356.            
  357.         end
  358.     end
  359. end
  360.  
  361. function removeSurround(X, Y)
  362.     local m, n = X - (boardWindowX - 1), Y - (boardWindowY - 1)
  363.     --Left
  364.     if m-1 ~= 0 then
  365.         onUncoverDo(X - 1,Y)
  366.         -- mineBoard[n][m-1] = mineBoard[n][m-1] + 1
  367.     end
  368.     --Right
  369.     if m+1 < boardSettings["Width"] + 1 then
  370.         onUncoverDo(X + 1,Y)
  371.         -- mineBoard[n][m+1] = mineBoard[n][m+1] + 1
  372.     end
  373.     --Up
  374.     if n-1 ~= 0 then
  375.         onUncoverDo(X,Y - 1)
  376.         -- mineBoard[n-1][m] = mineBoard[n-1][m] + 1
  377.     end
  378.     --Down
  379.     if n+1 <= boardSettings["Height"] + 1 then
  380.         onUncoverDo(X,Y + 1)
  381.         -- mineBoard[n+1][m] = mineBoard[n+1][m] + 1
  382.     end
  383.    
  384.     --Up Left
  385.     if n-1 ~= 0 and m-1 ~= 0 then
  386.         onUncoverDo(X - 1,Y - 1)
  387.         --mineBoard[n-1][m-1] = mineBoard[n-1][m-1] + 1
  388.     end
  389.     --Up Right
  390.     if n-1 ~= 0 and m+1 <= boardSettings["Width"] + 1 then
  391.         onUncoverDo(X + 1,Y - 1)
  392.         -- mineBoard[n-1][m+1] = mineBoard[n-1][m+1] + 1
  393.     end
  394.     --Down Left
  395.     if n+1 <= boardSettings["Height"] + 1 and m-1 ~= 0 then
  396.         onUncoverDo(X - 1,Y + 1)
  397.         -- mineBoard[n+1][m-1] = mineBoard[n+1][m-1] + 1
  398.     end
  399.     --Down Right
  400.     if n+1 <= boardSettings["Height"] + 1 and m+1 <= boardSettings["Width"] + 1 then
  401.         onUncoverDo(X + 1,Y + 1)
  402.         -- mineBoard[n+1][m+1] = mineBoard[n+1][m+1] + 1
  403.     end
  404. end
  405.  
  406. local deathMessage = math.random(1,16)
  407.  
  408. while true do
  409.     if firstMoveForControls == false then
  410.         term.redirect(bg)
  411.         term.setBackgroundColor(colors.blue)
  412.         term.setCursorPos(1,1)
  413.         print("Flagged:",flagged)
  414.         print("Controls:")
  415.         print("WASD to move the board/camera")
  416.         print("Mouse1 to Uncover")
  417.         print("Mouse2 to Flag")
  418.         print("I to invert camera controls")
  419.         print("H to bring this up again")
  420.         term.redirect(boardWindow)
  421.     elseif exploded == true then
  422.         term.redirect(bg)
  423.         term.setBackgroundColor(colors.gray)
  424.         term.clear()
  425.         boardWindow.redraw()
  426.         term.setBackgroundColor(colors.blue)
  427.         term.setCursorPos(1,1)
  428.         if deathMessage == 1 then
  429.             print("F")
  430.         elseif deathMessage == 2 then
  431.             local eggDeathMessage = math.random(1,6)
  432.             if eggDeathMessage == 1 then
  433.                 print("You are ded. Not big soup rice.")
  434.             elseif eggDeathMessage == 2 then
  435.                 print("If you were from, where I was from, you'd be frickin' dead.")
  436.             elseif eggDeathMessage == 3 then
  437.                 print("We're done for, everyone, get out!")
  438.             elseif eggDeathMessage == 4 then
  439.                 print("Use a flag. And if that don't work, use more flag.")
  440.             elseif eggDeathMessage == 5 then
  441.                 print("You can feel your sins crawling on your back.")
  442.             elseif eggDeathMessage == 6 then
  443.                 print("/kill @s")
  444.             end
  445.         elseif deathMessage == 3 then
  446.             print("L")
  447.         elseif deathMessage == 4 then
  448.             print("The player is gone!")
  449.         elseif deathMessage == 5 then
  450.             print("DeathMessage5.png")
  451.         elseif deathMessage == 6 then
  452.             print("Failed!")
  453.         elseif deathMessage == 7 then
  454.             print("So close, yet so far.")
  455.         elseif deathMessage == 8 then
  456.             print("Watch out, a 50/50 behind you!")
  457.         elseif deathMessage == 9 then
  458.             print("i ran out of ideas for messages")
  459.         elseif deathMessage == 10 then
  460.             print("Oof")
  461.         elseif deathMessage == 11 then
  462.             if boardSettings["Difficulty"] == "easy" then
  463.                 print("Failed... on easy?")
  464.             elseif boardSettings["Difficulty"] == "normal" then
  465.                 print("You can do it on normal.")
  466.             elseif boardSettings["Difficulty"] == "hard" then
  467.                 print("Hard is pretty difficult, just saying.")
  468.             elseif boardSettings["Difficulty"] == "custom" then
  469.                 print("Did you fail a 4x4 1 mine, or 50x50 512? I can't tell")
  470.             end
  471.         elseif deathMessage == 12 then
  472.             if boardSettings["Difficulty"] == "easy" then
  473.                 print("We all make mistakes...")
  474.             elseif boardSettings["Difficulty"] == "normal" or boardSettings["Difficulty"] == "custom" then
  475.                 print("You got this.")
  476.             elseif boardSettings["Difficulty"] == "hard" then
  477.                 print("Difficulty comes with mistakes")
  478.             end
  479.         elseif deathMessage == 13 then
  480.             print("HP: 0 / 1")
  481.         elseif deathMessage == 14 then
  482.             print("Well, you tried, and that's all that matters.")
  483.         elseif deathMessage == 15 then
  484.             print("a")
  485.         elseif deathMessage == 16 then
  486.             print("dddddddwwwwwwwaaaaaaaaaaa")
  487.         end
  488.         term.redirect(boardWindow)
  489.     else
  490.         term.redirect(bg)
  491.         term.setBackgroundColor(colors.gray)
  492.         term.clear()
  493.         boardWindow.redraw()
  494.         term.setBackgroundColor(colors.blue)
  495.         term.setCursorPos(1,1)
  496.         print("Flagged:",flagged)
  497.         term.redirect(boardWindow)
  498.     end
  499.    
  500.     boardWindowX, boardWindowY = boardWindow.getPosition()
  501.     local event, key, X, Y = os.pullEvent()
  502.    
  503.     if event == "key" then
  504.         firstMoveForControls = true
  505.         if key == keys.w then
  506.             term.redirect(bg)
  507.             term.setBackgroundColor(colors.gray)
  508.             term.clear()
  509.             term.redirect(boardWindow)
  510.             term.setBackgroundColor(colors.lightGray)
  511.             if invertCam then
  512.                 boardWindow.reposition(boardWindowX, boardWindowY + 1)
  513.             else
  514.                 boardWindow.reposition(boardWindowX, boardWindowY - 1)
  515.             end
  516.         elseif key == keys.a then
  517.             term.redirect(bg)
  518.             term.setBackgroundColor(colors.gray)
  519.             term.clear()
  520.             term.redirect(boardWindow)
  521.             term.setBackgroundColor(colors.lightGray)
  522.             if invertCam then
  523.                 boardWindow.reposition(boardWindowX + 1, boardWindowY)
  524.             else
  525.                 boardWindow.reposition(boardWindowX - 1, boardWindowY)
  526.             end
  527.         elseif key == keys.s then
  528.             term.redirect(bg)
  529.             term.setBackgroundColor(colors.gray)
  530.             term.clear()
  531.             term.redirect(boardWindow)
  532.             term.setBackgroundColor(colors.lightGray)
  533.             if invertCam then
  534.                 boardWindow.reposition(boardWindowX, boardWindowY - 1)
  535.             else
  536.                 boardWindow.reposition(boardWindowX, boardWindowY + 1)
  537.             end
  538.         elseif key == keys.d then
  539.             term.redirect(bg)
  540.             term.setBackgroundColor(colors.gray)
  541.             term.clear()
  542.             term.redirect(boardWindow)
  543.             term.setBackgroundColor(colors.lightGray)
  544.             if invertCam then
  545.                 boardWindow.reposition(boardWindowX - 1, boardWindowY)
  546.             else
  547.                 boardWindow.reposition(boardWindowX + 1, boardWindowY)
  548.             end
  549.         elseif key == keys.h then
  550.             firstMoveForControls = false
  551.         elseif key == keys.i then
  552.             if invertCam then
  553.                 invertCam = false
  554.             else
  555.                 invertCam = true
  556.             end
  557.         end
  558.     elseif event == "mouse_click" then
  559.         firstMoveForControls = true
  560.         if key == 1 then
  561.             onUncoverDo(X,Y)
  562.         elseif key == 2 then
  563.             if X > boardWindowX - 1 and X < boardWindowSX + (boardWindowX) and Y > boardWindowY - 1 and Y < boardWindowSY + (boardWindowY) then
  564.                 spaceToFlag = mineBoard[X - (boardWindowX - 1)][Y - (boardWindowY - 1)]
  565.                 if (spaceToFlag > 10 or spaceToFlag == 9) and spaceToFlag ~= 99 then
  566.                     paintutils.drawPixel(X - (boardWindowX - 1), Y - (boardWindowY - 1), colors.lightGray)
  567.                     flagged = flagged + 1
  568.                     if spaceToFlag ~= 9 then
  569.                         mineBoard[X - (boardWindowX - 1)][Y - (boardWindowY - 1)] = mineBoard[X - (boardWindowX - 1)][Y - (boardWindowY - 1)] - 10
  570.                     else
  571.                         mineBoard[X - (boardWindowX - 1)][Y - (boardWindowY - 1)] = 0
  572.                     end
  573.                 elseif spaceToFlag ~= 99 then
  574.                     paintutils.drawPixel(X - (boardWindowX - 1), Y - (boardWindowY - 1), colors.red)
  575.                     flagged = flagged - 1
  576.                     if spaceToFlag == 0 then
  577.                         mineBoard[X - (boardWindowX - 1)][Y - (boardWindowY - 1)] = 9
  578.                     else
  579.                         mineBoard[X - (boardWindowX - 1)][Y - (boardWindowY - 1)] = spaceToFlag + 10
  580.                     end
  581.                 end
  582.             end
  583.         end
  584.     end
  585. end
Advertisement
Add Comment
Please, Sign In to add comment