Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if not os.loadAPI("button") then
- error("Checkers util API requires the button API by minecraftwarlock to run")
- end
- mon = peripheral.wrap("left")
- button.default()
- local xSize,ySize = mon.getSize()
- function offset(x,coord)
- if string.lower(coord) == "x" then
- return math.floor(xSize / 2) + x
- elseif string.lower(coord) == "y" then
- return math.floor(ySize / 2) + x
- end
- end
- local boardX = offset(-3,"x")
- local boardY = offset(-3,"y")
- menuButtons = {}
- pieces = {
- white = {
- piece1 = {x = 1,y = 1,moves = 0,taken = 0,alive = true},piece2 = {x = 1,y = 3,moves = 0,taken = 0,alive = true},
- piece3 = {x = 1,y = 5,moves = 0,taken = 0,alive = true},piece4 = {x = 1,y = 7,moves = 0,taken = 0,alive = true},
- piece5 = {x = 2,y = 2,moves = 0,taken = 0,alive = true},piece6 = {x = 2,y = 4,moves = 0,taken = 0,alive = true},
- piece7 = {x = 2,y = 6,moves = 0,taken = 0,alive = true},piece8 = {x = 2,y = 8,moves = 0,taken = 0,alive = true},
- piece9 = {x = 3,y = 1,moves = 0,taken = 0,alive = true},piece10 = {x = 3,y = 3,moves = 0,taken = 0,alive = true},
- piece11 = {x = 3,y = 5,moves = 0,taken = 0,alive = true},piece12 = {x = 3,y = 7,moves = 0,taken = 0,alive = true}
- }
- }
- alive = {
- white = {
- }
- }
- function getRealCoords(x,y)
- return boardX + x - 1,boardY + y - 1
- end
- function cntrdTxt(txt,x,y)
- mon.setBackgroundColor(colors.black)
- mon.setTextColor(colors.white)
- mon.setCursorPos(offset(-1 * (math.floor(string.len(txt) / 2 + x ) - 1),"x"),1 + x)
- mon.write(txt)
- end
- mods = {}
- function drawRow(side,x,y)
- mon.setCursorPos(x,y)
- for i=1,4 do
- if side == 1 then
- mon.setBackgroundColor(colors.red)
- mon.write(" ")
- mon.setBackgroundColor(colors.black)
- mon.write(" ")
- elseif side == 2 then
- mon.setBackgroundColor(colors.black)
- mon.write(" ")
- mon.setBackgroundColor(colors.red)
- mon.write(" ")
- end
- end
- end
- function board()
- local y = boardY
- for i=1,4 do
- drawRow(1,boardX,y)
- y = y + 1
- drawRow(2,boardX,y)
- y = y + 1
- end
- end
- function mainMenu()
- cntrdTxt("Checkers",0,0)
- button.define("lcl","Local",offset(-6,"x"),offset(-1,"y"),colors.white,colors.red,true)
- button.define("glbl","Globlal",offset(2,"x"),offset(-1,"y"),colors.lightGray,colors.gray,true)
- button.draw("all")
- button.deactivate("glbl")
- local pressed = button.click()
- button.deactivate("all")
- button.erase("all")
- return pressed
- end
- function findPlayer()
- local id = rednet.lookup("cg","cg")
- if type(x) == number then
- os.queueEvent("found_player",id)
- end
- end
- print("Checkers util API (by minecraftwarlock) loaded")
- function getMods(path)
- if fs.exists(path) and fs.isDir(path) then
- local rawmods = fs.list(path)
- local mods = {}
- for index,mod in ipairs(rawmods) do
- if not fs.isDir(path.."/"..mod) then
- table.insert(mods,mod)
- end
- end
- return mods
- else
- error("directory: "..path.." not found")
- end
- end
- function drawWhite()
- for i in pairs(pieces[white]) do
- button.define(i,"X",getRealCoords(white[i][x],white[i][y]),colors.white,colors.red,false)
- end
- button.draw(white)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement