Picking the right match in order

  1. Apple, Preach, Red Onion flash on the screen. 

  2. Then 6 fruits/veggies appear on the screen including the 3 that flash.
     
    The purpose of this game is to remember the objects and the order in which they flash. 
     
    The code I have currently have moves the shapes in the order in which I click them in 3 different spots. I click the right shapes in the order in which they flash on the screen.
     
    Question:
    Can someone guide me in how I can let the user know they were correct?
     

    local fruitShuffle = require(“TableShuffle”) local dragFruits = require(“dragObject”) local fruits = require(“fruits”) local flashObjects = (“flashObjects”) local objectData = require(“objectData”) local fruitSheet = graphics.newImageSheet( “fruits.png”, fruits:getSheet() ) local t = objectData.Fruits shuffle(t) local s = {t[1],t[2],t[3],t[4],t[5],t[6]} – Shuffle 6 frames order from original Image Sheet shuffle(s) – Pulling frames from Shuffle table “s” showFruitsSeqData = { {name=“S1”,sheet=fruitSheet,frames={s[1]} }, {name=“S2”,sheet=fruitSheet,frames={s[2]} }, {name=“S3”,sheet=fruitSheet,frames={s[3]} }, {name=“S4”,sheet=fruitSheet,frames={s[4]} }, {name=“S5”,sheet=fruitSheet,frames={s[5]} }, {name=“S6”,sheet=fruitSheet,frames={s[6]} } } – configure size and placement for each frame store in table data local showFruitsData = { {frameIndex=s[1], width=80, height=80, x=50, y=25}, {frameIndex=s[2], width=80, height=80, x=display.contentCenterX, y=25 }, {frameIndex=s[3], width=80, height=80, x=270, y=25 }, {frameIndex=s[4], width=80, height=80, x=50, y=150 }, {frameIndex=s[5], width=80, height=80, x=display.contentCenterX, y=150 }, {frameIndex=s[6], width=80, height=80, x=270, y=150 } } local fruitsTransition = { {time=1000, x=50 ,y=400, onComplete}, {time=1000, x=display.contentCenterX, y=400, onComplete}, {time=1000, x=270, y=400, onComplete} } local number = 0 local textField = display.newText(number, 30, 325, native.systemFont, 25) local function moveIt(event) number = number + 1 textField:removeSelf() textField = display.newText(number, 30, 325, native.systemFont, 25) for i = number,#fruitsTransition do transition.to(event.target, fruitsTransition[i] ) return true end end – Looping the data from the ShowFruitsData Table & enabling objects to to drag local function showObjects() for i = 1,#showFruitsData do showFruits = display.newImageRect( fruitSheet, showFruitsData[i].frameIndex, showFruitsData[i].width, showFruitsData[i].height ) showFruits.x=showFruitsData[i].x showFruits.y=showFruitsData[i].y showFruits:addEventListener( “tap”, moveIt) end end showObjects() print(t[1],t[2],t[3],t[4],t[5],t[6]) print(s[1],s[2],s[3],s[4],s[5],s[6])

Hi kwesijc,

I would do something like that

  1. Shuffle table t. The result save in table s as you do in your code.

  2. Show (flash) first three fruits from s table.

  3. Show all fruits in random order and add ‘id’ property to each fruit. We use it later to distinguish them.

    local function showObjects() local fruitsIndex = {1,2,3,4,5,6} shuffle( fruitsIndex ) for j = 1,#fruitsIndex do i = fruitsIndex[j]   showFruits = display.newImageRect( ) showFruits.id= s[i] – Rest of your code end end

  4. Check fruits order in tap listener

    local success = true local function moveIt( event )     number = number + 1 local fruit = event.target     if s[number] ~= fruit.id then – No match success = false end – Rest of your code end 

  5. After three matches you know the result of game based on value of success variable.  

Read more :

Have a nice day:)

ldurniat

EDIT: I updated code due to error.

@Idurniat…Thank you for your response. The if s[number].id ~= fruit.id then success = false end tends throw off the code
 
 **s[number].id **in particular. When I just print (fruit.id) no issue. When I print ( s[number].id ) the is there. I was trying some workarounds but I can’t seem to fix it.
 

function showObjects() local fruitsIndex = {1,2,3,4,5,6} shuffle( fruitsIndex ) for j = 1,#fruitsIndex do i = fruitsIndex[j] -- for i = 1,#showFruitsData do showFruits = display.newImageRect( fruitSheet, showFruitsData[i].frameIndex, showFruitsData[i].width, showFruitsData[i].height ) showFruits.id= i showFruits.x=showFruitsData[i].x showFruits.y=showFruitsData[i].y if ( t[1] == s[i] or t[2] == s[i] or t[3] == s[i]) then print( "Match" ) else print( "No Match" ) showFruits:addEventListener( "tap", moveIt) end -- end end end local success = true function moveIt(event) number = number + 1 local fruit = event.target if s[number].id ~= fruit.id then success = false end textField:removeSelf() textField = display.newText(number, 30, 325, native.systemFont, 25) for i = number,#fruitsTransition do transition.to(event.target, fruitsTransition[i] ) -- local object = event.target -- print( object.name .. " TAP" ) return true end end end

@kwesijc: I made mistake. Sorry for that. Code updated. Should work now:)

Hi kwesijc,

I would do something like that

  1. Shuffle table t. The result save in table s as you do in your code.

  2. Show (flash) first three fruits from s table.

  3. Show all fruits in random order and add ‘id’ property to each fruit. We use it later to distinguish them.

    local function showObjects() local fruitsIndex = {1,2,3,4,5,6} shuffle( fruitsIndex ) for j = 1,#fruitsIndex do i = fruitsIndex[j]   showFruits = display.newImageRect( ) showFruits.id= s[i] – Rest of your code end end

  4. Check fruits order in tap listener

    local success = true local function moveIt( event )     number = number + 1 local fruit = event.target     if s[number] ~= fruit.id then – No match success = false end – Rest of your code end 

  5. After three matches you know the result of game based on value of success variable.  

Read more :

Have a nice day:)

ldurniat

EDIT: I updated code due to error.

@Idurniat…Thank you for your response. The if s[number].id ~= fruit.id then success = false end tends throw off the code
 
 **s[number].id **in particular. When I just print (fruit.id) no issue. When I print ( s[number].id ) the is there. I was trying some workarounds but I can’t seem to fix it.
 

function showObjects() local fruitsIndex = {1,2,3,4,5,6} shuffle( fruitsIndex ) for j = 1,#fruitsIndex do i = fruitsIndex[j] -- for i = 1,#showFruitsData do showFruits = display.newImageRect( fruitSheet, showFruitsData[i].frameIndex, showFruitsData[i].width, showFruitsData[i].height ) showFruits.id= i showFruits.x=showFruitsData[i].x showFruits.y=showFruitsData[i].y if ( t[1] == s[i] or t[2] == s[i] or t[3] == s[i]) then print( "Match" ) else print( "No Match" ) showFruits:addEventListener( "tap", moveIt) end -- end end end local success = true function moveIt(event) number = number + 1 local fruit = event.target if s[number].id ~= fruit.id then success = false end textField:removeSelf() textField = display.newText(number, 30, 325, native.systemFont, 25) for i = number,#fruitsTransition do transition.to(event.target, fruitsTransition[i] ) -- local object = event.target -- print( object.name .. " TAP" ) return true end end end

@kwesijc: I made mistake. Sorry for that. Code updated. Should work now:)