I have a gameboard that has 16 spaces and 16 game pieces. On the game screen I show the 16 pieces off to the side of the gameboard and they are draggable to the gameboard.
What I need help with is setting up a table. I need the game to recognize when I have moved a piece to the board and which piece it is. Once all sixteen pieces are on the board I need to know if the pieces are in the correct spot. I am a real newby to programming but I am assuming those are if then statements regarding the correctness of the pieces?
Can somebody show me how to set this table up? I am reading tutorials but still am very confused:-( I just need the starter code and I can program the rest of the pieces but I am truly lost right now.
I have posted some code below that shows an example of my preliminary game screen. It has my background.png, the gameboard.png, a backbutton and one gamepiece. My gameboard size is 360 x 216 pixels.
I tried to start the table array as you can see but didn’t get anywhere. I’m not even sure if it’s in the right place in the code:-(
Michelle
[lua]module(…, package.seeall)
–>main function - MUST return a display.newGroup()
function new()
local localGroup = display.newGroup()
–> This is how we start every single file or “screen” in our folder, except for main.lua
– and director.lua
–> director.lua is NEVER modified, while only one line in main.lua changes, described in that file
local physics = require (“physics”)
physics.start ()
–>Background
local background = display.newImage (“blackbackground.png”)
localGroup:insert(background)
–> This sets the background
–>Gameboard
local gameboard = display.newImage (“gameboard.png”)
gameboard.x = 310
gameboard.y = 200
localGroup:insert(gameboard)
–>This sets the gameboard
–>Table Array Begins
local gameboard = (1, 2, 3, 4,
5, 6, 7, 8,
9, 10, 11, 12,
13, 14, 15, 16)
–>This creates the Table data
local redblock = display.newImage (“redblock.png”)
localGroup:insert(redblock)
redblock.x = 70
redblock.y = 50
local redblockx0, redblocky0
local function startDrag( event )
local redblock = event.target
local phase = event.phase
if “began” == phase then
– Store initial position
x0 = event.x
y0 = event.y
redblockx0 = redblock.x
redblocky0 = redblock.y
print(x0, y0)
– Stop current motion, if any
redblock:setLinearVelocity( 0, 0 )
redblock.angularVelocity = 0
elseif “moved” == phase or “ended” == phase or “cancelled” == phase then
redblock.x = redblockx0 + event.x - x0
redblock.y = redblocky0 + event.y - y0
end
– Stop further propagtion of touch event!
return true
end
redblock:addEventListener( “touch”, startDrag );
–>This ends the redblock drag code
local backbutton = display.newImage (“backbutton.png”)
localGroup:insert(backbutton)
backbutton.x = 75
backbutton.y = 300
backbutton.xScale = .5
backbutton.yScale = .5
local function touchedBackbutton (event)
if (“ended” == event.phase) then
director:changeScene( “titlescreen”, “fade” )
end
end
backbutton:addEventListener (“touch”, touchedBackbutton)
–>MUST return a display.newGroup()
–> This is how we end every file except for director and main, as mentioned in my first
return localGroup
end[/lua] [import]uid: 72372 topic_id: 12727 reply_id: 312727[/import]