PDA

View Full Version : Slider Puzzle help!



sparrow_5
July 7th, 2009, 10:02 PM
So I have been somewhat successful in creating a slider puzzle, but i was wondering:
how would i write a set of variables (x and y corodinates) for each tile in the correct place, and then being able to write the following:

if correctplacement gotoAndPlay 2

heres my script so far, it just moves the tiles around, and theres an issue with the vacant tile, but my main concern is dectecting if someone has won.


box1_mc.onRelease = function(){
var x:Number = this._x;
var y:Number = this._y;
this._x = empty_mc._x;
this._y = empty_mc._y;
empty_mc._x = x;
empty_mc._y = y;
}
box2_mc.onRelease = function(){
var x:Number = this._x;
var y:Number = this._y;
this._x = empty_mc._x;
this._y = empty_mc._y;
empty_mc._x = x;
empty_mc._y = y;
}
box3_mc.onRelease = function(){
var x:Number = this._x;
var y:Number = this._y;
this._x = empty_mc._x;
this._y = empty_mc._y;
empty_mc._x = x;
empty_mc._y = y;
}
box4_mc.onRelease = function(){
var x:Number = this._x;
var y:Number = this._y;
this._x = empty_mc._x;
this._y = empty_mc._y;
empty_mc._x = x;
empty_mc._y = y;
}
box5_mc.onRelease = function(){
var x:Number = this._x;
var y:Number = this._y;
this._x = empty_mc._x;
this._y = empty_mc._y;
empty_mc._x = x;
empty_mc._y = y;
}
box6_mc.onRelease = function(){
var x:Number = this._x;
var y:Number = this._y;
this._x = empty_mc._x;
this._y = empty_mc._y;
empty_mc._x = x;
empty_mc._y = y;
}

box7_mc.onRelease = function(){
var x:Number = this._x;
var y:Number = this._y;
this._x = empty_mc._x;
this._y = empty_mc._y;
empty_mc._x = x;
empty_mc._y = y;
}
box8_mc.onRelease = function(){
var x:Number = this._x;
var y:Number = this._y;
this._x = empty_mc._x;
this._y = empty_mc._y;
empty_mc._x = x;
empty_mc._y = y;
}

flyingmonkey456
July 7th, 2009, 10:21 PM
it's actually really simple, just have the correct coordinates in a variable for each tile and when the actual coordinates equal the correct coordinates for every tile, the person has won.

bluemagica
July 8th, 2009, 12:04 AM
whoa whoa! that's really a lot more work you are doing there than needed! Basically all you need to do is use a 2d array!

Well, if you have already done it this way, then I guess restructuring will be a headache for you, so just use a normal array, like,


arrx = [1,32,64,1,32,64,1,32]; //cooresponding x for the boxs
arry = [1,1,1,32,32,32,64,64];

as you can see, these two arrays form 8 pairs of values, for the 8 boxes, now you can check



function checkOrder()
{
for(i=0;i<8;i++)
{
if(_root["box"+(i+1)+"_mc"]._x!=arrx[i] || _root["box"+(i+1)+"_mc"]._y!=arry[i])
{
return false;
}
}
return true;
}

well this is all untested, but you should get the idea!

sparrow_5
July 8th, 2009, 06:33 AM
i think i understand the basic concept of having 2 arrays, so i have chucked in the x and y values, but i think this is a little advanced. so fine tuning it would be an issue.
here it is anway

arrx = [1,100,200,1,100,200,1,100];
arry = [1,1,1,100,100,100,200,200];

function checkOrder()
{
for(i=0;i<8;i++)
{
if(_root["box"+(i+1)+"_mc"]._x!=arrx[i] || _root["box"+(i+1)+"_mc"]._y!=arry[i])
{
return false;
}
}
return true;
}

but thanks for your help all the same.