Advertisement
Hendrix000007

Millionaire type of game

Apr 6th, 2013
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.44 KB | None | 0 0
  1. ------------------------------------
  2. -- lookup.lua
  3. --[[screenshot here:
  4. http://snag.gy/GxyLY.jpg
  5. --]]
  6. ------------------------------------
  7. _M = {}
  8.  
  9. _M.taken = {}
  10.  
  11. _M.myBase = {
  12. --------------------------
  13. [1] = { question = "What is my name ?",
  14.         alt1 = "Hendrix",
  15.         alt2 = "Carlos",
  16.         alt3 = "Jesus",
  17.         alt4 = "BerhanK",
  18.         answer = "Hendrix"
  19. },
  20. [2] = { question = "Who is the king ?",
  21.         alt1 = "Hendrix",
  22.         alt2 = "Baktus",
  23.         alt3 = "BerhanK",
  24.         alt4 = "Carlos",
  25.         answer = alt1
  26. },
  27. }
  28.  
  29. return _M
  30.  
  31.  
  32. -------------------------------------
  33. --main.lua
  34. -------------------------------------
  35.  
  36. display.setStatusBar(display.HiddenStatusBar)
  37.  
  38. local lookup = require "lookup"
  39.  
  40. --VARIABLE DECLARATIONS------------
  41. local _W = display.contentWidth * 0.5
  42. local _H = display.contentHeight * 0.5
  43.  
  44. --[Graphics]
  45. local bg
  46. --[Score TextField]
  47. local score = display.newText("0", 2, 0, "SuperMarioGalaxy", 14)
  48. score:setTextColor(255, 206, 0)
  49.  
  50. --[Title screen]
  51. local titleBg
  52.     titleBg           = display.newImageRect ( "bg.jpg", 320, 480 )
  53.     titleBg:setReferencePoint(display.CenterReferencePoint)
  54.     titleBg.x = _W
  55.     titleBg.y = _H
  56.    
  57. local R, answerBeholder, logo, quizzLogo, playButton, credButton, titleView
  58.  
  59. --[Credit View]
  60. local credView, lastY, score
  61.  
  62. --[Game View]
  63. local gameView, question, aText, bText, cText, dText
  64.  
  65.  
  66.  
  67.  
  68. --[Sounds]
  69. --local bell = audio.loadSound ( "bell.mp3" )
  70. --local buzz = audio.loadSound ( "buzz.mp3" )
  71.  
  72.  
  73.  
  74. --DECLARE FUNCTIONS------------------
  75. local Main = {}
  76. local startButtonListeners = {}
  77. local showCredits = {}
  78. local hideCredits = {}
  79. local showGameView = {}
  80. local gameListeners = {}
  81. local update = {}
  82. local gameFunction = {}
  83.  
  84. -- CONSTRUCTOR OF MAIN FUNCTION ------
  85. function Main()
  86.     logo          = display.newImageRect ( "logo.png", 326, 128 )
  87.     logo:setReferencePoint(display.TopCenterReferencePoint)
  88.     logo.x = _W
  89.     logo.y = 0
  90.     quizzLogo    = display.newImageRect ( "quizzLogo.png", 320, 140, true )
  91.     quizzLogo:setReferencePoint(display.TopCenterReferencePoint)
  92.     quizzLogo.x = _W
  93.     quizzLogo.y = logo.height
  94.     playButton  = display.newImageRect ( "playButton.png", 204, 60, true )
  95.     playButton:setReferencePoint(display.TopCenterReferencePoint)
  96.     playButton.x = _W
  97.     playButton.y = display.contentHeight - ( playButton.height*2) -60
  98.     credButton  = display.newImageRect ( "scoreButton.png", 204, 60, true )
  99.     credButton:setReferencePoint(display.TopCenterReferencePoint)
  100.     credButton.x = _W
  101.     credButton.y = display.contentHeight - credButton.height - 50
  102.     titleView    = display.newGroup (logo, quizzLogo, playButton, credButton)
  103.     titleView.x = _W
  104.     titleView.y = 70
  105.     startButtonListeners( "add" )
  106. end
  107.  
  108. --CLASSES (OTHER FUNCS)--------------
  109. function startButtonListeners(action)
  110.     if action == "add" then
  111.         playButton:addEventListener( "tap", showGameView )
  112.         credButton:addEventListener( "tap", showCredits )
  113.     elseif action == "rmv" then
  114.         playButton:removeEventListener( "tap", showGameView )
  115.         credButton:removeEventListener( "tap", showCredits )
  116.     end
  117. end
  118.  
  119. function gameListeners(action)
  120.     if action == "add" then
  121.         aButton:addEventListener( "touch", gameFunction )
  122.         bButton:addEventListener( "touch", gameFunction )
  123.         cButton:addEventListener( "touch", gameFunction )
  124.         dButton:addEventListener( "touch", gameFunction )
  125.         Runtime:addEventListener( "enterFrame", update )
  126.     else
  127.         aButton:removeEventListener( "touch", gameFunction )
  128.         bButton:removeEventListener( "touch", gameFunction )
  129.         cButton:removeEventListener( "touch", gameFunction )
  130.         dButton:removeEventListener( "touch", gameFunction )
  131.         Runtime:removeEventListener( "enterFrame", update )
  132.     end
  133. end
  134.  
  135. function showCredits:tap(e)
  136.     playButton.isVisible = false
  137.     credButton.isVisible = false
  138.     credView = display.newImageRect ( "bg.jpg", 320, 480, true )
  139.     credView:setReferencePoint(display.CenterReferencePoint)
  140.     credView.x = _W
  141.     credView.y = _H
  142.     lastY = titleBg.y
  143.     transition.to ( titleBg, { time = 300, onComplete = function()
  144.         credButton.isVisible = true playButton.isVisible = true
  145.         credView:removeEventListener("tap", hideCredits)
  146.         display.remove( credView ) credView = nil
  147.         end} )
  148.        
  149.     transition.to ( creditsView, {time = 300, onComplete = function()
  150.         creditsView:addEventListener("tap", hideCredits)
  151.         end} )
  152. end
  153.  
  154. function hideCredits(e)
  155.     transition.to(credView, {time = 300, onComplete = function()
  156.         credButton.isVisible = true playButton.isVisible = true
  157.         credView:removeEventListener("tap", hideCredits)
  158.         display.remove(credView) credView = nil
  159.         end})
  160.        
  161.     transition.to(titleBg, {time = 300, y = lastY});
  162. end
  163.  
  164. function gameFunction(event)
  165.     if event.phase == "began" then
  166.         if event.target.answer == answerBeholder then
  167.             print(answerBeholder)
  168.             else
  169.             print("wrong answer")
  170.         end
  171.     end
  172.  
  173. end
  174.  
  175. function showGameView:tap(e)
  176.     R = math.random(1, #lookup.myBase)
  177.     answerBeholder = lookup.myBase[R].answer
  178.     question = display.newText( lookup.myBase[R].question, 0, 0, "SuperMarioGalaxy", 24 )
  179.     question:setTextColor ( 254, 254, 254 )
  180.     question.x = _W
  181.     question.y = 10
  182.     aButton = display.newImageRect ( "buttonImage.png", 320, 95, true )
  183.     aButton.x = _W
  184.     aButton.y = 200
  185.     aText = display.newText( lookup.myBase[R].alt1, 0, 0, "SuperMarioGalaxy", 24 )
  186.     aText:setTextColor ( 254, 254, 254 )
  187.     aText.x = aButton.x
  188.     aText.y = aButton.y
  189.  
  190.     bButton = display.newImageRect ( "buttonImage.png", 320, 95, true )
  191.     bButton.x = _W
  192.     bButton.y = aButton.y + 80
  193.     bText = display.newText( lookup.myBase[R].alt2, 0, 0, "SuperMarioGalaxy", 24 )
  194.     bText:setTextColor ( 254, 254, 254 )
  195.     bText.x = aButton.x
  196.     bText.y = bButton.y
  197.  
  198.     cButton = display.newImageRect ( "buttonImage.png", 320, 95, true )
  199.     cButton.x = _W
  200.     cButton.y = bButton.y + 80
  201.     cText = display.newText( lookup.myBase[R].alt3, 0, 0, "SuperMarioGalaxy", 24 )
  202.     cText:setTextColor ( 254, 254, 254 )
  203.     cText.x = aButton.x
  204.     cText.y = cButton.y
  205.  
  206.     dButton = display.newImageRect ( "buttonImage.png", 320, 95, true )
  207.     dButton.x = _W
  208.     dButton.y = cButton.y + 80
  209.     dText = display.newText( lookup.myBase[R].alt4, 0, 0, "SuperMarioGalaxy", 24 )
  210.     dText:setTextColor ( 254, 254, 254 )
  211.     dText.x = aButton.x
  212.     dText.y = dButton.y
  213.    
  214.     gameView = display.newGroup ( aButton, bButton, cButton, dButton, aText, bText, cText, dText, question )
  215.    
  216.     transition.to(gameView, {time = 300,
  217.     onComplete = function() gameListeners("add")
  218.     display.remove(titleView) titleView = nil
  219.     end})
  220. end
  221.  
  222.  
  223.  
  224. --CALL THE MAIN FUNCTION--------------
  225.  
  226. Main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement