Advertisement
AdslHouba

Jeu tempo 1

Feb 8th, 2017
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.13 KB | None | 0 0
  1. os.loadAPI("ahb")
  2. config=ahb.config("jeu",{
  3.     {nom="s1",info="selector haut gauche",choices=false,typ="string"},
  4.     {nom="s2",info="selector haut centre",choices=false,typ="string"},
  5.     {nom="s3",info="selector haut droite",choices=false,typ="string"},
  6.     {nom="s4",info="selector centre gauche",choices=false,typ="string"},
  7.     {nom="s5",info="selector centre centre",choices=false,typ="string"},
  8.     {nom="s6",info="selector centre droite",choices=false,typ="string"},
  9.     {nom="s7",info="selector bas gauche",choices=false,typ="string"},
  10.     {nom="s8",info="selector bas centre",choices=false,typ="string"},
  11.     {nom="s9",info="selector bas droite",choices=false,typ="string"},
  12. })
  13.  
  14. local items={
  15.     {id="minecraft:wool",dmg=3},
  16.     {id="minecraft:wool",dmg=8}
  17. }
  18. local dmgAleatoire=true
  19.  
  20. function addP(id)
  21.     if not(peripheral.isPresent(id)) then
  22.         print(id..' non co')
  23.     end
  24.     return {
  25.         pp=peripheral.wrap(id),
  26.         id=id
  27.     }
  28. end
  29. function addSelector(id)
  30.     return addP("openperipheral_selector_"..id)
  31. end
  32.  
  33. local selectors={
  34.     {
  35.         addSelector(config.s1),
  36.         addSelector(config.s2),
  37.         addSelector(config.s3)
  38.     },
  39.     {
  40.         addSelector(config.s4),
  41.         addSelector(config.s5),
  42.         addSelector(config.s6)
  43.     },
  44.     {
  45.         addSelector(config.s7),
  46.         addSelector(config.s8),
  47.         addSelector(config.s9)
  48.     }
  49. }
  50. function generationMaps()
  51.     local map={}
  52.     local y=1
  53.     local x=1
  54.     local slot=1
  55.     for ys=1,#selectors do
  56.         for yr=1,3 do
  57.             map[((ys-1)*3)+yr]={}
  58.         end
  59.         for xs=1,#selectors[ys] do
  60.             selectors[ys][xs].retour={}
  61.             slot=1
  62.             for yr=1,3 do
  63.                 for xr=1,3 do
  64.                     x=((xs-1)*3)+xr
  65.                     y=((ys-1)*3)+yr
  66.                     selectors[ys][xs].retour[slot]={x=x,y=y}
  67.                     map[y][x]={
  68.                         ys=ys,
  69.                         xs=xs,
  70.                         slot=slot,
  71.                         etat=1
  72.                     }
  73.                     slot=slot+1
  74.                 end
  75.             end
  76.         end
  77.     end
  78.     return map
  79. end
  80. local map=generationMaps()
  81.  
  82. function actu(x,y)
  83.     selectors[map[y][x].ys][map[y][x].xs].pp.setSlot(map[y][x].slot,items[map[y][x].etat])
  84. end
  85. function actuAffichageGlobal()
  86.     for y=1,#map do
  87.         for x=1,#map[y] do
  88.             actu(x,y)
  89.         end
  90.     end
  91. end
  92. function changeEtat(x,y,aplique)
  93.     if map[y][x].etat==1 then
  94.         map[y][x].etat=2
  95.     else
  96.         map[y][x].etat=1
  97.     end
  98.     print(map[y][x].etat)
  99.     if aplique then
  100.         actu(x,y)
  101.     end
  102. end
  103. function modif(x,y,aplique)
  104.     changeEtat(x,y,aplique)
  105.     if x-1~=0 then
  106.         changeEtat(x-1,y,aplique)
  107.     end
  108.     if y-1~=0 then
  109.         changeEtat(x,y-1,aplique)
  110.     end
  111.     if y~=#map then
  112.         changeEtat(x,y+1,aplique)
  113.     end
  114.     if x~=#map[y] then
  115.         changeEtat(x+1,y,aplique)
  116.     end
  117. end
  118. function trouverSelector(side)
  119.     for ys=1,#selectors do
  120.         for xs=1,#selectors[ys] do
  121.             if side==selectors[ys][xs].id then
  122.                 return selectors[ys][xs]
  123.             end
  124.         end
  125.     end
  126.     return false
  127. end
  128.  
  129. if dmgAleatoire then
  130.     items[1].dmg=math.random(0,15)
  131.     items[2].dmg=math.random(0,15)
  132. end
  133. function generateurDifficulter()
  134.     for i=1,50 do
  135.         modif(math.random(1,#map[1]),math.random(1,#map),false)
  136.     end
  137. end
  138. generateurDifficulter()
  139. actuAffichageGlobal()
  140. print('Pret')
  141. while true do
  142.     event, slot, side=os.pullEvent("slot_click")
  143.     print("Event "..side)
  144.     selector=trouverSelector(side)
  145.     if not(selector==false) then
  146.         modif(selector.retour[slot].x,selector.retour[slot].y,true)
  147.     end
  148. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement