Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- platform.apilevel="1.0"
- new=false
- screen=1
- game=0
- themes={{{0,0,255},{0,255,0},{0,0,0},{230,230,150},{0,0,0},{0,0,0}},{{0,0,255},{0,255,0},{255,255,255},{0,0,0},{50,50,50},{0,0,255}},{{200,200,200},{100,100,100},{0,0,0},{255,255,255},{0,0,0},{0,0,0}}}
- colors=themes[1]
- titlecolors={{0,0,255},{255,0,0},{0,255,0}}
- w = 318
- lang = locale.name()
- textpaint = {{fr="ISOLA",en="ISOLA"},{fr="appuyez sur enter",en="press enter"},{fr="Joueur ",en="Player "},{fr="Move",en="Move"},{fr="Block",en="Block"}}
- textdial = {{fr="QUITTER?",en="QUIT?"},{fr="RECOMMENCER",en="RESET?"},{fr="y : Yes",en="y : Yes"},{fr="n : No",en="n : No"},{fr="Comment jouer",en="How to play"},{fr="A votre tour, déplacez",en="On your turn, move"},{fr="vous à votre guise",en="straight or diagonal"},{fr="placez ensuite un trou pour tenter",en="then place a hole to try"},{fr="de piéger votre adversaire.",en="to trap your opponent."},{fr="A propos",en="About"},{fr="Jeu de LD Studio",en="Game by LD Studio"},{fr="contact.ldstudios@gmail.com",en="contact.ldstudios@gmail.com"},{fr="www.ld-studios.weebly.com",en="www.ld-studios.weebly.com"},{fr="NOUVELLE PARTIE",en="NEW GAME"},{fr="1: 1 joueur",en="1: 1 player"},{fr="2: 2 joueurs",en="2: 2 players"},{fr="Joueur ",en="Player "},{fr="a gagné!",en="wins!"}}
- function drawCenteredString(gc,string,y)
- if lang == "fr" then
- gc:drawString(string.fr,w/2-gc:getStringWidth(string.fr)/2,y)
- else
- gc:drawString(string.en,w/2-gc:getStringWidth(string.en)/2,y)
- end
- end
- function drawString2(gc,string,x,y)
- if lang == "fr" then
- gc:drawString(string.fr,x,y)
- else
- gc:drawString(string.en,x,y)
- end
- end
- function on.paint(gc)
- if screen==1 then
- gc:setColorRGB(255,255,155)
- gc:fillRect(0,0,318,218)
- gc:setColorRGB(0,0,0)
- gc:setFont("sansserif","b",24)
- drawCenteredString(gc,textpaint[1],100)
- gc:setFont("sansserif","r",12)
- drawCenteredString(gc,textpaint[2],110)
- gc:setColorRGB(unpack(titlecolors[math.random(1,3)]))
- gc:fillRect(155,120,15,15)
- gc:setPen("medium")
- gc:drawRect(155,120,15,15)
- else
- gc:setColorRGB(unpack(colors[4]))
- gc:fillRect(90,35,9*15,9*15)
- for i=2,10 do
- local v=board[i]
- for ii=2,10 do
- if v[ii]>0 then
- gc:setColorRGB(unpack(colors[v[ii]]))
- gc:fillRect(ii*15+60,i*15+5,15,15)
- end
- gc:setColorRGB(unpack(colors[5]))
- gc:drawRect(ii*15+60,i*15+5,15,15)
- end
- end
- gc:setPen("medium")
- gc:setColorRGB(unpack(colors[6]))
- gc:drawRect(x*15+60,y*15+5,15,15)
- gc:setColorRGB(0,0,0)
- gc:setFont("sansserif","b",12)
- if lang=="fr" then
- tmp = textpaint[2]
- tmp2 = textpaint[3]
- gc:drawString(tmp.fr..tmp2.fr..":",240,100)
- else
- tmp = textpaint[2]
- tmp2 = textpaint[3]
- gc:drawString(tmp.en..tmp2.en..":",240,100)
- end
- if turn[1]==1 then
- drawString2(gc,textpaint[4],250,120)
- else
- drawString2(gc,textpaint[5],247,120)
- end
- if game>0 or box>0 or exit==true or re==true or new==true then
- drawDialog(gc)
- end
- end
- end
- function drawDialog(gc)
- gc:setColorRGB(155,155,155)
- gc:fillRect(80,50,155,100)
- gc:setColorRGB(0,0,0)
- gc:drawRect(80,50,155,100)
- if exit==true or re==true then
- gc:setFont("sansserif","b",24)
- if exit==true then
- drawCenteredString(gc,textdial[1],100)
- elseif re==true then
- drawCenteredString(gc,textdial[2],100)
- end
- gc:setFont("sansserif","b",10)
- drawString2(gc,textdial[3],140,125)
- drawString2(gc,textdial[4],142,140)
- elseif box>0 then
- gc:setFont("sansserif","b",12)
- if box==1 then
- drawCenteredString(gc,textdial[5],75)
- gc:setFont("sansserif","b",10)
- drawCenteredString(gc,textdial[6],95)
- drawCenteredString(gc,textdial[7],110)
- drawCenteredString(gc,textdial[8],125)
- drawCenteredString(gc,textdial[9],140)
- elseif box==2 then
- drawCenteredString(gc,textdial[10],75)
- gc:setFont("sansserif","b",10)
- drawCenteredString(gc,textdial[11],95)
- gc:setFont("sansserif","b",8)
- drawCenteredString(gc,textdial[12],110)
- drawCenteredString(gc,textdial[13],125)
- end
- elseif new==true then
- gc:setFont("sansserif","b",12)
- drawCenteredString(gc,textdial[14],80)
- gc:setFont("sansserif","b",10)
- drawString2(gc,textdial[15],125,110)
- drawString2(gc,textdial[16],125,130)
- elseif game>0 then
- gc:setFont("sansserif","b",12)
- if lang=="fr" then
- temp = textdial[17]
- temp2 = textdial[18]
- gc:drawString(temp.fr..game..temp2.fr,105,80)
- else
- temp = textdial[17]
- temp2 = textdial[18]
- gc:drawString(temp.en..game..temp2.en,105,80)
- end
- gc:setFont("sansserif","b",10)
- drawCenteredString(gc,textdial[19],140)
- gc:setColorRGB(unpack(colors[game]))
- gc:fillRect(150,95,15,15)
- gc:setColorRGB(0,0,0)
- gc:setPen("medium")
- gc:drawRect(150,95,15,15)
- end
- end
- function on.mouseDown(x,y)
- click()
- end
- function on.mouseMove(mx,my)
- x=math.ceil((mx-90)/15)+1
- y=math.ceil((my-35)/15)+1
- if x>10 then
- x=10
- elseif x<2 then
- x=2
- end
- if y>10 then
- y=10
- elseif y<2 then
- y=2
- end
- platform.window:invalidate()
- end
- function on.arrowLeft()
- left()
- end
- function on.arrowRight()
- right()
- end
- function on.arrowUp()
- up()
- end
- function on.arrowDown()
- down()
- end
- function on.charIn(char)
- if char=="8" then
- up()
- elseif char=="6" then
- right()
- elseif char=="4" then
- left()
- elseif (char=="2" or char=="5") and new==false then
- down()
- end
- if new==true and char=="1" then
- players=1
- new=false
- elseif new==true and char=="2" then
- players=2
- new=false
- end
- if char=="y" and exit==true then
- quit()
- elseif char=="y" and re==true then
- new=true
- reset()
- elseif char=="n" then
- exit=false
- re=false
- if game>0 then
- game=0
- new=true
- reset()
- end
- end
- platform.window:invalidate()
- end
- function left()
- if x>2 then
- x=x-1
- platform.window:invalidate()
- end
- end
- function right()
- if x<10 then
- x=x+1
- platform.window:invalidate()
- end
- end
- function up()
- if y>2 then
- y=y-1
- platform.window:invalidate()
- end
- end
- function down()
- if y<10 then
- y=y+1
- platform.window:invalidate()
- end
- end
- function on.escapeKey()
- ask("","Exit")
- end
- function on.enterKey()
- click()
- end
- function click()
- re,exit,box=false,false,0
- if new==false then
- if game>0 then
- game=0
- new=true
- reset()
- end
- if screen==1 then
- screen=2
- new=true
- reset()
- elseif screen==2 then
- if game>0 then
- new=true
- reset()
- end
- if turn[1]==1 then
- if board[y][x]==0 and math.abs(x-p[turn[2]][1])<2 and math.abs(y-p[turn[2]][2])<2 then
- board[p[turn[2]][2]][p[turn[2]][1]]=0
- p[turn[2]]={x,y}
- board[y][x]=turn[2]
- turn[1]=2
- end
- elseif turn[1]==2 then
- if board[y][x]==0 then
- board[y][x]=3
- turn[1]=1
- turn[2]=(((turn[2]^2)-1)/-3)+2
- x=p[turn[2]][1]
- y=p[turn[2]][2]
- checkDeath(p[1][1],p[1][2],p[2][1],p[2][2])
- end
- end
- end
- if turn[2]==2 and players==1 then
- ai()
- end
- end
- platform.window:invalidate()
- end
- function checkDeath(px1,py1,px2,py2)
- game=2
- for i=-1,1 do
- for ii=-1,1 do
- if board[py1+i][px1+ii]==0 then
- game=0
- end
- end
- end
- if game==0 then
- game=1
- for i=-1,1 do
- for ii=-1,1 do
- if board[py2+i][px2+ii]==0 then
- game=0
- end
- end
- end
- end
- end
- function quit()
- screen=1
- toolpalette.register({})
- platform.window:invalidate()
- end
- function changeTheme(parent,option)
- if option=="Classic" then
- colors=themes[1]
- elseif option=="Dark" then
- colors=themes[2]
- elseif option=="84" then
- colors=themes[3]
- end
- platform.window:invalidate()
- end
- function reset()
- board= {{3,3,3,3,3,3,3,3,3,3,3},
- {3,0,0,0,0,2,0,0,0,0,3},
- {3,0,0,0,0,0,0,0,0,0,3},
- {3,0,0,0,0,0,0,0,0,0,3},
- {3,0,0,0,0,0,0,0,0,0,3},
- {3,0,0,0,0,0,0,0,0,0,3},
- {3,0,0,0,0,0,0,0,0,0,3},
- {3,0,0,0,0,0,0,0,0,0,3},
- {3,0,0,0,0,0,0,0,0,0,3},
- {3,0,0,0,0,1,0,0,0,0,3},
- {3,3,3,3,3,3,3,3,3,3,3}}
- x=6
- y=10
- game=0
- exit,re,box=false,false,0
- p={{6,10},{6,2}}
- turn={1,1}
- toolpalette.register(MenuEn)
- platform.window:invalidate()
- end
- function ai()
- options={}
- for i=-1,1,1 do
- for ii=-1,1,1 do
- if board[p[2][2]+i][p[2][1]+ii]==0 and (ii~=0 or i~=0) then
- table.insert(options,{p[2][1]+ii,p[2][2]+i})
- end
- end
- end
- if table.getn(options)>0 then
- board[p[2][2]][p[2][1]]=0
- options=options[math.random(1,table.getn(options))]
- p[2]=options
- turn[1]=2
- board[p[2][2]][p[2][1]]=2
- else
- game=1
- return
- end
- options={}
- if p[1][1]==2 or p[1][1]==10 or p[1][2]==1 or p[1][2]==10 then
- range=-1
- else
- range=-2
- end
- for i=range,math.abs(range) do
- for ii=range,math.abs(range) do
- if board[p[1][2]+i][p[1][1]+ii]==0 then
- table.insert(options,{p[1][1]+ii,p[1][2]+i})
- end
- end
- end
- if table.getn(options)>0 then
- options=options[math.random(1,table.getn(options))]
- board[options[2]][options[1]]=3
- turn={1,1}
- end
- checkDeath(p[1][2],p[1][1],p[1][2],p[1][2])
- end
- function forfeit()
- re,exit,box=false,false,0
- game=(((turn[2]^2)-1)/-3)+2
- platform.window:invalidate()
- end
- function ask(parent,option)
- re,exit,box=false,false,0
- if option=="Exit" then
- exit=true
- elseif option=="Reset" then
- re=true
- elseif option=="How to Play" then
- box=1
- elseif option=="About" then
- box=2
- end
- platform.window:invalidate()
- end
- MenuEn={{"Game",
- {"Exit",ask},
- {"Reset",ask},
- {"Foreit",forfeit}},
- {"Theme",
- {"Classic",changeTheme},
- {"Dark",changeTheme},
- {"84",changeTheme}},
- {"Help",
- {"How to Play",ask},
- {"About",ask}}
- }
- MenuFr={{"Jeu",
- {"Quitter",ask},
- {"Restaurer",ask},
- {"Abandonner",forfeit}},
- {"Theme",
- {"Classic",changeTheme},
- {"Sombre",changeTheme},
- {"84",changeTheme}},
- {"Aide",
- {"Comment jouer",ask},
- {"A propos",ask}}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement