Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local m = peripheral.wrap("right")
- local pieceType = {}
- local piece = {}
- local input
- local load = 0 --loading prank more so for school
- local turn
- local playerTurn = "Black"
- local rLeft = 12
- local bLeft = 12
- local invalids = 0
- local move = 0
- local jump = false
- local double = false
- local Over = 1
- local gameOver
- function clearDisp()
- m.setBackgroundColor(colors.black)
- m.clear()
- end
- function getXY(x,y)
- x = x*3
- y = y*2
- return x,y
- end
- function getAB(x,y)
- local a = x/3
- local b = y/2
- return a,b
- end
- function background()
- m.setBackgroundColor(colors.white)
- m.clear()
- end
- function boardCol(x,y)
- x,y = getCorner(x,y)
- local invert = false
- if y%4 ==0 then invert = true end
- if (x%2==0) then
- if invert then return(colors.black) else return(colors.red) end
- else
- if invert then return(colors.red) else return(colors.black) end
- end
- end
- function boardCol2(x,y)
- x,y = getCorner(x,y)
- local invert = false
- if y%4 ==0 then invert = true end
- if (x%2==0) then
- if invert then return(1) else return(0) end
- else
- if invert then return(0) else return(1) end
- end
- end
- function getCorner(x,y)
- if y%2~=0 then y=y-1 end
- if x%3~=0 then x=x-1 end
- if x%3~=0 then x=x-1 end
- return x,y
- end
- function drawBoard()
- for y = 2, 17 do
- for x = 3, 26 do
- m.setBackgroundColor(boardCol(x,y))
- m.setCursorPos(x,y)
- m.write(" ")
- end
- end
- end
- function drawPiece()
- for a = 1,8 do
- for b = 1,8 do
- if piece[a][b] ~= nil then
- local x,y = getXY(a,b)
- x = x+1
- m.setBackgroundColor(colors.black)
- m.setCursorPos(x,y)
- m.setTextColor(piece[a][b])
- m.write(pieceType[a][b])
- end
- end
- end
- end
- function colorBoard(a,b)
- local x,y = getXY(a,b)
- local x1 = x
- for i = 1,2 do
- for c = 1,3 do
- m.setCursorPos(x1,y)
- m.setBackgroundColor(colors.white)
- m.write(" ")
- x1 = x1+1
- end
- y = y+1
- x1 = x
- end
- drawPiece()
- end
- function drawScoreboard()
- if input == 0 then --english
- m.setBackgroundColor(colors.white)
- m.setTextColor(colors.black)
- m.setCursorPos(30,2)
- m.write("Popcorn's Checkers")
- m.setCursorPos(38,3)
- m.write("Game")
- m.setCursorPos(30,5)
- m.write("Turn #")
- m.write(turn)
- m.setCursorPos(30,7)
- m.write(playerTurn.."'s turn")
- m.setCursorPos(30,9)
- m.write("Pieces left")
- m.setCursorPos(30, 11)
- m.setTextColor(colors.red)
- m.write("R")
- m.write(" : "..rLeft.." ")
- m.setTextColor(128) --grey
- m.write("B")
- m.write(" : "..bLeft)
- m.setTextColor(colors.black)
- m.setCursorPos(30, 13)
- m.write("move #"..move)
- --invalid
- if invalids == 1 then
- m.setCursorPos(30,15)
- m.setBackgroundColor(colors.white)
- m.setTextColor(colors.red)
- m.write("Invalid Move")
- elseif invalids == 2 then
- m.setCursorPos(30,15)
- m.setBackgroundColor(colors.white)
- m.setTextColor(colors.red)
- m.write("Must Jump!")
- end
- for g = 17,19 do
- for h = 30, 49 do
- m.setTextColor(colors.black)
- m.setBackgroundColor(colors.green)
- m.setCursorPos(h,g)
- m.write(" ")
- end
- end
- m.setCursorPos(31,18)
- m.write("reset current move")
- for h = 3, 9 do
- m.setCursorPos(h,19)
- m.setBackgroundColor(colors.green)
- m.write(" ")
- m.setCursorPos(h,18)
- m.setBackgroundColor(colors.green)
- m.write(" ")
- m.setCursorPos(4,19)
- m.write("quit")
- end
- elseif input == 1 then -- french
- m.setBackgroundColor(colors.white)
- m.setTextColor(colors.black)
- m.setCursorPos(30,2)
- m.write("jeu de dames")
- m.setCursorPos(30,5)
- m.write("tour #")
- m.write(turn)
- m.setCursorPos(30,7)
- if playerTurn == "Black" then
- m.write("Au tour de Noir")
- elseif playerTurn == "Red" then
- m.write("le tour de rouge")
- end
- m.setCursorPos(30,9)
- m.write("pieces gauche")
- m.setCursorPos(30, 11)
- m.setTextColor(colors.red)
- m.write("R")
- m.write(" : "..rLeft.." ")
- m.setTextColor(128) --grey
- m.write("N")
- m.write(" : "..bLeft)
- m.setTextColor(colors.black)
- m.setCursorPos(30, 13)
- m.write("deplacer #"..move)
- --invalid
- if invalids == 1 then
- m.setCursorPos(30,15)
- m.setBackgroundColor(colors.white)
- m.setTextColor(colors.red)
- m.write("mouvement invalide")
- elseif invalids == 2 then
- m.setCursorPos(30,15)
- m.setBackgroundColor(colors.white)
- m.setTextColor(colors.red)
- m.write("doit Aller!")
- end
- for g = 17,19 do
- for h = 30, 49 do
- m.setTextColor(colors.black)
- m.setBackgroundColor(colors.green)
- m.setCursorPos(h,g)
- m.write(" ")
- end
- end
- m.setCursorPos(31,17)
- m.write("reinitialiser")
- m.setCursorPos(31,18)
- m.write("mouvement")
- m.setCursorPos(31,19)
- m.write("actuel")
- for h = 3, 9 do
- m.setCursorPos(h,19)
- m.setBackgroundColor(colors.green)
- m.write(" ")
- m.setCursorPos(h,18)
- m.setBackgroundColor(colors.green)
- m.write(" ")
- m.setCursorPos(4,18)
- m.write("cesser")
- m.setCursorPos(4,19)
- m.write("de")
- end
- end
- end
- function language()
- --english button draw
- m.setTextColor(colors.white)
- for y = 4, 8 do
- for x = 30 , 40 do
- m.setBackgroundColor(colors.green)
- m.setCursorPos(x,y)
- m.write(" ")
- end
- end
- m.setCursorPos(32,6)
- m.write("English")
- --french button draw
- for y = 10, 14 do
- for x = 30, 40 do
- m.setBackgroundColor(colors.green)
- m.setCursorPos(x,y)
- m.write(" ")
- end
- end
- m.setCursorPos(32,12)
- m.write("French")
- --draw question
- m.setBackgroundColor(colors.red)
- m.setCursorPos(30,2)
- m.write("select your language")
- --get userinput
- local inputDone = false
- while inputDone == false do
- local even, side, xpos, ypos = os.pullEvent("monitor_touch")
- if xpos >= 30 and ypos >= 10 and xpos <= 40 and ypos <= 14 then
- inputDone = true --french
- input = 1
- end
- if xpos >= 30 and ypos >=4 and xpos <= 40 and ypos <= 8 then
- inputDone = true --english
- input = 0
- end
- end
- --show answer
- clearDisp()
- for y = 5, 10 do
- for x = 10, 38 do
- m.setBackgroundColor(colors.red)
- m.setCursorPos(x,y)
- m.write(" ")
- end
- end
- m.setCursorPos(13,7)
- if input == 0 then
- m.write("your answer was english")
- end
- if input == 1 then
- m.write("your answer was french")
- end
- --sleep(5)
- m.setBackgroundColor(colors.black)
- clearDisp()
- if load == 1 then
- m.setCursorPos(13,7)
- m.write("initiating...")
- sleep(5)
- clearDisp()
- m.setCursorPos(13,7)
- m.write("now i'm loading")
- sleep(2)
- clearDisp()
- m.setCursorPos(13,7)
- m.write("more loading")
- sleep(3)
- clearDisp()
- m.setCursorPos(13,7)
- m.write("yay I'm Completed")
- end
- end
- function initPiece()
- for i = 1,8 do
- piece[i] = {}
- end
- for i = 1,8 do
- pieceType[i] = {}
- end
- --grays
- piece[1][1] = 256
- piece[3][1] = 256
- piece[5][1] = 256
- piece[7][1] = 256
- piece[2][2] = 256
- piece[4][2] = 256
- piece[6][2] = 256
- piece[8][2] = 256
- piece[1][3] = 256
- piece[3][3] = 256
- piece[5][3] = 256
- piece[7][3] = 256
- pieceType[1][1] = "X"
- pieceType[3][1] = "X"
- pieceType[5][1] = "X"
- pieceType[7][1] = "X"
- pieceType[2][2] = "X"
- pieceType[4][2] = "X"
- pieceType[6][2] = "X"
- pieceType[8][2] = "X"
- pieceType[1][3] = "X"
- pieceType[3][3] = "X"
- pieceType[5][3] = "X"
- pieceType[7][3] = "X"
- --pinks
- piece[2][6] = 64
- piece[4][6] = 64
- piece[6][6] = 64
- piece[8][6] = 64
- piece[1][7] = 64
- piece[3][7] = 64
- piece[5][7] = 64
- piece[7][7] = 64
- piece[2][8] = 64
- piece[4][8] = 64
- piece[6][8] = 64
- piece[8][8] = 64
- pieceType[2][6] = "X"
- pieceType[4][6] = "X"
- pieceType[6][6] = "X"
- pieceType[8][6] = "X"
- pieceType[1][7] = "X"
- pieceType[3][7] = "X"
- pieceType[5][7] = "X"
- pieceType[7][7] = "X"
- pieceType[2][8] = "X"
- pieceType[4][8] = "X"
- pieceType[6][8] = "X"
- pieceType[8][8] = "X"
- end
- function rMove(x,y)
- if x >= 30 and y >= 17 and x<=49 and y <= 19 then
- move = 1
- for g = 17, 19 do
- for h = 30, 49 do
- m.setBackgroundColor(colors.red)
- m.setCursorPos(h,g)
- m.write(" ")
- end
- end
- return true
- end
- end
- function invertCol()
- if playerTurn == "Black" then
- playerTurn = "Red"
- turn = turn+1
- elseif playerTurn == "Red" then
- playerTurn = "Black"
- turn = turn+1
- end
- end
- function inBoard(x,y)
- x,y = getCorner(x,y)
- x,y = getAB(x,y)
- if x >= 1 and y >= 1 and x <= 8 and y <= 8 then
- return true
- else
- invalid()
- return false
- end
- end
- function waitPlayer()
- endCheck()
- jump = false
- move = 1
- local tempColor = 0
- render()
- local even, side, x, y = os.pullEvent("monitor_touch")
- x,y = getCorner(x,y)
- move = 2
- if rMove(x,y) == true then
- return
- end
- quit(x,y)
- valid = inBoard(x,y)
- render()
- local v1 = 0
- local v2 = 0
- v1 = boardCol2(x,y)
- local a,b = getAB(x,y)
- local even, side, x, y = os.pullEvent("monitor_touch")
- move = 1
- render()
- quit(x,y)
- if rMove(x,y) == true then
- return
- end
- v2 = boardCol2(x,y)
- local a2,b2 = a,b
- local x,y = getCorner(x,y)
- local a,b = getAB(x,y)
- valid = inBoard(x,y)
- --moves
- --move normal
- tempColor = myTurn(tempColor)
- anyJump()
- if pieceType[a2][b2] ~= nil and v1 == 1 and v2 == 1 and piece[a2][b2] == tempColor and jump == false then
- local valid = false
- valid = validN(a,b,a2,b2)
- if pieceType[a][b] == nil and valid == true then
- piece[a][b] = piece[a2][b2]
- pieceType[a][b] = pieceType[a2][b2]
- piece[a2][b2] = nil
- pieceType[a2][b2] = nil
- invalids = 0
- invertCol()
- kingMe(a,b)
- render()
- else
- if tryJump(a,b,a2,b2) == false then
- invalid()
- end
- end
- else
- if jump == true then
- invalids = 2
- end
- if tryJump(a,b,a2,b2) == false and invalids ~= 2 then
- invalid()
- end
- end
- render()
- anyJump()
- end
- function anyJump()
- for a = 1,8 do
- for b = 1,8 do
- local tempColor = 0
- tempColor = myTurn(tempColor)
- if canDouble(a,b) and piece[a][b] == tempColor then
- jump = true
- end
- end
- end
- end
- function validJump(a,b,a2,b2)
- local tempColor = 0
- if a == nil or b == nil then return false end
- if a2 == nil or b2 == nil then return false end
- if a<1 or a>8 or b<1 or b>8 then return false end
- if a2<1 or a2>8 or b2<1 or b2>8 then return false end
- if b == b2-2 and myTurn(tempColor) == 256 then
- elseif b == b2+2 and myTurn(tempColor) == 64 then
- elseif pieceType[a][b] == "K" then
- else
- return false
- end
- if math.abs(a-a2)~=2 or math.abs(b-b2)~=2 then
- return false
- end
- if piece[a2][b2] ~= nil then return false end
- if piece[(a+a2)/2][(b+b2)/2] == nil then return false end
- if piece[(a+a2)/2][(b+b2)/2] == myTurn(tempColor) then
- return false
- else
- end
- return true
- end
- function tryJump(a2,b2,a,b)
- if validJump(a,b,a2,b2) == true then
- redstone.setOutput("back", false)
- sleep(0.2)
- redstone.setOutput("back", true)
- scoreChange(piece[(a+a2)/2][(b+b2)/2])
- piece[a2][b2] = piece[a][b]
- pieceType[a2][b2] = pieceType[a][b]
- piece[(a+a2)/2][(b+b2)/2] = nil
- pieceType[(a+a2)/2][(b+b2)/2] = nil
- pieceType[a][b] = nil
- piece[a][b] = nil
- render()
- kingMe(a2,b2)
- render()
- doubleJ(a2,b2)
- invertCol()
- render()
- invalids = 0
- return true
- end
- return false
- end
- function doubleJ(a,b)
- while canDouble(a,b) == true do
- move = 2
- render()
- colorBoard(a,b)
- local even, side, x, y = os.pullEvent("monitor_touch")
- x, y = getCorner(x,y)
- local a2,b2 = getAB(x,y)
- move = 2
- render()
- if validJump(a,b,a2,b2) == true then
- scoreChange(piece[(a+a2)/2][(b+b2)/2])
- piece[a2][b2] = piece[a][b]
- pieceType[a2][b2] = pieceType[a][b]
- piece[(a+a2)/2][(b+b2)/2] = nil
- pieceType[(a+a2)/2][(b+b2)/2] = nil
- pieceType[a][b] = nil
- piece[a][b] = nil
- a = a2
- b = b2
- end
- kingMe(a,b)
- render()
- end
- end
- function canDouble(a2,b2)
- double = false
- if validJump(a2,b2,a2+2,b2+2) then
- double = true
- end -- greys
- if validJump(a2,b2,a2-2,b2+2) then
- double = true
- end --greys
- if validJump(a2,b2,a2+2,b2-2) then
- double = true
- end --pinks
- if validJump(a2,b2,a2-2,b2-2) then
- double = true
- end --pinks
- return double
- end
- function myTurn(tempColor)
- if playerTurn == "Black" then
- tempColor = 256
- elseif playerTurn == "Red" then
- tempColor = 64
- end
- return(tempColor)
- end
- function kingMe(a,b)
- if piece[a][b] == 256 and b == 8 and pieceType[a][b] == "X" then
- pieceType[a][b] = "K"
- end
- if piece[a][b] == 64 and b == 1 and pieceType[a][b] == "X" then
- pieceType[a][b] = "K"
- end
- end
- function validN(a,b,a2,b2)
- local tA,tB = a,b
- --down right -greys
- local tA1 = a2+1
- local tB1= b2+1
- --down left - greys
- local tA3 = a2-1
- local tB3 = b2+1
- --up left -pinks
- local tA2 = a2-1
- local tB2 = b2-1
- --up right - pinks
- local tA4 = a2+1
- local tB4 = b2-1
- if tA1 == a and tB1 == b and pieceType[a2][b2] == "K" then
- return true
- elseif tA2 == a and tB2 == b and pieceType[a2][b2] == "K" then
- return true
- elseif tA3 == a and tB3 == b and pieceType[a2][b2] == "K" then
- return true
- elseif tA4 == a and tB4 == b and pieceType[a2][b2] == "K" then
- return true
- elseif tA1 == a and tB1 == b and piece[a2][b2] == 256 then
- return true
- elseif tA2 == a and tB2 == b and piece[a2][b2] == 64 then
- return true
- elseif tA3 == a and tB3 == b and piece[a2][b2] == 256 then
- return true
- elseif tA4 == a and tB4 == b and piece[a2][b2] == 64 then
- return true
- else
- return false
- end
- end
- function invalid()
- invalids = 1
- render()
- end
- function render()
- m.setBackgroundColor(colors.white)
- m.clear()
- drawBoard()
- drawScoreboard()
- drawPiece()
- end
- function quit(x,y)
- invalids = 0
- render()
- if x >= 3 and y >= 18 and x <= 9 and y <= 19 then
- for g = 3, 9 do
- m.setBackgroundColor(colors.red)
- m.setCursorPos(g,19)
- m.write(" ")
- m.setCursorPos(g,18)
- m.write(" ")
- m.setCursorPos(4,19)
- if input == 0 then
- m.write("quit")
- elseif input == 1 then
- m.write("quitter")
- end
- end
- m.setBackgroundColor(colors.white)
- m.clear()
- m.setCursorPos(30,2)
- m.setTextColor(colors.black)
- if input == 0 then
- m.write("Do You Really Want To")
- m.setCursorPos(30,3)
- m.write("quit?")
- elseif input == 1 then
- m.write("voulez-vous vraiment a")
- m.setCursorPos(30,3)
- m.write("quitter?")
- end
- for y = 4, 8 do
- for x = 30, 40 do
- m.setBackgroundColor(colors.green)
- m.setCursorPos(x,y)
- m.write(" ")
- end
- end
- m.setCursorPos(32,6)
- if input == 0 then
- m.write("Yes?")
- elseif input == 1 then
- m.write("oui")
- end
- for y = 10, 14 do
- for x = 30, 40 do
- m.setBackgroundColor(colors.green)
- m.setCursorPos(x,y)
- m.write(" ")
- end
- end
- m.setCursorPos(32,12)
- if input == 0 then
- m.write("No?")
- elseif input == 1 then
- m.write("non")
- end
- local even, side, x, y = os.pullEvent("monitor_touch")
- if x >= 30 and y >= 10 and x <= 40 and y <= 14 then
- for y = 10, 14 do
- for x = 30, 40 do
- m.setBackgroundColor(colors.red)
- m.setCursorPos(x,y)
- m.write(" ")
- end
- end
- m.setCursorPos(32,12)
- if input == 0 then
- m.write("No?")
- elseif input == 1 then
- m.write("non")
- end
- sleep(2)
- return
- end
- if x >= 30 and y >= 4 and x <= 40 and y <= 8 then
- for y = 4, 8 do
- for x = 30, 40 do
- m.setBackgroundColor(colors.red)
- m.setCursorPos(x,y)
- m.write(" ")
- end
- end
- m.setCursorPos(32,6)
- if input == 0 then
- m.write("Yes?")
- elseif input == 1 then
- m.write("oui")
- end
- sleep(2)
- os.reboot()
- end
- sleep(5)
- render()
- end
- end
- function scoreChange(colors)
- local tempColor
- if myTurn(tempColor) ~= colors then
- if colors == 256 then
- bLeft = bLeft-1
- elseif colors == 64 then
- rLeft = rLeft-1
- end
- end
- end
- function endCheck()
- if rLeft == 0 then
- gameOver = 2
- Over = 2
- gameover()
- end
- if bLeft == 0 then
- gameOver = 1
- Over = 2
- gameover()
- end
- end
- function gameover()
- clearDisp()
- m.setBackgroundColor(colors.white)
- m.clear()
- m.setCursorPos(10,8)
- if gameOver == 1 and input == 0 then
- m.setTextColor(colors.red)
- m.write("You Win")
- m.setCursorPos(25,8)
- m.setTextColor(colors.black)
- m.write("You Loose")
- elseif gameOver == 2 and input == 0 then
- m.setTextColor(colors.black)
- m.write("You Win")
- m.setCursorPos(25,8)
- m.setTextColor(colors.red)
- m.write("You Loose")
- elseif gameOver == 1 and input == 1 then
- m.setTextColor(colors.red)
- m.write("vous Wom")
- m.setCursorPos(25,8)
- m.setTextColor(colors.black)
- m.write("vous perdez")
- elseif gameOver == 2 and input == 1 then
- m.setTextColor(colors.black)
- m.write("vous Wom")
- m.setCursorPos(25,8)
- m.setTextColor(colors.red)
- m.write("vous perdez")
- end
- sleep(10)
- end
- turn = 1
- clearDisp()
- background()
- drawBoard()
- language()
- background()
- drawBoard()
- drawScoreboard()
- initPiece()
- drawPiece()
- while Over == 1 do
- render()
- waitPlayer()
- render()
- end
- --gameover()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement