$(document).ready(function() { var k = Karma({ audio: [{'name':'correct','file':'correct.ogg'}]}); k.ready(function(){ //initialize the variables used and display initial value var drag_no = 0; //store the current dragged no var drop_no = 0; //store the current dropped on no var imgrand = []; //stores the random variables generated var imgPosition = []; //stores the position of the random variable var drag_position = 0; //position of dragged object var drop_position = 0; //position of dropped object var flag, i ,j; var moves_count = 0; var imgPath; var feedbackImage = $('#feedback_image'); for(var i=0; i<16; i++){ feedbackImage.append(""); } game("img1"); $('a#anchorImg1').click(function(){ $("#"+imgPath+"").hide(); $(".dragme").show(); game("img1"); }); $('a#anchorImg2').click(function(){ $("#"+imgPath+"").hide(); $(".dragme").show(); game("img2"); }); $('a#anchorImg3').click(function(){ $("#"+imgPath+"").hide(); $(".dragme").show(); game("img3"); }); function generate_random_no() { //generate random number var rand_no = Math.ceil(16*Math.random()); return rand_no; } //update the Random variable number according to the position //update number according to the position and the value function update_Numbers_position(){ imgrand[drag_position] = drop_no; imgrand[drop_position] = drag_no; } //Check the game over function check_game_over(){ var x = 0; for(i=0;i<16;i++){ if(imgrand[i] == i+1){ x++; } } if(x == 16){ //puzzle solved . Hurray k.audio.correct.play(); $(".dragme").hide(); $("#"+imgPath+"").fadeIn(5000); } } function game(imgPuzzle){ //draws the necessary random numbers for the game imgPath = imgPuzzle; imgrand[0]=generate_random_no(); //1 number generated, 3 different numbers to be generated for(i=1; i<16; i++){ do{ flag = 0; imgrand[i] = generate_random_no(); for(j=0; j