Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.17 KB | None | 0 0
  1. function scene:create( event )
  2.   math.randomseed(os.time())
  3.     local sceneGroup = self.view
  4.   generatePassword(2)
  5.   local buttonlist = {}
  6.   local code = {}
  7.   local drawCode = display.newText({text = "",x = 50,y = 50})
  8.   local tryCount = 0
  9.   local drawTryCount = display.newText({text = "Nombre d'essai : 0",x = display.contentHeight/2,y = display.contentWidth /5,align = "right" })
  10.   local money = 0
  11.   local drawMoney = display.newText({text = "money : 0",x = display.contentHeight/2,y = display.contentWidth /4 ,align = "right"})
  12.   local function onButton(event)
  13.       if event.target.id == "10" then
  14.         local str = ""
  15.           for i = 1,#code do
  16.               str = str..code[i]
  17.           end
  18.           print("try "..str)
  19.           if #str ~= 0 then
  20.               if str == password then
  21.                 print("correct")
  22.               else
  23.                  print("false")
  24.                 tryCount = tryCount +1
  25.                 drawTryCount.text = "Nombre d'essai : "..tryCount
  26.               end
  27.           end
  28.           code = {}
  29.           drawCode.text = ""
  30.       elseif event.target.id == "11" then
  31.           code = {}
  32.           drawCode.text = ""
  33.       else
  34.        
  35.        
  36.         table.insert(code,event.target.id)
  37.         local str = ""
  38.         for i = 1,#code do
  39.             str = str..code[i]
  40.         end
  41.         drawCode.text = str
  42.       end
  43.   end
  44.   local function buyStuff()
  45.       composer.gotoScene("shop")
  46.   end
  47.   print("creategamescene")
  48.    table.insert(buttonlist, widget.newButton({
  49.       label = "1",
  50.       id = "1",
  51.       x = display.contentWidth/10,
  52.       y = display.contentHeight/5,
  53.       shape = "circle",
  54.       radius = 15,
  55.       fillColor = { default={ 1, 1, 1, 1 }, over={ 0, 1, 0, 1 } },
  56.       onRelease = onButton
  57.     }))
  58.     table.insert(buttonlist, widget.newButton({
  59.       label = "2",
  60.       id = "2",
  61.       x = display.contentWidth/10+40,
  62.       y = display.contentHeight/5,
  63.       shape = "circle",
  64.       radius = 15,
  65.       fillColor = { default={ 1, 1, 1, 1 }, over={ 0, 1, 0, 1 } },
  66.       onRelease = onButton
  67.     }))
  68.     table.insert(buttonlist, widget.newButton({
  69.       label = "3",
  70.       id = "3",
  71.       x = display.contentWidth/10+80,
  72.       y = display.contentHeight/5,
  73.       shape = "circle",
  74.       radius = 15,
  75.       fillColor = { default={ 1, 1, 1, 1 }, over={ 0, 1, 0, 1 } },
  76.       onRelease = onButton
  77.     }))
  78.  
  79.   table.insert(buttonlist, widget.newButton({
  80.       label = "4",
  81.       id = "4",
  82.       x = display.contentWidth/10,
  83.       y = display.contentHeight/5 +40,
  84.       shape = "circle",
  85.       radius = 15,
  86.       fillColor = { default={ 1, 1, 1, 1 }, over={ 0, 1, 0, 1 } },
  87.       onRelease = onButton
  88.     }))
  89.   table.insert(buttonlist, widget.newButton({
  90.         label = "5",
  91.         id = "5",
  92.         x = display.contentWidth/10+40,
  93.         y = display.contentHeight/5 +40,
  94.         shape = "circle",
  95.         radius = 15,
  96.         fillColor = { default={ 1, 1, 1, 1 }, over={ 0, 1, 0, 1 } },
  97.         onRelease = onButton
  98.       }))
  99.    table.insert(buttonlist, widget.newButton({
  100.         label = "6",
  101.         id = "6",
  102.         x = display.contentWidth/10+80,
  103.         y = display.contentHeight/5 +40,
  104.         shape = "circle",
  105.         radius = 15,
  106.         fillColor = { default={ 1, 1, 1, 1 }, over={ 0, 1, 0, 1 } },
  107.         onRelease = onButton
  108.       }))
  109.  table.insert(buttonlist, widget.newButton({
  110.       label = "7",
  111.       id = "7",
  112.       x = display.contentWidth/10,
  113.       y = display.contentHeight/5 +80,
  114.       shape = "circle",
  115.       radius = 15,
  116.       fillColor = { default={ 1, 1, 1, 1 }, over={ 0, 1, 0, 1 } },
  117.       onRelease = onButton
  118.     }))
  119.  table.insert(buttonlist, widget.newButton({
  120.       label = "8",
  121.       id = "8",
  122.       x = display.contentWidth/10+40,
  123.       y = display.contentHeight/5 +80,
  124.       shape = "circle",
  125.       radius = 15,
  126.       fillColor = { default={ 1, 1, 1, 1 }, over={ 0, 1, 0, 1 } },
  127.       onRelease = onButton
  128.     }))
  129.  table.insert(buttonlist, widget.newButton({
  130.       label = "9",
  131.       id = "9",
  132.       x = display.contentWidth/10+80,
  133.       y = display.contentHeight/5 +80,
  134.       shape = "circle",
  135.       radius = 15,
  136.       fillColor = { default={ 1, 1, 1, 1 }, over={ 0, 1, 0, 1 } },
  137.       onRelease = onButton
  138.     }))
  139.  table.insert(buttonlist, widget.newButton({
  140.       label = "0",
  141.       id = "0",
  142.       x = display.contentWidth/10+40,
  143.       y = display.contentHeight/5 +120,
  144.       shape = "circle",
  145.       radius = 15,
  146.       fillColor = { default={ 1, 1, 1, 1 }, over={ 0, 1, 0, 1 } },
  147.       onRelease = onButton
  148.     }))
  149.  table.insert(buttonlist, widget.newButton({
  150.       label = "ok",
  151.       id = "10",
  152.       x = display.contentWidth/10+80,
  153.       y = display.contentHeight/5 +120,
  154.       shape = "circle",
  155.       radius = 15,
  156.       fillColor = { default={ 1, 1, 1, 1 }, over={ 0, 1, 0, 1 } },
  157.       onRelease = onButton
  158.     }))
  159.  table.insert(buttonlist, widget.newButton({
  160.       label = "clear",
  161.       id = "11",
  162.       x = display.contentWidth/10,
  163.       y = display.contentHeight/5 +120,
  164.       shape = "circle",
  165.       radius = 15,
  166.       fillColor = { default={ 1, 1, 1, 1 }, over={ 0, 1, 0, 1 } },
  167.       onRelease = onButton
  168.     }))
  169.  
  170. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement