jquery - How to undo changes? -
i making educational game kids, have big problem. level one:
<div class="row" id="one"> <div class="col-md-12"> <div class="col-md-3"> <img src="img/ananas.png" class="img-responsive dimenzii"> <h3 class="drop1" id="drop1">______________</h3> </div> <div class="col-md-3"> <h1 class="green" id="dr2">Кокос</h1> </div> <div class="col-md-3"> <h1 class="green" id="dr1">Ананас</h1> </div> <div class="col-md-3"> <img src="img/coconut.png" class="img-responsive dimenzii"> <h3 class="drop2" id="drop2">______________</h3> </div> </div> </div>
i have 4 columns, outer ones pictures of fruit, , 2 inside contain name of fruit task connect two. works fine. problem when game ends, , question "do want play again?" appears, if clicked yes, shows first level, names dragged position before.
i tried manually change level previous condition not working. here jquery used:
$("#begin,#yes").click(function(){ $("#begin").hide(); game.play(); points = 0; $("#stazi").show(); $("#final, #one,#two,#three,#four,#five,#six,#seven,#eight").hide(); $("#one").show(); $("#poeni").html(points); $(".drop1,.drop2").html("_____________"); $("#dr1,#dr2").show(); settimeout( function(){ game.pause(); $("#stazi").fadeout(1000); $("#finalpoints").html(points); $("#final").delay(1000).fadein(2000); win.play(); } , 60000 ); });
can tell me how can save initial condition can use later?
you save initial state variable before starting. if levels aren't big use jquery's .clone() copy it, don't put in dom. when you're ready reset game can use .replacewith() destroy 1 on dom , replace saved copy of initial state.
var initialstate = $(levelid).clone(); // stuff modifies level $(levelid).replacewith(initialstate);
Comments
Post a Comment