Advertisement
AdslHouba

Jeu1 : jeu

May 30th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.42 KB | None | 0 0
  1. sensor=peripheral.find("sensor")
  2. noteBlock=peripheral.find("noteBlock")
  3. modem=peripheral.find("modem")
  4. chatBox=peripheral.find("chatBox")
  5. coteRedstonne="back"
  6.  
  7. payant=true
  8. modem.open(1)
  9.  
  10. file=fs.open("scoreboard","r")
  11. scoreboard=textutils.unserialize(file.readAll())
  12. file.close()
  13.  
  14. redstone.setOutput(coteRedstonne, false)
  15.  
  16. config={
  17.     Ypoint=-7,
  18.     note={
  19.         ZM=1,
  20.         ZP=3,
  21.         XM=5,
  22.         XP=7
  23.     }
  24. }
  25.  
  26. score={
  27.     ZM={joueur="",pt=0,cote='ZM'},
  28.     ZP={joueur="",pt=0,cote='ZP'},
  29.     XM={joueur="",pt=0,cote='XM'},
  30.     XP={joueur="",pt=0,cote='XP'}
  31. }
  32. enLigne=true
  33. joueursNb=0
  34. poulePret={}
  35. temps=60
  36.  
  37. function addJoueur(coteA,nomA)
  38.     if score[coteA].joueur=="" then
  39.         joueursNb=joueursNb+1
  40.     end
  41.     score[coteA].joueur=nomA   
  42.     listeJoueur=""
  43.     table.foreach(score,function(cote,data)
  44.         if data.joueur~="" then
  45.             if listeJoueur~="" then
  46.                 listeJoueur=listeJoueur..", "
  47.             end
  48.             listeJoueur=listeJoueur..data.joueur
  49.         end
  50.     end)
  51.     actuEcran("")
  52. end
  53. function reset()
  54.     score={
  55.         ZM={joueur="",pt=0,cote='ZM'},
  56.         ZP={joueur="",pt=0,cote='ZP'},
  57.         XM={joueur="",pt=0,cote='XM'},
  58.         XP={joueur="",pt=0,cote='XP'}
  59.     }
  60.     joueursNb=0
  61.     actuEcran("scoreboard")
  62. end
  63. function actuEcran(msg)
  64.     scoreTrie={}
  65.     if msg=="1" or msg=="2" or msg=="3" or msg=="GO" then
  66.         data=textutils.serialize({msg=msg})
  67.     elseif msg=="scoreboard" then
  68.         table.foreach(scoreboard,function(nom,pt)
  69.             table.insert(scoreTrie,pt)
  70.         end)
  71.         table.sort(scoreTrie, function(a,b) return a>b end)  
  72.         scoreTable={}
  73.         derPt=-1
  74.         table.foreach(scoreTrie,function(a,pts)
  75.             if derPt~=pts then
  76.                 derPt=pts
  77.                 table.foreach(scoreboard,function(nom,pt)
  78.                     if pt==pts then
  79.                         table.insert(scoreTable,{nom=nom,pt=pt})
  80.                     end
  81.                 end)
  82.             end
  83.         end)
  84.         data=textutils.serialize({score=scoreTable,msg=msg,temps=""})
  85.     else
  86.         table.foreach(score,function(cote,data)
  87.             table.insert(scoreTrie,data.pt)
  88.         end)
  89.         table.sort(scoreTrie, function(a,b) return a>b end)  
  90.         scoreTable={}
  91.         derPt=-1
  92.         table.foreach(scoreTrie,function(a,pt)
  93.             if derPt~=pt then
  94.                 derPt=pt
  95.                 table.foreach(score,function(cote,data)
  96.                     if data.pt==pt then
  97.                         table.insert(scoreTable,data)
  98.                     end
  99.                 end)
  100.             end
  101.         end)
  102.         data=textutils.serialize({score=scoreTable,msg=msg,temps=temps})
  103.     end
  104.     modem.transmit(2,1,data)
  105. end
  106. function chatBoxFc()
  107.     while true do
  108.         command, player, arg = os.pullEvent("command")
  109.         if arg[1]=='HBreset' then
  110.             reset()
  111.             return
  112.         end
  113.     end
  114. end
  115. function addPoind(coteA)
  116.     score[coteA].pt=score[coteA].pt+1
  117.     noteBlock.playNote(0,config.note[coteA])
  118.     actuEcran("")
  119. end
  120.  
  121.  
  122. function timeFC()
  123.     temps=60
  124.     while temps~=0 do
  125.         print(temps)
  126.         os.sleep(1)
  127.         temps=temps-1
  128.         actuEcran("")      
  129.     end
  130.     enLigne=false
  131.     os.sleep(20)
  132. end
  133. function jeuFc()
  134.     print("Lancer le jeu !")   
  135.     enLigne=true
  136.     while enLigne do
  137.         liste=sensor.getTargets()
  138.         table.foreach(liste,function(id,data)
  139.             if data.IsPlayer==false then
  140.                 if data.Position.Y<config.Ypoint then
  141.                     if poulePret[id] then
  142.                         poulePret[id]=false                    
  143.                         if data.Position.Z<-3 then
  144.                             addPoind("ZM")                 
  145.                         elseif data.Position.Z>3 then
  146.                             addPoind("ZP")
  147.                         elseif data.Position.X<-3 then
  148.                             addPoind("XM")
  149.                         elseif data.Position.X>3 then
  150.                             addPoind("XP")
  151.                         end
  152.                     end
  153.                 else
  154.                     poulePret[id]=true
  155.                 end
  156.             end
  157.         end)
  158.         os.sleep(0.5)
  159.     end
  160.     actuEcran("gagnant")
  161.     table.foreach(score,function(cote,data)
  162.         if data.joueur~="" then
  163.             if scoreboard[data.joueur]==nil then
  164.                 scoreboard[data.joueur]=data.pt
  165.             elseif scoreboard[data.joueur]<data.pt then
  166.                 scoreboard[data.joueur]=data.pt
  167.             end
  168.         end
  169.     end)
  170.     file=fs.open("scoreboard","w")
  171.     file.write(textutils.serialize(scoreboard))
  172.     file.close()
  173.    
  174.    
  175.    
  176.     print("FIN")
  177.     score={
  178.         ZM={joueur="",pt=0,cote='ZM'},
  179.         ZP={joueur="",pt=0,cote='ZP'},
  180.         XM={joueur="",pt=0,cote='XM'},
  181.         XP={joueur="",pt=0,cote='XP'}
  182.     }
  183.     joueursNb=0
  184.     return
  185. end
  186. os.sleep(20)
  187. actuEcran("scoreboard")
  188. while true do
  189.     command, player, arg = os.pullEvent("command")
  190.     print(player.." "..arg[1])
  191.     if arg[1]=='HBjoin' then
  192.         liste=sensor.getTargets()
  193.         table.foreach(liste,function(id,data)
  194.             if data.IsPlayer==true and id==player then
  195.                 if data.Position.Z<-4.5 then
  196.                     addJoueur("ZM",id)                 
  197.                 elseif data.Position.Z>4.5 then
  198.                     addJoueur("ZP",id)
  199.                 elseif data.Position.X<-4.5 then
  200.                     addJoueur("XM",id)
  201.                 elseif data.Position.X>4.5 then
  202.                     addJoueur("XP",id)
  203.                 else
  204.                     chatBox.tell(player,"Vous devez etre sur un escalier")
  205.                 end
  206.             end
  207.         end)
  208.     elseif arg[1]=='HBquit' then
  209.         table.foreach(score,function(cote,data)
  210.             if data.joueur==player then
  211.                 score[cote].joueur=""
  212.                 joueursNb=joueursNb-1
  213.             end
  214.         end)
  215.         actuEcran("")
  216.     elseif arg[1]=='HBreset' then
  217.         reset()
  218.     elseif arg[1]=='HBgo' then
  219.         if joueursNb==0 then
  220.             chatBox.tell(player,"Pas de joueur \\HBjoin quand vous etes en place")
  221.         else
  222.             pret=true
  223.             if payant then
  224.                 print("Demande verif")
  225.                 modem.transmit(3,1,"verif")
  226.                 reponse=0
  227.                 retour={}
  228.                 prob=""
  229.                 while reponse~=4 do
  230.                     local event, modemSide, senderChannel,
  231.                         replyChannel, message, senderDistance = os.pullEvent("modem_message")
  232.                     datas=textutils.unserialize(message)
  233.                     print("reponse "..tostring(reponse).. " : "..datas.cote.." "..tostring(datas.argent))
  234.                     if score[datas.cote].joueur~="" then
  235.                         if datas.argent==false then
  236.                             if prob~="" then
  237.                                 prob=prob..", "
  238.                             end
  239.                             prob=prob..score[datas.cote].joueur
  240.                         end
  241.                     end
  242.                    
  243.                     reponse=reponse+1
  244.                 end
  245.                 if prob=="" then
  246.                     modem.transmit(3,1,"payer")
  247.                     pret=true
  248.                 else
  249.                     chatBox.tell(player,"Le(s) joueur(s) suivant non pas paye : "..prob)
  250.                     pret=false
  251.                 end
  252.             end
  253.             if pret then
  254.                 print("Prepa")
  255.                 redstone.setOutput(coteRedstonne, true)
  256.                 actuEcran("3")
  257.                 noteBlock.playNote(4,1) --3
  258.                 os.sleep(1)
  259.                 actuEcran("2")
  260.                 noteBlock.playNote(4,3) --2
  261.                 os.sleep(1)
  262.                 actuEcran("1")
  263.                 noteBlock.playNote(4,5) --1
  264.                 os.sleep(1)        
  265.                
  266.                 noteBlock.playNote(4,7)
  267.                 os.sleep(0.2)
  268.                 noteBlock.playNote(4,7)
  269.                 os.sleep(0.2)
  270.                 noteBlock.playNote(4,7)    
  271.                 actuEcran("GO")    
  272.                 print("Lancer le jeu")
  273.                 parallel.waitForAny(chatBoxFc,jeuFc,timeFC)
  274.                 print("Fin du jeu")
  275.                 noteBlock.playNote(4,1)
  276.                 os.sleep(0.2)
  277.                 noteBlock.playNote(4,1)
  278.                 os.sleep(0.2)
  279.                 noteBlock.playNote(4,1)
  280.                 redstone.setOutput(coteRedstonne, false)
  281.             end
  282.         end
  283.     end
  284. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement