Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[Awale [v1.0]
- Remplacez Joueur1 et Joueur2 par les pseudos des joueurs pour la partie d'awalé (ligne 8)
- ]]
- players = {"Joueur1", "Joueur2" }
- score = {0,0}
- function init()
- tab = {4,4,4,4,4,4,4,4,4,4,4,4}
- local playerL = players
- local p1, p2 = playerL[1], playerL[2]
- local coordL = { 130, 230, 330, 430, 530, 630 }
- local addT = ui.addTA
- local upTA = ui.updateTextArea
- ui.addTextArea(0, "", playerL, 100, 100, 600, 120, 0x324650,0x324650,0.8,true)
- ui.addTextArea(-1, "", playerL, 100, 70, 600, 20, 0x324650,0x324650,0.8,true)
- updateScore()
- for id, x in ipairs(coordL) do
- addT(id, id, p1, x, 180, 100, 30,0, 0, 0, true)
- addT(id+6, id+6, p1, 760-x, 120, 100, 30,0, 0, 0, true)
- addT(id, id, p2, 760-x, 120, 100, 30,0, 0, 0, true)
- addT(id+6, id+6, p2, x, 180, 100, 30,0, 0, 0, true)
- end
- for id, v in ipairs(tab) do
- upTA(id, "<a href='event:"..tostring(id).."'>"..stringP(tab[id]).."</a>", playerL)
- end
- round = 1
- end
- function eventTextAreaCallback (id, name, call)
- if name == players[round] then
- if not(tab[id] == 0) and ((round==2 and id>6 and id<13) or (round==1 and id>0 and id<7)) then
- empty(id)
- round = (round%2)+1
- if testEndGame(round) then
- print('end')
- round = 3
- local s1, s2, p1, p2 = score[1], score[2], players[1], players[2]
- ui.updateTextArea(-1, s1==s2 and "Égalité" or s1>s2 and (p1..' remporte la partie : '..s1..'-'..s2) or (p2..' remporte la partie : '..s2..'-'..s1), players)
- end
- else
- print("mauvaise case")
- end
- end
- end
- function empty(id)
- print("in")
- toGive = tab[id]
- tab[id] = 0
- toDeliver(toGive, (id%12)+1)
- ui.updateTextArea(id, "<a href='event:"..tostring(id).."'>"..stringP(tab[id]).."</a>", players)
- end
- function toDeliver(nb, id)
- if nb == 1 then
- tab[id] = tab[id]+1
- if ( (round==1 and id>6 and id<13) or (round==2 and id>0 and id<7) ) and (tab[id] == 2 or tab[id] == 3) then -- si c'est bien sur une des cases de l'adversaire
- takeOut(id)
- end
- else
- tab[id] = tab[id]+1
- toDeliver(nb-1, (id%12)+1)
- end
- ui.updateTextArea(id, "<a href='event:"..tostring(id).."'>"..stringP(tab[id]).."</a>", players)
- end
- function takeOut(id)
- score[round] = score[round]+tab[id]
- tab[id] = 0
- if (id-1)%6 ~= 0 and (tab[id-1] == 3 or tab[id-1] == 2) then
- takeOut(id-1)
- else
- updateScore()
- end
- end
- function stringP(nb)
- if nb == 0 then return "0"
- elseif nb == 1 then return "•"
- else return "•"..stringP(nb-1)
- end
- end
- function updateScore()
- ui.updateTextArea(-1, players[1]..' : '..score[1]..'\t'..players[2]..' : '..score[2], playerL)
- end
- function testEndGame(roundA)
- pieces = 0
- for i=(roundA-1)*6+1, roundA*6 do
- pieces = pieces+tab[i]
- end
- print(pieces)
- return pieces == 0
- end
- ui.addPp = ui.addPopup
- ui.addTA = ui.addTextArea
- ui.updateTA = ui.updateTextArea
- ui.removeTA = ui.removeTextArea
- function ui.removeTA(id, name)
- if type(name) == "table" then
- local fct = ui.removeTA
- for _, n in ipairs(name) do
- fct(id, n)
- end
- else ui.removeTA(id, name)
- end
- end
- function ui.updateTextArea(id, text, name)
- if type(name) == "table" then
- local fct = ui.updateTA
- for _, n in ipairs(name) do
- fct(id, text, n)
- end
- else ui.updateTA(id, text, name)
- end
- end
- function ui.addTextArea(id, text, name, x, y, w, h, c1, c2, alp, fix)
- if type(name) == "table" then
- local fct = ui.addTA
- for _,n in ipairs(name) do
- print(n)
- fct(id, text, n, x, y, w, h, c1, c2, alp, fix)
- end
- else ui.addTA(id, text, name, x, y, w, h, c1, c2, alp, fix)
- end
- end
- function ui.addPopup(id, t, text, name, x, y, w, fix)
- if type(name) == "table" then
- local fct = ui.addPp
- for _, n in ipairs(name) do
- fct(id, t, text, n, x, y, fix)
- end
- else ui.addPp(id, t, text, name, x, y, fix)
- end
- end
- init()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement