Advertisement
sosochka

init

Dec 7th, 2022 (edited)
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.06 KB | None | 0 0
  1. local term = require("term")
  2. local component = require("component")
  3. local colors = require("colors")
  4. local gpu = component.gpu
  5.  
  6. local drawing = {}
  7.  
  8. function drawing.drawPlayField(PlayGrid)
  9.     gpu.setForeground(0xFFFFFF)
  10.     local title = "MINESWEEPER"
  11.     term.setCursor(PlayGrid.offset.x + #PlayGrid.values[0]/2 - #title/2, 2)
  12.     term.write(title)
  13.     term.setCursor(PlayGrid.offset.x, PlayGrid.offset.y)
  14.     for y=0,#PlayGrid.values do
  15.         for x=0,#PlayGrid.values[0] do
  16.             term.setCursor(PlayGrid.offset.x + x, PlayGrid.offset.y + y)
  17.             if(PlayGrid.revealedGrid[y][x] == "r") then
  18.                 gpu.setForeground(0xFFFFFF)
  19.                 term.write(PlayGrid.values[y][x])
  20.             elseif PlayGrid.revealedGrid[y][x] == "f" then
  21.                 gpu.setForeground(0x006D00)
  22.                 term.write("F")
  23.             else
  24.                 gpu.setForeground(0xFFFF80)
  25.                 term.write("H")
  26.             end
  27.         end
  28.     end
  29.  
  30.     gpu.setForeground(0xFFFFFF)
  31.     -- local instructions = "LMB = reveal, Alt + LMB = Flag"
  32.     -- local  instructions2 = "To win the game you have to flag all the mines"
  33.     -- term.setCursor(PlayGrid.offset.x + #PlayGrid.values[0]/2 - #instructions/2, PlayGrid.offset.y + PlayGrid.playFieldSize.y + 5)
  34.     -- term.write(instructions)
  35.     -- term.setCursor(PlayGrid.offset.x + #PlayGrid.values[0]/2 - #instructions2/2, PlayGrid.offset.y + PlayGrid.playFieldSize.y + 6)
  36.     -- term.write(instructions2)
  37.  
  38.     if PlayGrid.cheater then
  39.         for y=1,#PlayGrid.values+1 do
  40.             for x=1,#PlayGrid.values[0]+1 do
  41.                 term.setCursor(x + PlayGrid.offset.x - PlayGrid.playFieldSize.x - 5, y)
  42.                 term.write(PlayGrid.values[y-1][x-1])
  43.             end
  44.         end
  45.  
  46.         for y=1,#PlayGrid.revealedGrid+1 do
  47.             for x=1,#PlayGrid.revealedGrid[0]+1 do
  48.                 term.setCursor(x + PlayGrid.offset.x + PlayGrid.playFieldSize.x + 3, y)
  49.                 term.write(PlayGrid.revealedGrid[y-1][x-1])
  50.             end
  51.         end
  52.     end
  53. end
  54.  
  55. return drawing
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement