Advertisement
Guest User

checkers

a guest
Aug 22nd, 2014
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 17.50 KB | None | 0 0
  1. local m = peripheral.wrap("right")
  2. local pieceType = {}
  3. local piece = {}
  4. local input
  5. local load = 0 --loading prank more so for school
  6. local turn
  7. local playerTurn = "Black"
  8. local rLeft = 12
  9. local bLeft = 12
  10. local invalids = 0
  11. local move = 0
  12. local jump = false
  13. local double = false
  14. local Over = 1
  15. local gameOver
  16.  
  17. function clearDisp()
  18.   m.setBackgroundColor(colors.black)
  19.   m.clear()
  20. end
  21.  
  22. function getXY(x,y)
  23.   x = x*3
  24.   y = y*2
  25.   return x,y
  26. end
  27.  
  28. function getAB(x,y)
  29.   local a = x/3
  30.   local b = y/2
  31.   return a,b
  32. end
  33.  
  34. function background()
  35.   m.setBackgroundColor(colors.white)
  36.   m.clear()
  37. end
  38.  
  39. function boardCol(x,y)
  40.   x,y = getCorner(x,y)
  41.   local invert = false
  42.   if y%4 ==0 then invert = true end
  43.   if (x%2==0) then
  44.     if invert  then return(colors.black) else return(colors.red) end
  45.   else
  46.     if invert then return(colors.red) else return(colors.black) end
  47.   end
  48. end
  49.  
  50. function boardCol2(x,y)
  51.   x,y = getCorner(x,y)
  52.   local invert = false
  53.   if y%4 ==0 then invert = true end
  54.   if (x%2==0) then
  55.     if invert  then return(1) else return(0) end
  56.   else
  57.     if invert then return(0) else return(1) end
  58.   end
  59. end
  60.  
  61. function getCorner(x,y)
  62.   if y%2~=0 then y=y-1 end
  63.   if x%3~=0 then x=x-1 end
  64.   if x%3~=0 then x=x-1 end
  65.   return x,y
  66. end
  67.  
  68. function drawBoard()
  69.   for y = 2, 17 do
  70.     for x = 3, 26 do
  71.       m.setBackgroundColor(boardCol(x,y))
  72.       m.setCursorPos(x,y)
  73.       m.write(" ")
  74.     end
  75.   end
  76. end
  77.  
  78. function drawPiece()
  79.   for a = 1,8 do
  80.     for b = 1,8 do
  81.       if piece[a][b] ~= nil then
  82.         local x,y = getXY(a,b)
  83.         x = x+1
  84.         m.setBackgroundColor(colors.black)
  85.         m.setCursorPos(x,y)
  86.         m.setTextColor(piece[a][b])
  87.         m.write(pieceType[a][b])
  88.       end
  89.     end
  90.   end
  91. end
  92.  
  93. function colorBoard(a,b)
  94.   local x,y = getXY(a,b)
  95.   local x1 = x
  96.   for i = 1,2 do
  97.     for c = 1,3 do
  98.       m.setCursorPos(x1,y)
  99.       m.setBackgroundColor(colors.white)
  100.       m.write(" ")
  101.        x1 = x1+1
  102.     end
  103.     y = y+1
  104.     x1 = x
  105.   end
  106.   drawPiece()
  107. end
  108.  
  109. function drawScoreboard()
  110.   if input == 0 then --english
  111.     m.setBackgroundColor(colors.white)
  112.     m.setTextColor(colors.black)
  113.     m.setCursorPos(30,2)
  114.     m.write("Popcorn's Checkers")
  115.     m.setCursorPos(38,3)
  116.     m.write("Game")
  117.     m.setCursorPos(30,5)
  118.     m.write("Turn #")
  119.     m.write(turn)
  120.     m.setCursorPos(30,7)
  121.     m.write(playerTurn.."'s turn")
  122.     m.setCursorPos(30,9)
  123.     m.write("Pieces left")
  124.     m.setCursorPos(30, 11)
  125.     m.setTextColor(colors.red)
  126.     m.write("R")
  127.     m.write(" : "..rLeft.."    ")
  128.     m.setTextColor(128) --grey
  129.     m.write("B")
  130.     m.write(" : "..bLeft)
  131.     m.setTextColor(colors.black)
  132.     m.setCursorPos(30, 13)
  133.     m.write("move #"..move)
  134.     --invalid
  135.     if invalids == 1 then
  136.       m.setCursorPos(30,15)
  137.       m.setBackgroundColor(colors.white)
  138.       m.setTextColor(colors.red)
  139.       m.write("Invalid Move")
  140.     elseif invalids == 2 then
  141.       m.setCursorPos(30,15)
  142.       m.setBackgroundColor(colors.white)
  143.       m.setTextColor(colors.red)
  144.       m.write("Must Jump!")
  145.     end
  146.     for g = 17,19  do
  147.       for h = 30, 49 do
  148.          m.setTextColor(colors.black)
  149.          m.setBackgroundColor(colors.green)
  150.          m.setCursorPos(h,g)
  151.          m.write(" ")
  152.        end
  153.     end
  154.     m.setCursorPos(31,18)
  155.     m.write("reset current move")
  156.     for h = 3, 9 do
  157.       m.setCursorPos(h,19)
  158.       m.setBackgroundColor(colors.green)   
  159.       m.write(" ")
  160.       m.setCursorPos(h,18)
  161.       m.setBackgroundColor(colors.green)   
  162.       m.write(" ")
  163.       m.setCursorPos(4,19)
  164.       m.write("quit")
  165.     end
  166.   elseif input == 1 then -- french
  167.  
  168.  
  169.     m.setBackgroundColor(colors.white)
  170.     m.setTextColor(colors.black)
  171.     m.setCursorPos(30,2)
  172.     m.write("jeu de dames")
  173.     m.setCursorPos(30,5)
  174.     m.write("tour #")
  175.     m.write(turn)
  176.     m.setCursorPos(30,7)
  177.     if playerTurn == "Black" then
  178.       m.write("Au tour de Noir")
  179.     elseif playerTurn == "Red" then
  180.       m.write("le tour de rouge")
  181.     end
  182.     m.setCursorPos(30,9)
  183.     m.write("pieces gauche")
  184.     m.setCursorPos(30, 11)
  185.     m.setTextColor(colors.red)
  186.     m.write("R")
  187.     m.write(" : "..rLeft.."    ")
  188.     m.setTextColor(128) --grey
  189.     m.write("N")
  190.     m.write(" : "..bLeft)
  191.     m.setTextColor(colors.black)
  192.     m.setCursorPos(30, 13)
  193.     m.write("deplacer #"..move)
  194.     --invalid
  195.     if invalids == 1 then
  196.       m.setCursorPos(30,15)
  197.       m.setBackgroundColor(colors.white)
  198.       m.setTextColor(colors.red)
  199.       m.write("mouvement invalide")
  200.     elseif invalids == 2 then
  201.       m.setCursorPos(30,15)
  202.       m.setBackgroundColor(colors.white)
  203.       m.setTextColor(colors.red)
  204.       m.write("doit Aller!")
  205.     end
  206.     for g = 17,19  do
  207.       for h = 30, 49 do
  208.          m.setTextColor(colors.black)
  209.          m.setBackgroundColor(colors.green)
  210.          m.setCursorPos(h,g)
  211.          m.write(" ")
  212.        end
  213.     end
  214.     m.setCursorPos(31,17)
  215.     m.write("reinitialiser")
  216.     m.setCursorPos(31,18)
  217.     m.write("mouvement")
  218.     m.setCursorPos(31,19)
  219.     m.write("actuel")
  220.     for h = 3, 9 do
  221.       m.setCursorPos(h,19)
  222.       m.setBackgroundColor(colors.green)   
  223.       m.write(" ")
  224.       m.setCursorPos(h,18)
  225.       m.setBackgroundColor(colors.green)   
  226.       m.write(" ")
  227.       m.setCursorPos(4,18)
  228.       m.write("cesser")
  229.       m.setCursorPos(4,19)
  230.       m.write("de")
  231.     end
  232.    
  233.   end
  234. end
  235.  
  236. function language()
  237.   --english button draw
  238.   m.setTextColor(colors.white)
  239.   for y = 4, 8 do
  240.     for x = 30 , 40 do
  241.       m.setBackgroundColor(colors.green)
  242.       m.setCursorPos(x,y)
  243.       m.write(" ")
  244.     end
  245.   end
  246.   m.setCursorPos(32,6)
  247.   m.write("English")
  248.   --french button draw
  249.   for y = 10, 14 do
  250.     for x = 30, 40 do
  251.       m.setBackgroundColor(colors.green)
  252.       m.setCursorPos(x,y)
  253.       m.write(" ")
  254.     end
  255.   end
  256.   m.setCursorPos(32,12)
  257.   m.write("French")
  258.   --draw question
  259.   m.setBackgroundColor(colors.red)
  260.   m.setCursorPos(30,2)
  261.   m.write("select your language")
  262.   --get userinput
  263.   local inputDone = false
  264.   while inputDone == false do
  265.     local even, side, xpos, ypos = os.pullEvent("monitor_touch")
  266.     if xpos >= 30 and ypos >= 10 and xpos <= 40 and ypos <= 14 then
  267.       inputDone = true --french
  268.       input = 1
  269.     end
  270.     if xpos >= 30 and ypos >=4 and xpos <= 40 and ypos <= 8 then
  271.     inputDone = true --english
  272.     input = 0
  273.     end  
  274.   end
  275.   --show answer
  276.   clearDisp()
  277.   for y = 5, 10 do
  278.     for x = 10, 38 do
  279.       m.setBackgroundColor(colors.red)
  280.       m.setCursorPos(x,y)
  281.       m.write(" ")
  282.     end
  283.   end
  284.   m.setCursorPos(13,7)
  285.   if input == 0 then
  286.     m.write("your answer was english")
  287.   end
  288.   if input == 1 then
  289.     m.write("your answer was french")
  290.   end
  291.   --sleep(5)
  292.   m.setBackgroundColor(colors.black)
  293.   clearDisp()
  294.   if load == 1 then
  295.     m.setCursorPos(13,7)
  296.     m.write("initiating...")
  297.     sleep(5)
  298.     clearDisp()
  299.     m.setCursorPos(13,7)
  300.     m.write("now i'm loading")
  301.     sleep(2)
  302.     clearDisp()
  303.     m.setCursorPos(13,7)
  304.     m.write("more loading")
  305.     sleep(3)
  306.     clearDisp()
  307.     m.setCursorPos(13,7)
  308.     m.write("yay I'm Completed")
  309.   end
  310. end
  311.  
  312.  
  313.  
  314.  
  315. function initPiece()
  316.   for i = 1,8 do
  317.     piece[i] = {}
  318.   end
  319.   for i = 1,8 do
  320.     pieceType[i] = {}
  321.   end
  322.   --grays  
  323.   piece[1][1] = 256
  324.   piece[3][1] = 256
  325.   piece[5][1] = 256
  326.   piece[7][1] = 256
  327.   piece[2][2] = 256
  328.   piece[4][2] = 256
  329.   piece[6][2] = 256
  330.   piece[8][2] = 256
  331.   piece[1][3] = 256
  332.   piece[3][3] = 256
  333.   piece[5][3] = 256
  334.   piece[7][3] = 256
  335.   pieceType[1][1] = "X"
  336.   pieceType[3][1] = "X"
  337.   pieceType[5][1] = "X"
  338.   pieceType[7][1] = "X"
  339.   pieceType[2][2] = "X"
  340.   pieceType[4][2] = "X"
  341.   pieceType[6][2] = "X"
  342.   pieceType[8][2] = "X"
  343.   pieceType[1][3] = "X"
  344.   pieceType[3][3] = "X"
  345.   pieceType[5][3] = "X"
  346.   pieceType[7][3] = "X"
  347.   --pinks
  348.   piece[2][6] = 64
  349.   piece[4][6] = 64
  350.   piece[6][6] = 64
  351.   piece[8][6] = 64
  352.   piece[1][7] = 64
  353.   piece[3][7] = 64
  354.   piece[5][7] = 64
  355.   piece[7][7] = 64
  356.   piece[2][8] = 64
  357.   piece[4][8] = 64
  358.   piece[6][8] = 64
  359.   piece[8][8] = 64
  360.  
  361.   pieceType[2][6] = "X"
  362.   pieceType[4][6] = "X"
  363.   pieceType[6][6] = "X"
  364.   pieceType[8][6] = "X"
  365.   pieceType[1][7] = "X"
  366.   pieceType[3][7] = "X"
  367.   pieceType[5][7] = "X"
  368.   pieceType[7][7] = "X"
  369.   pieceType[2][8] = "X"
  370.   pieceType[4][8] = "X"
  371.   pieceType[6][8] = "X"
  372.   pieceType[8][8] = "X"
  373. end
  374.  
  375. function rMove(x,y)
  376.   if x >= 30 and y >= 17 and x<=49 and y <= 19 then
  377.     move = 1
  378.     for g = 17, 19 do
  379.       for h = 30, 49 do
  380.         m.setBackgroundColor(colors.red)
  381.         m.setCursorPos(h,g)
  382.         m.write(" ")
  383.       end
  384.     end
  385.     return true
  386.   end
  387. end
  388.  
  389. function invertCol()
  390.   if playerTurn == "Black" then
  391.     playerTurn = "Red"
  392.     turn = turn+1
  393.   elseif playerTurn == "Red" then
  394.     playerTurn = "Black"
  395.     turn = turn+1
  396.   end
  397. end
  398.  
  399. function inBoard(x,y)
  400.   x,y = getCorner(x,y)
  401.   x,y = getAB(x,y)
  402.   if x >= 1 and y >= 1 and x <= 8 and y <= 8 then
  403.     return true
  404.   else
  405.     invalid()
  406.     return false
  407.   end
  408. end
  409.  
  410. function waitPlayer()
  411.   endCheck()
  412.   jump = false
  413.  
  414.   move = 1
  415.  
  416.   local tempColor = 0
  417.   render()
  418.   local even, side, x, y = os.pullEvent("monitor_touch")
  419.   x,y = getCorner(x,y)
  420.   move = 2
  421.   if rMove(x,y) == true then
  422.     return
  423.   end
  424.   quit(x,y)
  425.   valid = inBoard(x,y)
  426.   render()
  427.   local v1 = 0
  428.   local v2 = 0
  429.   v1 =  boardCol2(x,y)
  430.   local a,b = getAB(x,y)
  431.   local even, side, x, y = os.pullEvent("monitor_touch")
  432.   move = 1
  433.   render()
  434.   quit(x,y)
  435.   if rMove(x,y) == true then
  436.     return
  437.   end
  438.   v2 = boardCol2(x,y)
  439.   local a2,b2 = a,b
  440.   local x,y = getCorner(x,y)
  441.   local a,b = getAB(x,y)
  442.   valid = inBoard(x,y)
  443.   --moves
  444.   --move normal
  445.   tempColor = myTurn(tempColor)
  446.   anyJump()
  447.   if pieceType[a2][b2] ~= nil and v1 == 1 and v2 == 1 and piece[a2][b2] == tempColor and jump == false then
  448.     local valid = false
  449.     valid = validN(a,b,a2,b2)
  450.     if pieceType[a][b] == nil and valid == true then
  451.       piece[a][b] = piece[a2][b2]
  452.       pieceType[a][b] = pieceType[a2][b2]
  453.       piece[a2][b2] = nil
  454.       pieceType[a2][b2] = nil
  455.       invalids = 0
  456.       invertCol()
  457.       kingMe(a,b)
  458.       render()
  459.     else
  460.       if tryJump(a,b,a2,b2) == false then
  461.         invalid()
  462.       end
  463.     end
  464.  
  465.   else
  466.     if jump == true then
  467.       invalids = 2
  468.     end
  469.     if tryJump(a,b,a2,b2) == false and invalids ~= 2 then
  470.       invalid()
  471.     end
  472.   end
  473.   render()
  474.   anyJump()
  475. end
  476.  
  477. function anyJump()
  478.   for a = 1,8 do
  479.     for b = 1,8 do
  480.       local tempColor = 0
  481.       tempColor = myTurn(tempColor)
  482.       if canDouble(a,b) and piece[a][b] == tempColor  then
  483.         jump = true
  484.        
  485.       end
  486.     end
  487.   end
  488. end
  489.  
  490. function validJump(a,b,a2,b2)
  491.    local tempColor = 0
  492.    
  493.  
  494.    
  495.    if a == nil or b == nil then return false end
  496.    if a2 == nil or b2 == nil then return false end
  497.    if a<1 or a>8 or b<1 or b>8 then return false end
  498.    if a2<1 or a2>8 or b2<1 or b2>8 then return false end
  499.    if b == b2-2 and myTurn(tempColor) == 256 then
  500.    elseif b == b2+2 and myTurn(tempColor) == 64 then
  501.    elseif pieceType[a][b] == "K" then
  502.    else
  503.      return false
  504.    end  
  505.    
  506.    if math.abs(a-a2)~=2 or math.abs(b-b2)~=2 then
  507.      return false
  508.    end
  509.    if piece[a2][b2] ~= nil then return false end
  510.    if piece[(a+a2)/2][(b+b2)/2] == nil then return false end
  511.    if piece[(a+a2)/2][(b+b2)/2] == myTurn(tempColor) then
  512.      return false
  513.    else
  514.    end
  515.    return true
  516. end
  517.  
  518. function tryJump(a2,b2,a,b)
  519.  
  520.   if validJump(a,b,a2,b2) == true then
  521.     redstone.setOutput("back", false)
  522.     sleep(0.2)
  523.     redstone.setOutput("back", true)
  524.     scoreChange(piece[(a+a2)/2][(b+b2)/2])
  525.     piece[a2][b2] = piece[a][b]
  526.     pieceType[a2][b2] = pieceType[a][b]
  527.     piece[(a+a2)/2][(b+b2)/2] = nil
  528.     pieceType[(a+a2)/2][(b+b2)/2] = nil
  529.     pieceType[a][b] = nil
  530.     piece[a][b] = nil
  531.     render()
  532.     kingMe(a2,b2)
  533.     render()
  534.     doubleJ(a2,b2)
  535.     invertCol()
  536.     render()
  537.     invalids = 0
  538.     return true
  539.   end
  540.   return false
  541. end
  542.  
  543. function doubleJ(a,b)
  544.   while canDouble(a,b) == true do
  545.     move = 2
  546.     render()
  547.     colorBoard(a,b)
  548.     local even, side, x, y = os.pullEvent("monitor_touch")
  549.     x, y = getCorner(x,y)
  550.     local a2,b2 = getAB(x,y)
  551.     move = 2
  552.     render()
  553.     if validJump(a,b,a2,b2) == true then
  554.       scoreChange(piece[(a+a2)/2][(b+b2)/2])
  555.       piece[a2][b2] = piece[a][b]
  556.       pieceType[a2][b2] = pieceType[a][b]
  557.       piece[(a+a2)/2][(b+b2)/2] = nil
  558.       pieceType[(a+a2)/2][(b+b2)/2] = nil
  559.       pieceType[a][b] = nil
  560.       piece[a][b] = nil
  561.       a = a2
  562.       b = b2
  563.     end
  564.     kingMe(a,b)
  565.     render()
  566.   end
  567. end
  568.  
  569. function canDouble(a2,b2)
  570.   double = false
  571.   if validJump(a2,b2,a2+2,b2+2) then
  572.     double = true
  573.   end -- greys
  574.   if validJump(a2,b2,a2-2,b2+2) then
  575.     double = true
  576.   end --greys
  577.   if validJump(a2,b2,a2+2,b2-2) then
  578.     double = true
  579.   end --pinks
  580.   if validJump(a2,b2,a2-2,b2-2) then
  581.     double = true
  582.   end --pinks
  583.   return double
  584. end  
  585.  
  586. function myTurn(tempColor)
  587.   if playerTurn == "Black" then
  588.     tempColor = 256
  589.   elseif playerTurn == "Red" then
  590.     tempColor = 64
  591.   end
  592.   return(tempColor)
  593. end
  594.  
  595. function kingMe(a,b)
  596.     if piece[a][b] == 256 and b == 8 and pieceType[a][b] == "X" then
  597.       pieceType[a][b] = "K"
  598.     end
  599.  if piece[a][b] == 64 and b == 1 and pieceType[a][b] == "X" then
  600.       pieceType[a][b] = "K"
  601.     end
  602. end
  603.  
  604.  
  605.  
  606. function validN(a,b,a2,b2)
  607.   local tA,tB = a,b
  608.   --down right -greys
  609.   local tA1 = a2+1
  610.   local tB1= b2+1
  611.   --down left - greys
  612.   local tA3 = a2-1
  613.   local tB3 = b2+1
  614.   --up left -pinks
  615.   local tA2 = a2-1
  616.   local tB2 = b2-1
  617.   --up right - pinks
  618.   local tA4 = a2+1
  619.   local tB4 = b2-1
  620.   if tA1 == a and tB1 == b and pieceType[a2][b2] == "K" then
  621.     return true
  622.   elseif tA2 == a and tB2 == b and pieceType[a2][b2] == "K" then
  623.     return true
  624.   elseif tA3 == a and tB3 == b and pieceType[a2][b2] == "K" then
  625.     return true
  626.   elseif tA4 == a and tB4 == b and pieceType[a2][b2] == "K" then
  627.     return true
  628.   elseif tA1 == a and tB1 == b and piece[a2][b2] == 256 then
  629.     return true
  630.   elseif tA2 == a and tB2 == b and piece[a2][b2] == 64 then
  631.     return true
  632.   elseif tA3 == a and tB3 == b and piece[a2][b2] == 256 then
  633.     return true
  634.   elseif tA4 == a and tB4 == b and piece[a2][b2] == 64 then
  635.     return true
  636.   else
  637.     return false
  638.   end
  639. end
  640.  
  641. function invalid()
  642.     invalids = 1
  643.     render()
  644.  
  645. end
  646.  
  647. function render()
  648.   m.setBackgroundColor(colors.white)
  649.   m.clear()
  650.   drawBoard()
  651.   drawScoreboard()
  652.   drawPiece()
  653. end
  654.  
  655. function quit(x,y)
  656.   invalids = 0
  657.   render()
  658.   if x >= 3  and y >= 18  and x <= 9 and y <= 19 then
  659.     for g = 3, 9 do
  660.       m.setBackgroundColor(colors.red)
  661.       m.setCursorPos(g,19)
  662.       m.write(" ")
  663.       m.setCursorPos(g,18)
  664.       m.write(" ")
  665.       m.setCursorPos(4,19)
  666.       if input == 0 then
  667.         m.write("quit")
  668.       elseif input == 1 then
  669.         m.write("quitter")
  670.       end
  671.     end
  672.   m.setBackgroundColor(colors.white)
  673.   m.clear()
  674.   m.setCursorPos(30,2)
  675.   m.setTextColor(colors.black)
  676.  
  677.   if input == 0 then
  678.     m.write("Do You Really Want To")
  679.     m.setCursorPos(30,3)
  680.     m.write("quit?")
  681.   elseif input == 1 then
  682.         m.write("voulez-vous vraiment a")
  683.     m.setCursorPos(30,3)
  684.     m.write("quitter?")
  685.   end
  686.  
  687.   for y = 4, 8 do
  688.     for x = 30, 40 do
  689.       m.setBackgroundColor(colors.green)
  690.       m.setCursorPos(x,y)
  691.       m.write(" ")   
  692.     end
  693.   end
  694.   m.setCursorPos(32,6)
  695.   if input == 0 then
  696.     m.write("Yes?")
  697.   elseif input == 1 then
  698.     m.write("oui")
  699.   end
  700.  
  701.   for y = 10, 14 do
  702.     for x = 30, 40 do
  703.       m.setBackgroundColor(colors.green)
  704.       m.setCursorPos(x,y)
  705.       m.write(" ")   
  706.     end
  707.   end
  708.   m.setCursorPos(32,12)
  709.   if input == 0 then
  710.     m.write("No?")
  711.   elseif input == 1 then
  712.     m.write("non")
  713.   end
  714.   local even, side, x, y = os.pullEvent("monitor_touch")
  715.   if x >= 30 and y >= 10 and x <= 40 and y <= 14 then
  716.     for y = 10, 14 do
  717.       for x = 30, 40 do
  718.         m.setBackgroundColor(colors.red)
  719.         m.setCursorPos(x,y)
  720.         m.write(" ")     
  721.       end  
  722.     end
  723.     m.setCursorPos(32,12)
  724.     if input == 0 then
  725.       m.write("No?")
  726.     elseif input == 1 then
  727.       m.write("non")
  728.     end
  729.     sleep(2)
  730.     return
  731.   end
  732.   if x >= 30 and y >= 4 and x <= 40 and y <= 8 then
  733.     for y = 4, 8 do
  734.       for x = 30, 40 do
  735.         m.setBackgroundColor(colors.red)
  736.         m.setCursorPos(x,y)
  737.         m.write(" ")     
  738.       end  
  739.     end
  740.     m.setCursorPos(32,6)
  741.     if input == 0 then
  742.       m.write("Yes?")  
  743.     elseif input == 1 then
  744.       m.write("oui")
  745.     end
  746.     sleep(2)
  747.     os.reboot()
  748.   end
  749.   sleep(5)
  750.   render()
  751.   end
  752. end
  753.  
  754. function scoreChange(colors)
  755.   local tempColor
  756.   if myTurn(tempColor) ~= colors then
  757.     if colors == 256 then
  758.       bLeft = bLeft-1
  759.     elseif colors == 64 then
  760.       rLeft = rLeft-1
  761.     end
  762.   end
  763. end
  764.  
  765. function endCheck()
  766.   if rLeft == 0 then
  767.     gameOver = 2
  768.     Over = 2
  769.     gameover()
  770.   end
  771.   if bLeft == 0 then
  772.     gameOver = 1
  773.     Over = 2
  774.      gameover()
  775.   end
  776. end
  777.  
  778. function gameover()
  779.   clearDisp()
  780.   m.setBackgroundColor(colors.white)
  781.   m.clear()
  782.   m.setCursorPos(10,8)
  783.   if gameOver == 1 and input == 0 then
  784.     m.setTextColor(colors.red)
  785.     m.write("You Win")
  786.     m.setCursorPos(25,8)
  787.     m.setTextColor(colors.black)
  788.     m.write("You Loose")
  789.   elseif gameOver == 2 and input == 0 then
  790.     m.setTextColor(colors.black)
  791.     m.write("You Win")
  792.     m.setCursorPos(25,8)
  793.     m.setTextColor(colors.red)
  794.     m.write("You Loose")
  795.   elseif gameOver == 1 and input == 1 then
  796.     m.setTextColor(colors.red)
  797.     m.write("vous Wom")
  798.     m.setCursorPos(25,8)
  799.     m.setTextColor(colors.black)
  800.     m.write("vous perdez")
  801.   elseif gameOver == 2 and input == 1 then
  802.     m.setTextColor(colors.black)
  803.     m.write("vous Wom")
  804.     m.setCursorPos(25,8)
  805.     m.setTextColor(colors.red)
  806.     m.write("vous perdez")
  807.   end
  808.  
  809.   sleep(10)
  810. end
  811.  
  812. turn = 1
  813. clearDisp()
  814. background()
  815. drawBoard()
  816. language()
  817. background()
  818. drawBoard()
  819. drawScoreboard()
  820. initPiece()
  821. drawPiece()
  822. while Over == 1 do
  823.   render()
  824.   waitPlayer()
  825.   render()
  826. end
  827. --gameover()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement