Advertisement
Guest User

cutil

a guest
Sep 20th, 2014
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.05 KB | None | 0 0
  1. if not os.loadAPI("button") then
  2.     error("Checkers util API requires the button API by minecraftwarlock to run")
  3. end
  4.  
  5. mon = peripheral.wrap("left")
  6.  
  7. button.default()
  8.  
  9. local xSize,ySize = mon.getSize()
  10.  
  11. function offset(x,coord)
  12.     if string.lower(coord) == "x" then
  13.         return math.floor(xSize / 2) + x
  14.     elseif string.lower(coord) == "y" then
  15.         return math.floor(ySize / 2) + x
  16.     end
  17. end
  18.  
  19. local boardX = offset(-3,"x")
  20. local boardY = offset(-3,"y")
  21.  
  22. menuButtons = {}
  23.  
  24. pieces = {
  25. white = {
  26. piece1 = {x = 1,y = 1,moves = 0,taken = 0,alive = true},piece2 = {x = 1,y = 3,moves = 0,taken = 0,alive = true},
  27. piece3 = {x = 1,y = 5,moves = 0,taken = 0,alive = true},piece4 = {x = 1,y = 7,moves = 0,taken = 0,alive = true},
  28. piece5 = {x = 2,y = 2,moves = 0,taken = 0,alive = true},piece6 = {x = 2,y = 4,moves = 0,taken = 0,alive = true},
  29. piece7 = {x = 2,y = 6,moves = 0,taken = 0,alive = true},piece8 = {x = 2,y = 8,moves = 0,taken = 0,alive = true},
  30. piece9 = {x = 3,y = 1,moves = 0,taken = 0,alive = true},piece10 = {x = 3,y = 3,moves = 0,taken = 0,alive = true},
  31. piece11 = {x = 3,y = 5,moves = 0,taken = 0,alive = true},piece12 = {x = 3,y = 7,moves = 0,taken = 0,alive = true}
  32. }
  33. }
  34.  
  35. alive = {
  36. white = {
  37. }
  38. }
  39.  
  40. function getRealCoords(x,y)
  41.     return boardX + x - 1,boardY + y - 1
  42. end
  43.  
  44. function cntrdTxt(txt,x,y)
  45.     mon.setBackgroundColor(colors.black)
  46.     mon.setTextColor(colors.white)
  47.     mon.setCursorPos(offset(-1 * (math.floor(string.len(txt) / 2 + x ) - 1),"x"),1 + x)
  48.     mon.write(txt)
  49. end
  50.  
  51. mods = {}
  52.  
  53. function drawRow(side,x,y)
  54.     mon.setCursorPos(x,y)
  55.     for i=1,4 do
  56.         if side == 1 then
  57.             mon.setBackgroundColor(colors.red)
  58.             mon.write(" ")
  59.             mon.setBackgroundColor(colors.black)
  60.             mon.write(" ")
  61.         elseif side == 2 then
  62.             mon.setBackgroundColor(colors.black)
  63.             mon.write(" ")
  64.             mon.setBackgroundColor(colors.red)
  65.             mon.write(" ")
  66.         end
  67.     end
  68. end
  69.  
  70. function board()
  71.     local y = boardY
  72.     for i=1,4 do
  73.         drawRow(1,boardX,y)
  74.         y = y + 1
  75.         drawRow(2,boardX,y)
  76.         y = y + 1
  77.     end
  78. end
  79.  
  80. function mainMenu()
  81.     cntrdTxt("Checkers",0,0)
  82.     button.define("lcl","Local",offset(-6,"x"),offset(-1,"y"),colors.white,colors.red,true)
  83.     button.define("glbl","Globlal",offset(2,"x"),offset(-1,"y"),colors.lightGray,colors.gray,true)
  84.     button.draw("all")
  85.     button.deactivate("glbl")
  86.     local pressed = button.click()
  87.     button.deactivate("all")
  88.     button.erase("all")
  89.     return pressed
  90. end
  91.  
  92. function findPlayer()
  93.     local id = rednet.lookup("cg","cg")
  94.     if type(x) == number then
  95.         os.queueEvent("found_player",id)
  96.     end
  97. end
  98. print("Checkers util API (by minecraftwarlock) loaded")
  99.  
  100. function getMods(path)
  101.     if fs.exists(path) and fs.isDir(path) then
  102.         local rawmods = fs.list(path)
  103.         local mods = {}
  104.         for index,mod in ipairs(rawmods) do
  105.             if not fs.isDir(path.."/"..mod) then
  106.                 table.insert(mods,mod)
  107.             end
  108.         end
  109.         return mods
  110.     else
  111.         error("directory: "..path.." not found")
  112.     end
  113. end
  114.  
  115. function drawWhite()
  116.     for i in pairs(pieces[white]) do
  117.         button.define(i,"X",getRealCoords(white[i][x],white[i][y]),colors.white,colors.red,false)
  118.     end
  119.     button.draw(white)
  120. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement