Advertisement
AdslHouba

Machine à sous (Computercraft)

Jun 16th, 2016
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.21 KB | None | 0 0
  1. chest=peripheral.wrap("back") -- Chest de laine
  2. chestInsert=peripheral.wrap("front") -- Chest insert
  3. chestInsertSortie="WEST"
  4. chestCoffre=peripheral.wrap("right")
  5. chestCoffreSortie="UP"
  6. chatBox=peripheral.find("chatBox")
  7.  
  8. noteBlock=peripheral.find("noteBlock")
  9. ecran=peripheral.find("monitor")
  10. arriveRedstone="bottom"
  11. credit=0
  12.  
  13. file=fs.open("gagnotte","r")
  14. gagnotte=tonumber(textutils.unserialize(file.readAll()))
  15. file.close()
  16.  
  17. statutActuelLanc=redstone.testBundledInput(arriveRedstone,colors.brown)
  18.  
  19. nMax=8
  20.  
  21. cote={"WEST","SOUTH","EAST"}
  22. anim={
  23.     {0.05,0.05,0.05},
  24.     {0.05,0.05,0.05},
  25.     {0.1,0.05,0.05},
  26.     {0.2,0.05,0.05},
  27.     {0  ,0.2,0.1},
  28.     {0  ,0.3,0.1},
  29.     {0  ,0  ,0.2}
  30. }
  31. couleur={14,1,4,5,13,11,9,10}
  32. -- "north", "south"
  33.  
  34.  
  35.  
  36. redstone.setOutput("top", false)
  37. function envoi(choix,cote)
  38.     chest.condenseItems()
  39.     stacks=chest.getAllStacks()
  40.     table.foreach(stacks,function(i,data)
  41.         info=data.basic()
  42.         if info.dmg==couleur[choix+1] then
  43.             chest.pushItem(cote,i,1)
  44.             redstone.setOutput("top", true)
  45.             os.sleep(0.08)
  46.             redstone.setOutput("top", false)
  47.             return
  48.         end
  49.     end)
  50. end
  51. function actuEcran()
  52.     ecran.setTextColor(colors.white)
  53.     ecran.setBackgroundColor(colors.yellow)
  54.     ecran.clear()
  55.     ecran.setTextScale(2)
  56.     affichage=tostring(gagnotte);
  57.  
  58.     ecran.setCursorPos(1+math.floor((14-string.len(affichage))/2),1)
  59.     ecran.write(affichage)
  60.  
  61.     ecran.setCursorPos(3,2)
  62.     ecran.write(tostring(math.floor(credit/2))..' credits')
  63. end
  64. function ecranCredit2(t)
  65.     if t then
  66.         ecran.setTextColor(colors.white)
  67.         ecran.setBackgroundColor(colors.yellow)
  68.     else
  69.         ecran.setTextColor(colors.yellow)
  70.         ecran.setBackgroundColor(colors.white)
  71.     end
  72.     ecran.clear()
  73.     ecran.setTextScale(2)
  74.     ecran.setCursorPos(6,1)
  75.     ecran.write("GAIN")
  76.     ecran.setCursorPos(3,2)
  77.     ecran.write("+2 credits")
  78. end
  79. function ecranJackpot(t)
  80.     if t then
  81.         ecran.setTextColor(colors.white)
  82.         ecran.setBackgroundColor(colors.orange)
  83.     else
  84.         ecran.setTextColor(colors.white)
  85.         ecran.setBackgroundColor(colors.yellow)
  86.     end
  87.     ecran.clear()
  88.     ecran.setTextScale(2)
  89.     ecran.setCursorPos(3,1)
  90.     ecran.write("JACKPOT")
  91.     affichage=tostring(gagnotte);
  92.     ecran.setCursorPos(1+math.floor((14-string.len(affichage))/2),2)
  93.     ecran.write(affichage)
  94. end
  95.  
  96. actuEcran()
  97. jeuActif=false
  98. function lancement()           
  99.     tirage={math.random(nMax-1),math.random(nMax-1),math.random(nMax-1)}
  100.     --tirage={4,2,1}
  101.  
  102.     table.foreach(anim,function(u,ligne)
  103.         table.foreach(ligne,function(o,dure)
  104.             if dure~=0 then
  105.                 os.sleep(dure)
  106.                 tirage[o]=tirage[o]+1
  107.                 if tirage[o]==nMax then tirage[o]=0 end
  108.                 envoi(tirage[o],cote[o])           
  109.             end
  110.         end)
  111.     end)
  112.     if tirage[1]==tirage[2] and tirage[2]==tirage[3] then
  113.         if tirage[1]==0 then
  114.             ecranJackpot(true)
  115.             noteBlock.playNote(0,0)
  116.             os.sleep(0.5)
  117.            
  118.             gagnotteD=gagnotte
  119.             chestCoffre.condenseItems()
  120.             stacks=chestCoffre.getAllStacks()
  121.             table.foreach(stacks,function(i,data)
  122.                 if gagnotteD>0 then
  123.                     info=data.basic()
  124.                     if gagnotteD>info.qty then
  125.                         chestCoffre.pushItem(chestCoffreSortie,i,info.qty)
  126.                         gagnotteD=gagnotteD-info.qty
  127.                     else
  128.                         chestCoffre.pushItem(chestCoffreSortie,i,gagnotteD)
  129.                         gagnotteD=0
  130.                     end
  131.                 end
  132.             end)
  133.             for i = 1,40 do
  134.                 ecranJackpot(false)
  135.                 noteBlock.playNote(0,3)
  136.                 os.sleep(0.15)
  137.                 ecranJackpot(false)
  138.                 noteBlock.playNote(0,0)
  139.                 ecranJackpot(true)
  140.                 os.sleep(0.15)
  141.             end
  142.             file=fs.open("gagnotteGain","w")
  143.             file.write(tostring(gagnotte))
  144.             file.close()
  145.             gagnotte=100
  146.             file=fs.open("gagnotte","w")
  147.             file.write(tostring(100))
  148.             file.close()
  149.         else
  150.             ecranCredit2(true)
  151.             noteBlock.playNote(0,0)
  152.             os.sleep(0.5)
  153.             ecranCredit2(false)
  154.             noteBlock.playNote(0,1)
  155.             for i = 1,6 do
  156.                 os.sleep(0.1)
  157.                 ecranCredit2(true)
  158.                 os.sleep(0.1)
  159.                 ecranCredit2(false)
  160.             end
  161.             credit=credit+4
  162.         end
  163.     else
  164.         os.sleep(0.5)
  165.         noteBlock.playNote(4,4)
  166.         os.sleep(0.3)
  167.         noteBlock.playNote(4,2)
  168.     end
  169.     actuEcran()
  170.     jeuActif=false
  171. end
  172. function verifDollar()
  173.     if redstone.testBundledInput(arriveRedstone,colors.green) then
  174.         print("verif dollar")
  175.         chestInsert.condenseItems()
  176.         stacks=chestInsert.getAllStacks()
  177.         table.foreach(stacks,function(i,data)
  178.             info=data.basic()          
  179.             chestInsert.pushItem(chestInsertSortie,i,info.qty)
  180.             credit=credit+info.qty
  181.             noteBlock.playNote(0,2)
  182.         end)
  183.         actuEcran()
  184.     end
  185. end
  186. function verif()
  187.     while true do
  188.         local event = os.pullEvent("redstone")
  189.         verifDollar()
  190.     end
  191. end
  192. while true do
  193.     local event = os.pullEvent("redstone")
  194.     verifDollar()
  195.     if redstone.testBundledInput(arriveRedstone,colors.brown)~=statutActuelLanc then
  196.         statutActuelLanc=redstone.testBundledInput(arriveRedstone,colors.brown)
  197.         if jeuActif==false then
  198.             if credit>=2 then
  199.                 credit=credit-2
  200.                 gagnotte=gagnotte+1
  201.                 file=fs.open("gagnotte","w")
  202.                 file.write(tostring(gagnotte))
  203.                 file.close()
  204.                 actuEcran()
  205.                 jeuActif=true
  206.                 parallel.waitForAny(verif,lancement)
  207.             else
  208.                 noteBlock.playNote(4,2)
  209.                 ecran.setTextColor(colors.white)
  210.                 ecran.setBackgroundColor(colors.red)   
  211.                 ecran.clear()
  212.                 ecran.setTextScale(2)
  213.                 ecran.setCursorPos(1,1)
  214.                 ecran.write("PAS DE CREDIT")
  215.                 ecran.setCursorPos(1,2)
  216.                 ecran.write("insert 2 coin")
  217.             end
  218.         end
  219.     end
  220. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement