javascript - Create an image puzzle game using jQuery -


i'm trying create image puzzle game using jquery. using code

var img_one=$("img[src$='one.jpg'][name='a']");  var atrval_one=img_one.attr("src"); var img_two=$("img[src$='blank.jpg'][name='b']");  var atrval_two=img_two.attr("src");   $('#one').click(function()  {      if(atrval_two ==  "images/img/blank.jpg"){        $("img", '#one').attr("src", atrval_nine);        $("img", '#two').attr("src", "images/img/one.jpg");     } });  

and html

<div id="one" class="1"  style="background-repeat:no-repeat;position:absolute;"><img id="1" name="a" src="images/img/one.jpg" /></div> <div id="two"  class="2" style="background-repeat:no-repeat; position:absolute;"><img id="2" name="b" src="images/img/blank.jpg" /></div> 

it sample code. have 9 divs , it's 3/3 arrangement. problem when click on nearest div of blank image change image please me find solution. please try understand situation

no need use thing can make in simple jquery or js sending type of game in answer check , make one. simple 0-9 puzzle game keep images @ place of numbers change images background images of buttons. gud luk

<!doctype html > <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>anuppuzzle</title> <script src="jquery-1.8.2.min.js"></script> <style> .main-container{background:#600; width:270px; height:270px; text-align:center;} button{width:80px; height:80px; background:#ccc; float:left; margin:5px; color:#600; font-size:18px; } button:hover{background:#9cf;} span{width:100%; color:#900; font-family:"comic sans ms", cursive;} </style> </head> <body> <h3>are want try brain logics...</h3> <div class="main-container">         <button alt="" name="1" value="1" id="1">5</button>     <button alt="" name="2" value="2" id="2">6</button>     <button alt="" name="3" value="3" id="3">8</button>     <button alt="" name="4" value="4" id="4">3</button>     <button alt="" name="5" value="5" id="5"></button>     <button alt="" name="6" value="6" id="6">7</button>     <button alt="" name="7" value="7" id="7">1</button>     <button alt="" name="8" value="8" id="8">2</button>     <button alt="" name="9" value="9" id="9">4</button> </div> <span>anup</span> </body> </html> <script> $(document).ready(function(){ var upval, downval, leftval, rightval, txt, bval; $("button").click(function(){     txt = $(this).text();     bval = $(this).val();        if(txt != ""){         if((bval != 1) && (bval != 2) &&(bval != 3)){             upval = eval(eval(bval)-eval(3));                        var uptxt = $("#"+upval).text();                         if(uptxt == ""){                             $("#"+upval).text(txt);                 $(this).text("");             }         }         if((bval != 7) && (bval != 8) &&(bval != 9)){             downval = eval(eval(bval)+ eval(3));                         var downtxt = $("#"+downval).text();             if(downtxt == ""){                           $("#"+downval).text(txt);                 $(this).text("");             }         }         if((bval != 1) && (bval != 4) &&(bval != 7)){             leftval = eval(eval(bval)-eval(1));                      var lefttxt = $("#"+leftval).text();             if(lefttxt == ""){                           $("#"+leftval).text(txt);                 $(this).text("");             }         }         if((bval != 3) && (bval != 6) &&(bval != 9)){             rightval = eval(eval(bval)+ eval(1));                        var righttxt = $("#"+rightval).text();                       if(righttxt == ""){                                  $("#"+rightval).text(txt);                 $(this).text("");             }         }         var 1 = $("#1").text();         var 2 = $("#2").text();         var 3 = $("#3").text();         var 4 = $("#4").text();         var 5 = $("#5").text();         var 6 = $("#6").text();         var 7 = $("#7").text();         var 8 = $("#8").text();         var 9 = $("#9").text();          if((one == "1")&&(two == "2")&&(three == "3")&&(four == "4")&&(five == "5")&&(six == "6")&&(seven == "7")&&(eight == "8")&&(nine == "")){                        alert("congratulations won game...");             $("button").attr("disabled", "disabled");         }                    }    });  });   </script> 

it full puzzle game code css,js , html.


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -