/*
I would like to move the #p11 from pos1 to pos11 in direction 4,7,8,11
*/
$(".move").click(function(e){
/* console.log($(this).attr('tt')) */
animate($(this).attr('tt'));
});
var yy = 6;
var y = 1;
var directions;
var trashBin = [];
for (var t = 1; t <= 6; t++) {
var eachRow = "";
if (yy <= 36) {
for (var y = y; y <= yy; y++) {
eachRow += '<td id="pos' + y + '"><span class="numberTile">' + y + '</span></td>';
trashBin.push(y);
}
$('table').append('<tr>' + eachRow + '</tr>');
y = yy + 1;
yy = yy + 6;
}
}
function animate(player) {
//console.log(e);
direction = trashBin[Math.floor(Math.random() * trashBin.length)];
moveAnimate("#"+player, 0, direction);
var indexId = trashBin.indexOf(direction);
if (indexId > -1) {
trashBin.splice(indexId,1);
}
console.log(trashBin);
if(trashBin.length==0){
alert('game over')
}
}
function moveAnimate(element, count, randNum) {
console.log('rrr'+element)
if (count >= randNum) {
return;
}
newParent = '#pos' + randNum;
element = $(element); //Allow passing in either a JQuery object or selector
newParent = $(newParent); //Allow passing in either a JQuery object or selector
var oldOffset = element.offset();
element.appendTo(newParent);
var newOffset = element.offset();
var temp = element.clone().appendTo('body');
temp.css('position', 'absolute')
.css('left', oldOffset.left)
.css('top', oldOffset.top)
.css('zIndex', 1000);
element.hide();
temp.animate({
'top': newOffset.top,
'left': newOffset.left
}, 'slow', function() {
element.show();
temp.remove();
count++;
document.getElementById("'"+element+"'").parentNode.style.border=0;
document.getElementById("'"+element+"'").parentNode.style.color='transparent';
// moveAnimate(element, count);
});
/* if(count==0){
console.log('done');
document.getElementById('p11').parentNode.style.border=0;
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.