Advertisement
Null_Cat

MSCC v1.1

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