Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("ahb")
- config=ahb.config("jeu",{
- {nom="s1",info="selector haut gauche",choices=false,typ="string"},
- {nom="s2",info="selector haut centre",choices=false,typ="string"},
- {nom="s3",info="selector haut droite",choices=false,typ="string"},
- {nom="s4",info="selector centre gauche",choices=false,typ="string"},
- {nom="s5",info="selector centre centre",choices=false,typ="string"},
- {nom="s6",info="selector centre droite",choices=false,typ="string"},
- {nom="s7",info="selector bas gauche",choices=false,typ="string"},
- {nom="s8",info="selector bas centre",choices=false,typ="string"},
- {nom="s9",info="selector bas droite",choices=false,typ="string"},
- })
- local items={
- {id="minecraft:wool",dmg=3},
- {id="minecraft:wool",dmg=8}
- }
- local dmgAleatoire=true
- function addP(id)
- if not(peripheral.isPresent(id)) then
- print(id..' non co')
- end
- return {
- pp=peripheral.wrap(id),
- id=id
- }
- end
- function addSelector(id)
- return addP("openperipheral_selector_"..id)
- end
- local selectors={
- {
- addSelector(config.s1),
- addSelector(config.s2),
- addSelector(config.s3)
- },
- {
- addSelector(config.s4),
- addSelector(config.s5),
- addSelector(config.s6)
- },
- {
- addSelector(config.s7),
- addSelector(config.s8),
- addSelector(config.s9)
- }
- }
- function generationMaps()
- local map={}
- local y=1
- local x=1
- local slot=1
- for ys=1,#selectors do
- for yr=1,3 do
- map[((ys-1)*3)+yr]={}
- end
- for xs=1,#selectors[ys] do
- selectors[ys][xs].retour={}
- slot=1
- for yr=1,3 do
- for xr=1,3 do
- x=((xs-1)*3)+xr
- y=((ys-1)*3)+yr
- selectors[ys][xs].retour[slot]={x=x,y=y}
- map[y][x]={
- ys=ys,
- xs=xs,
- slot=slot,
- etat=1
- }
- slot=slot+1
- end
- end
- end
- end
- return map
- end
- local map=generationMaps()
- function actu(x,y)
- selectors[map[y][x].ys][map[y][x].xs].pp.setSlot(map[y][x].slot,items[map[y][x].etat])
- end
- function actuAffichageGlobal()
- for y=1,#map do
- for x=1,#map[y] do
- actu(x,y)
- end
- end
- end
- function changeEtat(x,y,aplique)
- if map[y][x].etat==1 then
- map[y][x].etat=2
- else
- map[y][x].etat=1
- end
- print(map[y][x].etat)
- if aplique then
- actu(x,y)
- end
- end
- function modif(x,y,aplique)
- changeEtat(x,y,aplique)
- if x-1~=0 then
- changeEtat(x-1,y,aplique)
- end
- if y-1~=0 then
- changeEtat(x,y-1,aplique)
- end
- if y~=#map then
- changeEtat(x,y+1,aplique)
- end
- if x~=#map[y] then
- changeEtat(x+1,y,aplique)
- end
- end
- function trouverSelector(side)
- for ys=1,#selectors do
- for xs=1,#selectors[ys] do
- if side==selectors[ys][xs].id then
- return selectors[ys][xs]
- end
- end
- end
- return false
- end
- if dmgAleatoire then
- items[1].dmg=math.random(0,15)
- items[2].dmg=math.random(0,15)
- end
- function generateurDifficulter()
- for i=1,50 do
- modif(math.random(1,#map[1]),math.random(1,#map),false)
- end
- end
- generateurDifficulter()
- actuAffichageGlobal()
- print('Pret')
- while true do
- event, slot, side=os.pullEvent("slot_click")
- print("Event "..side)
- selector=trouverSelector(side)
- if not(selector==false) then
- modif(selector.retour[slot].x,selector.retour[slot].y,true)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement