Advertisement
Doob

Rubik's_cube_gui

Nov 29th, 2014
700
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.91 KB | None | 0 0
  1. local tCube = {}
  2.  
  3. rednet.open('back')
  4.  
  5. local tCoords = {
  6.   {{12, 13, 14}, {7, 8, 9}},
  7.   {{15, 16, 17}, {7, 8, 9}},
  8.   {{14, 13, 12}, {6, 5, 4}},
  9.   {{9, 10, 11}, {7, 8, 9}},
  10.   {{12, 13, 14}, {10, 11, 12}},
  11.   {{12, 13, 14}, {13, 14, 15}},
  12.  
  13.   ['buttons'] = {
  14.     {12, 3, '04'}, {13, 2, '05'}, {14, 3, '06'}, -- up
  15.     {12, 16, '14'}, {13, 17, '15'}, {14, 16, '16'}, -- down
  16.     {8, 7, '17'}, {7, 8, '18'}, {8, 9, '19'}, -- left
  17.     {18, 7, '07'}, {19, 8, '08'}, {18, 9, '09'}, -- right
  18.     {11, 10, '01'}, {10, 11, '02'}, {11, 12, '03'}, -- cw
  19.     {15, 10, '11'}, {16, 11, '12'}, {15, 12, '13'}, -- ccw
  20.     {2, 16, 'reset'}, {18, 16, 'shuffle'} -- reset, shuffle
  21. }}
  22.  
  23. local function drawButtons()
  24.   for b = 1, #tCoords['buttons'] do
  25.     paintutils.drawPixel(tCoords['buttons'][b][1], tCoords['buttons'][b][2], 0x100)
  26.   end
  27.  
  28.   term.setBackgroundColor(0x8000)
  29.   term.setCursorPos(tCoords['buttons'][19][1]+1, tCoords['buttons'][19][2])
  30.   write('RESET')
  31.  
  32.   term.setCursorPos(tCoords['buttons'][20][1]+1, tCoords['buttons'][20][2])
  33.   write('SHUFFLE')
  34. end
  35.  
  36. local function drawNet()
  37.   for side = 1, 6 do
  38.     for cell = 1, 9 do
  39.       if cell == 1 then x, y = 1, 1
  40.         elseif cell == 2 then x, y = 2, 1
  41.         elseif cell == 3 then x, y = 3, 1
  42.  
  43.         elseif cell == 4 then x, y = 1, 2
  44.         elseif cell == 5 then x, y = 2, 2
  45.         elseif cell == 6 then x, y = 3, 2
  46.  
  47.         elseif cell == 7 then x, y = 1, 3
  48.         elseif cell == 8 then x, y = 2, 3
  49.         elseif cell == 9 then x, y = 3, 3
  50.       end
  51.      
  52.       s = ('s'..side)
  53.      
  54.       color = tCube[s][cell]
  55.  
  56.       if color == 14 then color = 0x4000
  57.         elseif color == 0 then color = 0x1
  58.         elseif color == 13 then color = 0x2000
  59.         elseif color == 4 then color = 0x10
  60.         elseif color == 11 then color = 0x800
  61.         elseif color == 1 then color = 0x2
  62.       end
  63.    
  64.       paintutils.drawPixel(tCoords[side][1][x], tCoords[side][2][y], color)
  65.     end
  66.   end
  67. end
  68.  
  69. while true do
  70.   term.setBackgroundColor(0x8000)
  71.   term.clear()
  72.   term.setCursorPos(1, 1)
  73.  
  74.   local id, msg = rednet.receive('cube_0')
  75.   tCube = textutils.unserialize(msg)
  76.   tCube['s2'][1], tCube['s2'][3], tCube['s2'][9], tCube['s2'][7] =
  77.   tCube['s2'][3], tCube['s2'][9], tCube['s2'][7], tCube['s2'][1]
  78.   tCube['s2'][2], tCube['s2'][6], tCube['s2'][8], tCube['s2'][4] =
  79.   tCube['s2'][6], tCube['s2'][8], tCube['s2'][4], tCube['s2'][2]
  80.   tCube['s4'][1], tCube['s4'][7], tCube['s4'][9], tCube['s4'][3] =
  81.   tCube['s4'][7], tCube['s4'][9], tCube['s4'][3], tCube['s4'][1]
  82.   tCube['s4'][2], tCube['s4'][4], tCube['s4'][8], tCube['s4'][6] =
  83.   tCube['s4'][4], tCube['s4'][8], tCube['s4'][6], tCube['s4'][2]
  84.  
  85.   drawButtons()
  86.   drawNet()
  87.  
  88.   local et, bn, x, y = os.pullEvent("mouse_click")
  89.   for i = 1, #tCoords['buttons'] do
  90.     if x == tCoords['buttons'][i][1] and y == tCoords['buttons'][i][2] then
  91.       rednet.broadcast(tCoords['buttons'][i][3], 'cube_0')
  92.     end
  93.   end
  94. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement