var Tetris = AspectScript.i13n.wrap(function(){return (function Tetris(){ {var Tetris = arguments.callee = arguments.callee.wrapper;var Window = AspectScript.i13n.wrap(function(){return (function Window(id){ {var Window = arguments.callee = arguments.callee.wrapper;AspectScript.i13n.propWrite(this,"id",id); AspectScript.i13n.propWrite(this,"el",AspectScript.i13n.call2(AspectScript.i13n.propRead(AspectScript.globalObject,"document"),"getElementById",[AspectScript.i13n.propRead(this,"id")],this)); var self = this; AspectScript.i13n.propWrite(this,"activate",AspectScript.i13n.wrap(function(){return (function (){ {arguments.callee = arguments.callee.wrapper;AspectScript.i13n.propWrite(AspectScript.i13n.propRead(AspectScript.i13n.propRead(self,"el"),"style"),"display",(((AspectScript.i13n.propRead(AspectScript.i13n.propRead(AspectScript.i13n.propRead(self,"el"),"style"),"display") == "block")?("none"):("block")))); }})})); AspectScript.i13n.propWrite(this,"close",AspectScript.i13n.wrap(function(){return (function (){ {arguments.callee = arguments.callee.wrapper;AspectScript.i13n.propWrite(AspectScript.i13n.propRead(AspectScript.i13n.propRead(self,"el"),"style"),"display","none"); }})})); AspectScript.i13n.propWrite(this,"isActive",AspectScript.i13n.wrap(function(){return (function (){ {arguments.callee = arguments.callee.wrapper;return (AspectScript.i13n.propRead(AspectScript.i13n.propRead(AspectScript.i13n.propRead(self,"el"),"style"),"display") == "block"); }})})); }})}); var Keyboard = AspectScript.i13n.wrap(function(){return (function Keyboard(){ {var Keyboard = arguments.callee = arguments.callee.wrapper;AspectScript.i13n.propWrite(this,"up",38); AspectScript.i13n.propWrite(this,"down",40); AspectScript.i13n.propWrite(this,"left",37); AspectScript.i13n.propWrite(this,"right",39); AspectScript.i13n.propWrite(this,"n",78); AspectScript.i13n.propWrite(this,"r",82); AspectScript.i13n.propWrite(this,"space",32); AspectScript.i13n.propWrite(this,"f12",123); AspectScript.i13n.propWrite(this,"escape",27); AspectScript.i13n.propWrite(this,"keys",AspectScript.i13n.creation4([])); AspectScript.i13n.propWrite(this,"funcs",AspectScript.i13n.creation4([])); var self = this; AspectScript.i13n.propWrite(this,"set",AspectScript.i13n.wrap(function(){return (function (key,func){ {arguments.callee = arguments.callee.wrapper;AspectScript.i13n.call2(AspectScript.i13n.propRead(this,"keys"),"push",[key],this); AspectScript.i13n.call2(AspectScript.i13n.propRead(this,"funcs"),"push",[func],this); }})})); AspectScript.i13n.propWrite(this,"event",AspectScript.i13n.wrap(function(){return (function (e){ {arguments.callee = arguments.callee.wrapper;if(!e){ e = AspectScript.i13n.propRead(AspectScript.i13n.propRead(AspectScript.globalObject,"window"),"event"); } for(var i = 0;i < AspectScript.i13n.propRead(AspectScript.i13n.propRead(self,"keys"),"length");i++){ if(AspectScript.i13n.propRead(e,"keyCode") == AspectScript.i13n.propRead(AspectScript.i13n.propRead(self,"keys"),i)){ AspectScript.i13n.call2(AspectScript.i13n.propRead(self,"funcs"),i,[],this); } } }})})); }})}); var Stats = AspectScript.i13n.wrap(function(){return (function Stats(){ {var Stats = arguments.callee = arguments.callee.wrapper;AspectScript.i13n.propRead(this,"level"); AspectScript.i13n.propRead(this,"time"); AspectScript.i13n.propRead(this,"apm"); AspectScript.i13n.propRead(this,"lines"); AspectScript.i13n.propRead(this,"score"); AspectScript.i13n.propRead(this,"puzzles"); AspectScript.i13n.propRead(this,"actions"); AspectScript.i13n.propWrite(this,"el",AspectScript.i13n.creation2(function(){var $__this__=arguments[0];arguments=arguments[1];AspectScript.i13n.propWrite($__this__, "level",AspectScript.i13n.call2(AspectScript.i13n.propRead(AspectScript.globalObject,"document"),"getElementById",["tetris-stats-level"],this));AspectScript.i13n.propWrite($__this__, "time",AspectScript.i13n.call2(AspectScript.i13n.propRead(AspectScript.globalObject,"document"),"getElementById",["tetris-stats-time"],this));AspectScript.i13n.propWrite($__this__, "apm",AspectScript.i13n.call2(AspectScript.i13n.propRead(AspectScript.globalObject,"document"),"getElementById",["tetris-stats-apm"],this));AspectScript.i13n.propWrite($__this__, "lines",AspectScript.i13n.call2(AspectScript.i13n.propRead(AspectScript.globalObject,"document"),"getElementById",["tetris-stats-lines"],this));AspectScript.i13n.propWrite($__this__, "score",AspectScript.i13n.call2(AspectScript.i13n.propRead(AspectScript.globalObject,"document"),"getElementById",["tetris-stats-score"],this));},this,arguments)); AspectScript.i13n.propWrite(this,"timerId",null); var self = this; AspectScript.i13n.propWrite(this,"start",AspectScript.i13n.wrap(function(){return (function (){ {arguments.callee = arguments.callee.wrapper;AspectScript.i13n.call2(this,"reset",[],this); AspectScript.i13n.propWrite(this,"timerId",AspectScript.i13n.call(AspectScript.globalObject,AspectScript.i13n.propRead(AspectScript.globalObject,"setInterval"),[AspectScript.i13n.propRead(this,"incTime"), 10],this)); }})})); AspectScript.i13n.propWrite(this,"stop",AspectScript.i13n.wrap(function(){return (function (){ {arguments.callee = arguments.callee.wrapper;if(AspectScript.i13n.propRead(this,"timerId")){ AspectScript.i13n.call(AspectScript.globalObject,AspectScript.i13n.propRead(AspectScript.globalObject,"clearInterval"),[AspectScript.i13n.propRead(this,"timerId")],this); } }})})); AspectScript.i13n.propWrite(this,"reset",AspectScript.i13n.wrap(function(){return (function (){ {arguments.callee = arguments.callee.wrapper;AspectScript.i13n.call2(this,"stop",[],this); AspectScript.i13n.propWrite(this,"level",1); AspectScript.i13n.propWrite(this,"time",0); AspectScript.i13n.propWrite(this,"apm",0); AspectScript.i13n.propWrite(this,"lines",0); AspectScript.i13n.propWrite(this,"score",0); AspectScript.i13n.propWrite(this,"puzzles",0); AspectScript.i13n.propWrite(this,"actions",0); AspectScript.i13n.propWrite(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"el"),"level"),"innerHTML",AspectScript.i13n.propRead(this,"level")); AspectScript.i13n.propWrite(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"el"),"time"),"innerHTML",AspectScript.i13n.propRead(this,"time")); AspectScript.i13n.propWrite(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"el"),"apm"),"innerHTML",AspectScript.i13n.propRead(this,"apm")); AspectScript.i13n.propWrite(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"el"),"lines"),"innerHTML",AspectScript.i13n.propRead(this,"lines")); AspectScript.i13n.propWrite(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"el"),"score"),"innerHTML",AspectScript.i13n.propRead(this,"score")); }})})); AspectScript.i13n.propWrite(this,"incTime",AspectScript.i13n.wrap(function(){return (function (){ {arguments.callee = arguments.callee.wrapper;AspectScript.i13n.propIncr(self,"time",1,true); AspectScript.i13n.propWrite(AspectScript.i13n.propRead(AspectScript.i13n.propRead(self,"el"),"time"),"innerHTML",AspectScript.i13n.propRead(self,"time")); AspectScript.i13n.propWrite(self,"apm",AspectScript.i13n.call(AspectScript.globalObject,AspectScript.i13n.propRead(AspectScript.globalObject,"parseInt"),[(AspectScript.i13n.propRead(self,"actions") / AspectScript.i13n.propRead(self,"time")) * 60],this)); AspectScript.i13n.propWrite(AspectScript.i13n.propRead(AspectScript.i13n.propRead(self,"el"),"apm"),"innerHTML",AspectScript.i13n.propRead(self,"apm")); }})})); AspectScript.i13n.propWrite(this,"setScore",AspectScript.i13n.wrap(function(){return (function (i){ {arguments.callee = arguments.callee.wrapper;AspectScript.i13n.propWrite(this,"score",i); AspectScript.i13n.propWrite(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"el"),"score"),"innerHTML",AspectScript.i13n.propRead(this,"score")); }})})); AspectScript.i13n.propWrite(this,"setLevel",AspectScript.i13n.wrap(function(){return (function (i){ {arguments.callee = arguments.callee.wrapper;AspectScript.i13n.propWrite(this,"level",i); AspectScript.i13n.propWrite(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"el"),"level"),"innerHTML",AspectScript.i13n.propRead(this,"level")); }})})); AspectScript.i13n.propWrite(this,"setLines",AspectScript.i13n.wrap(function(){return (function (i){ {arguments.callee = arguments.callee.wrapper;AspectScript.i13n.propWrite(this,"lines",i); AspectScript.i13n.propWrite(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"el"),"lines"),"innerHTML",AspectScript.i13n.propRead(this,"lines")); }})})); AspectScript.i13n.propWrite(this,"setPuzzles",AspectScript.i13n.wrap(function(){return (function (i){ {arguments.callee = arguments.callee.wrapper;AspectScript.i13n.propWrite(this,"puzzles",i); }})})); AspectScript.i13n.propWrite(this,"setActions",AspectScript.i13n.wrap(function(){return (function (i){ {arguments.callee = arguments.callee.wrapper;AspectScript.i13n.propWrite(this,"actions",i); }})})); AspectScript.i13n.propWrite(this,"getScore",AspectScript.i13n.wrap(function(){return (function (){ {arguments.callee = arguments.callee.wrapper;return AspectScript.i13n.propRead(this,"score"); }})})); AspectScript.i13n.propWrite(this,"getLevel",AspectScript.i13n.wrap(function(){return (function (){ {arguments.callee = arguments.callee.wrapper;return AspectScript.i13n.propRead(this,"level"); }})})); AspectScript.i13n.propWrite(this,"getLines",AspectScript.i13n.wrap(function(){return (function (){ {arguments.callee = arguments.callee.wrapper;return AspectScript.i13n.propRead(this,"lines"); }})})); AspectScript.i13n.propWrite(this,"getPuzzles",AspectScript.i13n.wrap(function(){return (function (){ {arguments.callee = arguments.callee.wrapper;return AspectScript.i13n.propRead(this,"puzzles"); }})})); AspectScript.i13n.propWrite(this,"getActions",AspectScript.i13n.wrap(function(){return (function (){ {arguments.callee = arguments.callee.wrapper;return AspectScript.i13n.propRead(this,"actions"); }})})); }})}); var Area = AspectScript.i13n.wrap(function(){return (function Area(unit,x,y,id){ {var Area = arguments.callee = arguments.callee.wrapper;AspectScript.i13n.propWrite(this,"unit",unit); AspectScript.i13n.propWrite(this,"x",x); AspectScript.i13n.propWrite(this,"y",y); AspectScript.i13n.propWrite(this,"el",AspectScript.i13n.call2(AspectScript.i13n.propRead(AspectScript.globalObject,"document"),"getElementById",[id],this)); AspectScript.i13n.propWrite(this,"board",AspectScript.i13n.creation4([])); for(var y = 0;y < AspectScript.i13n.propRead(this,"y");y++){ AspectScript.i13n.call2(AspectScript.i13n.propRead(this,"board"),"push",[AspectScript.i13n.creation(0,AspectScript.i13n.propRead(AspectScript.globalObject,"Array"),[])],this); for(var x = 0;x < AspectScript.i13n.propRead(this,"x");x++){ AspectScript.i13n.call2(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"board"),y),"push",[0],this); } } AspectScript.i13n.propWrite(this,"destroy",AspectScript.i13n.wrap(function(){return (function (){ {arguments.callee = arguments.callee.wrapper;for(var y = 0;y < AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"board"),"length");y++){ for(var x = 0;x < AspectScript.i13n.propRead(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"board"),y),"length");x++){ if(AspectScript.i13n.propRead(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"board"),y),x)){ AspectScript.i13n.call2(AspectScript.i13n.propRead(this,"el"),"removeChild",[AspectScript.i13n.propRead(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"board"),y),x)],this); AspectScript.i13n.propWrite(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"board"),y),x,0); } } } }})})); AspectScript.i13n.propWrite(this,"removeFullLines",AspectScript.i13n.wrap(function(){return (function (){ {arguments.callee = arguments.callee.wrapper;var lines = 0; for(var y = AspectScript.i13n.propRead(this,"y") - 1;y > 0;y--){ if(AspectScript.i13n.call2(this,"isLineFull",[y],this)){ AspectScript.i13n.call2(this,"removeLine",[y],this); lines++; y++; } } return lines; }})})); AspectScript.i13n.propWrite(this,"isLineFull",AspectScript.i13n.wrap(function(){return (function (y){ {arguments.callee = arguments.callee.wrapper;for(var x = 0;x < AspectScript.i13n.propRead(this,"x");x++){ if(!AspectScript.i13n.propRead(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"board"),y),x)){ return false; } } return true; }})})); AspectScript.i13n.propWrite(this,"removeLine",AspectScript.i13n.wrap(function(){return (function (y){ {arguments.callee = arguments.callee.wrapper;for(var x = 0;x < AspectScript.i13n.propRead(this,"x");x++){ AspectScript.i13n.call2(AspectScript.i13n.propRead(this,"el"),"removeChild",[AspectScript.i13n.propRead(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"board"),y),x)],this); AspectScript.i13n.propWrite(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"board"),y),x,0); } y--; for(;y > 0;y--){ for(var x = 0;x < AspectScript.i13n.propRead(this,"x");x++){ if(AspectScript.i13n.propRead(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"board"),y),x)){ var el = AspectScript.i13n.propRead(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"board"),y),x); AspectScript.i13n.propWrite(AspectScript.i13n.propRead(el,"style"),"top",AspectScript.i13n.propRead(el,"offsetTop") + AspectScript.i13n.propRead(this,"unit") + "px"); AspectScript.i13n.propWrite(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"board"),y + 1),x,el); AspectScript.i13n.propWrite(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"board"),y),x,0); } } } }})})); AspectScript.i13n.propWrite(this,"getBlock",AspectScript.i13n.wrap(function(){return (function (y,x){ {arguments.callee = arguments.callee.wrapper;if(y < 0){ return 0; } if(y < AspectScript.i13n.propRead(this,"y") && x < AspectScript.i13n.propRead(this,"x")){ return AspectScript.i13n.propRead(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"board"),y),x); } else { throw "Area.getBlock(" + y + ", " + x + ") failed" } }})})); AspectScript.i13n.propWrite(this,"addElement",AspectScript.i13n.wrap(function(){return (function (el){ {arguments.callee = arguments.callee.wrapper;var x = AspectScript.i13n.call(AspectScript.globalObject,AspectScript.i13n.propRead(AspectScript.globalObject,"parseInt"),[AspectScript.i13n.propRead(el,"offsetLeft") / AspectScript.i13n.propRead(this,"unit")],this); var y = AspectScript.i13n.call(AspectScript.globalObject,AspectScript.i13n.propRead(AspectScript.globalObject,"parseInt"),[AspectScript.i13n.propRead(el,"offsetTop") / AspectScript.i13n.propRead(this,"unit")],this); if(y >= 0 && y < AspectScript.i13n.propRead(this,"y") && x >= 0 && x < AspectScript.i13n.propRead(this,"x")){ AspectScript.i13n.propWrite(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"board"),y),x,el); } else { } }})})); }})}); var Puzzle = AspectScript.i13n.wrap(function(){return (function Puzzle(tetris,area){ {var Puzzle = arguments.callee = arguments.callee.wrapper;var self = this; AspectScript.i13n.propWrite(this,"tetris",tetris); AspectScript.i13n.propWrite(this,"area",area); AspectScript.i13n.propWrite(this,"fallDownID",null); AspectScript.i13n.propWrite(this,"forceMoveDownID",null); AspectScript.i13n.propWrite(this,"type",null); AspectScript.i13n.propWrite(this,"nextType",null); AspectScript.i13n.propWrite(this,"position",null); AspectScript.i13n.propWrite(this,"speed",null); AspectScript.i13n.propWrite(this,"running",null); AspectScript.i13n.propWrite(this,"stopped",null); AspectScript.i13n.propWrite(this,"board",AspectScript.i13n.creation4([])); AspectScript.i13n.propWrite(this,"elements",AspectScript.i13n.creation4([])); AspectScript.i13n.propWrite(this,"nextElements",AspectScript.i13n.creation4([])); AspectScript.i13n.propWrite(this,"x",null); AspectScript.i13n.propWrite(this,"y",null); AspectScript.i13n.propWrite(this,"puzzles",AspectScript.i13n.creation4([AspectScript.i13n.creation4([AspectScript.i13n.creation4([0, 0, 1]), AspectScript.i13n.creation4([1, 1, 1]), AspectScript.i13n.creation4([0, 0, 0])]), AspectScript.i13n.creation4([AspectScript.i13n.creation4([1, 0, 0]), AspectScript.i13n.creation4([1, 1, 1]), AspectScript.i13n.creation4([0, 0, 0])]), AspectScript.i13n.creation4([AspectScript.i13n.creation4([0, 1, 1]), AspectScript.i13n.creation4([1, 1, 0]), AspectScript.i13n.creation4([0, 0, 0])]), AspectScript.i13n.creation4([AspectScript.i13n.creation4([1, 1, 0]), AspectScript.i13n.creation4([0, 1, 1]), AspectScript.i13n.creation4([0, 0, 0])]), AspectScript.i13n.creation4([AspectScript.i13n.creation4([0, 1, 0]), AspectScript.i13n.creation4([1, 1, 1]), AspectScript.i13n.creation4([0, 0, 0])]), AspectScript.i13n.creation4([AspectScript.i13n.creation4([1, 1]), AspectScript.i13n.creation4([1, 1])]), AspectScript.i13n.creation4([AspectScript.i13n.creation4([0, 0, 0, 0]), AspectScript.i13n.creation4([1, 1, 1, 1]), AspectScript.i13n.creation4([0, 0, 0, 0]), AspectScript.i13n.creation4([0, 0, 0, 0])])])); AspectScript.i13n.propWrite(this,"reset",AspectScript.i13n.wrap(function(){return (function (){ {arguments.callee = arguments.callee.wrapper;if(AspectScript.i13n.propRead(this,"fallDownID")){ AspectScript.i13n.call(AspectScript.globalObject,AspectScript.i13n.propRead(AspectScript.globalObject,"clearTimeout"),[AspectScript.i13n.propRead(this,"fallDownID")],this); } if(AspectScript.i13n.propRead(this,"forceMoveDownID")){ AspectScript.i13n.call(AspectScript.globalObject,AspectScript.i13n.propRead(AspectScript.globalObject,"clearTimeout"),[AspectScript.i13n.propRead(this,"forceMoveDownID")],this); } AspectScript.i13n.propWrite(this,"type",AspectScript.i13n.propRead(this,"nextType")); AspectScript.i13n.propWrite(this,"nextType",AspectScript.i13n.call(AspectScript.globalObject,random,[AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"puzzles"),"length")],this)); AspectScript.i13n.propWrite(this,"position",0); AspectScript.i13n.propWrite(this,"speed",100 + (700 / AspectScript.i13n.call2(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"tetris"),"stats"),"getLevel",[],this))); AspectScript.i13n.propWrite(this,"running",false); AspectScript.i13n.propWrite(this,"stopped",false); AspectScript.i13n.propWrite(this,"board",AspectScript.i13n.creation4([])); AspectScript.i13n.propWrite(this,"elements",AspectScript.i13n.creation4([])); for(var i = 0;i < AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"nextElements"),"length");i++){ AspectScript.i13n.call2(AspectScript.i13n.call2(AspectScript.i13n.propRead(AspectScript.globalObject,"document"),"getElementById",["tetris-nextpuzzle"],this),"removeChild",[AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"nextElements"),i)],this); } AspectScript.i13n.propWrite(this,"nextElements",AspectScript.i13n.creation4([])); AspectScript.i13n.propWrite(this,"x",null); AspectScript.i13n.propWrite(this,"y",null); }})})); AspectScript.i13n.propWrite(this,"nextType",AspectScript.i13n.call(AspectScript.globalObject,random,[AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"puzzles"),"length")],this)); AspectScript.i13n.call2(this,"reset",[],this); AspectScript.i13n.propWrite(this,"isRunning",AspectScript.i13n.wrap(function(){return (function (){ {arguments.callee = arguments.callee.wrapper;return AspectScript.i13n.propRead(this,"running"); }})})); AspectScript.i13n.propWrite(this,"isStopped",AspectScript.i13n.wrap(function(){return (function (){ {arguments.callee = arguments.callee.wrapper;return AspectScript.i13n.propRead(this,"stopped"); }})})); AspectScript.i13n.propWrite(this,"getX",AspectScript.i13n.wrap(function(){return (function (){ {arguments.callee = arguments.callee.wrapper;return AspectScript.i13n.propRead(this,"x"); }})})); AspectScript.i13n.propWrite(this,"getY",AspectScript.i13n.wrap(function(){return (function (){ {arguments.callee = arguments.callee.wrapper;return AspectScript.i13n.propRead(this,"y"); }})})); AspectScript.i13n.propWrite(this,"mayPlace",AspectScript.i13n.wrap(function(){return (function (){ {arguments.callee = arguments.callee.wrapper;var puzzle = AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"puzzles"),AspectScript.i13n.propRead(this,"type")); var areaStartX = AspectScript.i13n.call(AspectScript.globalObject,AspectScript.i13n.propRead(AspectScript.globalObject,"parseInt"),[(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"area"),"x") - AspectScript.i13n.propRead(AspectScript.i13n.propRead(puzzle,0),"length")) / 2],this); var areaStartY = 1; var lineFound = false; var lines = 0; for(var y = AspectScript.i13n.propRead(puzzle,"length") - 1;y >= 0;y--){ for(var x = 0;x < AspectScript.i13n.propRead(AspectScript.i13n.propRead(puzzle,y),"length");x++){ if(AspectScript.i13n.propRead(AspectScript.i13n.propRead(puzzle,y),x)){ lineFound = true; if(AspectScript.i13n.call2(AspectScript.i13n.propRead(this,"area"),"getBlock",[areaStartY, areaStartX + x],this)){ return false; } } } if(lineFound){ lines++; } if(areaStartY - lines < 0){ break } } return true; }})})); AspectScript.i13n.propWrite(this,"place",AspectScript.i13n.wrap(function(){return (function (){ {arguments.callee = arguments.callee.wrapper;AspectScript.i13n.call2(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"tetris"),"stats"),"setPuzzles",[AspectScript.i13n.call2(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"tetris"),"stats"),"getPuzzles",[],this) + 1],this); if(AspectScript.i13n.call2(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"tetris"),"stats"),"getPuzzles",[],this) >= (10 + AspectScript.i13n.call2(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"tetris"),"stats"),"getLevel",[],this) * 2)){ AspectScript.i13n.call2(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"tetris"),"stats"),"setLevel",[AspectScript.i13n.call2(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"tetris"),"stats"),"getLevel",[],this) + 1],this); AspectScript.i13n.call2(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"tetris"),"stats"),"setPuzzles",[0],this); } var puzzle = AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"puzzles"),AspectScript.i13n.propRead(this,"type")); var areaStartX = AspectScript.i13n.call(AspectScript.globalObject,AspectScript.i13n.propRead(AspectScript.globalObject,"parseInt"),[(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"area"),"x") - AspectScript.i13n.propRead(AspectScript.i13n.propRead(puzzle,0),"length")) / 2],this); var areaStartY = 1; var lineFound = false; var lines = 0; AspectScript.i13n.propWrite(this,"x",areaStartX); AspectScript.i13n.propWrite(this,"y",1); AspectScript.i13n.propWrite(this,"board",AspectScript.i13n.call2(this,"createEmptyPuzzle",[AspectScript.i13n.propRead(puzzle,"length"), AspectScript.i13n.propRead(AspectScript.i13n.propRead(puzzle,0),"length")],this)); for(var y = AspectScript.i13n.propRead(puzzle,"length") - 1;y >= 0;y--){ for(var x = 0;x < AspectScript.i13n.propRead(AspectScript.i13n.propRead(puzzle,y),"length");x++){ if(AspectScript.i13n.propRead(AspectScript.i13n.propRead(puzzle,y),x)){ lineFound = true; var el = AspectScript.i13n.call2(AspectScript.i13n.propRead(AspectScript.globalObject,"document"),"createElement",["div"],this); AspectScript.i13n.propWrite(el,"className","block" + AspectScript.i13n.propRead(this,"type")); AspectScript.i13n.propWrite(AspectScript.i13n.propRead(el,"style"),"left",(areaStartX + x) * AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"area"),"unit") + "px"); AspectScript.i13n.propWrite(AspectScript.i13n.propRead(el,"style"),"top",(areaStartY - lines) * AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"area"),"unit") + "px"); AspectScript.i13n.call2(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"area"),"el"),"appendChild",[el],this); AspectScript.i13n.propWrite(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"board"),y),x,el); AspectScript.i13n.call2(AspectScript.i13n.propRead(this,"elements"),"push",[el],this); } } if(lines){ AspectScript.i13n.propIncr(this,"y",-1,true); } if(lineFound){ lines++; } } AspectScript.i13n.propWrite(this,"running",true); AspectScript.i13n.propWrite(this,"fallDownID",AspectScript.i13n.call(AspectScript.globalObject,AspectScript.i13n.propRead(AspectScript.globalObject,"setTimeout"),[AspectScript.i13n.propRead(this,"fallDown"), AspectScript.i13n.propRead(this,"speed")],this)); var nextPuzzle = AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"puzzles"),AspectScript.i13n.propRead(this,"nextType")); for(var y = 0;y < AspectScript.i13n.propRead(nextPuzzle,"length");y++){ for(var x = 0;x < AspectScript.i13n.propRead(AspectScript.i13n.propRead(nextPuzzle,y),"length");x++){ if(AspectScript.i13n.propRead(AspectScript.i13n.propRead(nextPuzzle,y),x)){ var el = AspectScript.i13n.call2(AspectScript.i13n.propRead(AspectScript.globalObject,"document"),"createElement",["div"],this); AspectScript.i13n.propWrite(el,"className","block" + AspectScript.i13n.propRead(this,"nextType")); AspectScript.i13n.propWrite(AspectScript.i13n.propRead(el,"style"),"left",(x * AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"area"),"unit")) + "px"); AspectScript.i13n.propWrite(AspectScript.i13n.propRead(el,"style"),"top",(y * AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"area"),"unit")) + "px"); AspectScript.i13n.call2(AspectScript.i13n.call2(AspectScript.i13n.propRead(AspectScript.globalObject,"document"),"getElementById",["tetris-nextpuzzle"],this),"appendChild",[el],this); AspectScript.i13n.call2(AspectScript.i13n.propRead(this,"nextElements"),"push",[el],this); } } } }})})); AspectScript.i13n.propWrite(this,"destroy",AspectScript.i13n.wrap(function(){return (function (){ {arguments.callee = arguments.callee.wrapper;for(var i = 0;i < AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"elements"),"length");i++){ AspectScript.i13n.call2(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"area"),"el"),"removeChild",[AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"elements"),i)],this); } AspectScript.i13n.propWrite(this,"elements",AspectScript.i13n.creation4([])); AspectScript.i13n.propWrite(this,"board",AspectScript.i13n.creation4([])); AspectScript.i13n.call2(this,"reset",[],this); }})})); AspectScript.i13n.propWrite(this,"createEmptyPuzzle",AspectScript.i13n.wrap(function(){return (function (y,x){ {arguments.callee = arguments.callee.wrapper;var puzzle = AspectScript.i13n.creation4([]); for(var y2 = 0;y2 < y;y2++){ AspectScript.i13n.call2(puzzle,"push",[AspectScript.i13n.creation(0,AspectScript.i13n.propRead(AspectScript.globalObject,"Array"),[])],this); for(var x2 = 0;x2 < x;x2++){ AspectScript.i13n.call2(AspectScript.i13n.propRead(puzzle,y2),"push",[0],this); } } return puzzle; }})})); AspectScript.i13n.propWrite(this,"fallDown",AspectScript.i13n.wrap(function(){return (function (){ {arguments.callee = arguments.callee.wrapper;if(AspectScript.i13n.call2(self,"isRunning",[],this)){ if(AspectScript.i13n.call2(self,"mayMoveDown",[],this)){ AspectScript.i13n.call2(self,"moveDown",[],this); AspectScript.i13n.propWrite(self,"fallDownID",AspectScript.i13n.call(AspectScript.globalObject,AspectScript.i13n.propRead(AspectScript.globalObject,"setTimeout"),[AspectScript.i13n.propRead(self,"fallDown"), AspectScript.i13n.propRead(self,"speed")],this)); } else { for(var i = 0;i < AspectScript.i13n.propRead(AspectScript.i13n.propRead(self,"elements"),"length");i++){ AspectScript.i13n.call2(AspectScript.i13n.propRead(self,"area"),"addElement",[AspectScript.i13n.propRead(AspectScript.i13n.propRead(self,"elements"),i)],this); } var lines = AspectScript.i13n.call2(AspectScript.i13n.propRead(self,"area"),"removeFullLines",[],this); if(lines){ AspectScript.i13n.call2(AspectScript.i13n.propRead(AspectScript.i13n.propRead(self,"tetris"),"stats"),"setLines",[AspectScript.i13n.call2(AspectScript.i13n.propRead(AspectScript.i13n.propRead(self,"tetris"),"stats"),"getLines",[],this) + lines],this); AspectScript.i13n.call2(AspectScript.i13n.propRead(AspectScript.i13n.propRead(self,"tetris"),"stats"),"setScore",[AspectScript.i13n.call2(AspectScript.i13n.propRead(AspectScript.i13n.propRead(self,"tetris"),"stats"),"getScore",[],this) + (1000 * AspectScript.i13n.call2(AspectScript.i13n.propRead(AspectScript.i13n.propRead(self,"tetris"),"stats"),"getLevel",[],this) * lines)],this); } AspectScript.i13n.call2(self,"reset",[],this); if(AspectScript.i13n.call2(self,"mayPlace",[],this)){ AspectScript.i13n.call2(self,"place",[],this); } else { AspectScript.i13n.call2(AspectScript.i13n.propRead(self,"tetris"),"gameOver",[],this); } } } }})})); AspectScript.i13n.propWrite(this,"forceMoveDown",AspectScript.i13n.wrap(function(){return (function (){ {arguments.callee = arguments.callee.wrapper;if(!AspectScript.i13n.call2(self,"isRunning",[],this) && !AspectScript.i13n.call2(self,"isStopped",[],this)){ if(AspectScript.i13n.call2(self,"mayMoveDown",[],this)){ AspectScript.i13n.call2(AspectScript.i13n.propRead(AspectScript.i13n.propRead(self,"tetris"),"stats"),"setScore",[AspectScript.i13n.call2(AspectScript.i13n.propRead(AspectScript.i13n.propRead(self,"tetris"),"stats"),"getScore",[],this) + 5 + AspectScript.i13n.call2(AspectScript.i13n.propRead(AspectScript.i13n.propRead(self,"tetris"),"stats"),"getLevel",[],this)],this); AspectScript.i13n.call2(AspectScript.i13n.propRead(AspectScript.i13n.propRead(self,"tetris"),"stats"),"setActions",[AspectScript.i13n.call2(AspectScript.i13n.propRead(AspectScript.i13n.propRead(self,"tetris"),"stats"),"getActions",[],this) + 1],this); AspectScript.i13n.call2(self,"moveDown",[],this); AspectScript.i13n.propWrite(self,"forceMoveDownID",AspectScript.i13n.call(AspectScript.globalObject,AspectScript.i13n.propRead(AspectScript.globalObject,"setTimeout"),[AspectScript.i13n.propRead(self,"forceMoveDown"), 30],this)); } else { for(var i = 0;i < AspectScript.i13n.propRead(AspectScript.i13n.propRead(self,"elements"),"length");i++){ AspectScript.i13n.call2(AspectScript.i13n.propRead(self,"area"),"addElement",[AspectScript.i13n.propRead(AspectScript.i13n.propRead(self,"elements"),i)],this); } var lines = AspectScript.i13n.call2(AspectScript.i13n.propRead(self,"area"),"removeFullLines",[],this); if(lines){ AspectScript.i13n.call2(AspectScript.i13n.propRead(AspectScript.i13n.propRead(self,"tetris"),"stats"),"setLines",[AspectScript.i13n.call2(AspectScript.i13n.propRead(AspectScript.i13n.propRead(self,"tetris"),"stats"),"getLines",[],this) + lines],this); AspectScript.i13n.call2(AspectScript.i13n.propRead(AspectScript.i13n.propRead(self,"tetris"),"stats"),"setScore",[AspectScript.i13n.call2(AspectScript.i13n.propRead(AspectScript.i13n.propRead(self,"tetris"),"stats"),"getScore",[],this) + (1000 * AspectScript.i13n.call2(AspectScript.i13n.propRead(AspectScript.i13n.propRead(self,"tetris"),"stats"),"getLevel",[],this) * lines)],this); } AspectScript.i13n.call2(self,"reset",[],this); if(AspectScript.i13n.call2(self,"mayPlace",[],this)){ AspectScript.i13n.call2(self,"place",[],this); } else { AspectScript.i13n.call2(AspectScript.i13n.propRead(self,"tetris"),"gameOver",[],this); } } } }})})); AspectScript.i13n.propWrite(this,"stop",AspectScript.i13n.wrap(function(){return (function (){ {arguments.callee = arguments.callee.wrapper;AspectScript.i13n.propWrite(this,"running",false); }})})); AspectScript.i13n.propWrite(this,"mayRotate",AspectScript.i13n.wrap(function(){return (function (){ {arguments.callee = arguments.callee.wrapper;for(var y = 0;y < AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"board"),"length");y++){ for(var x = 0;x < AspectScript.i13n.propRead(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"board"),y),"length");x++){ if(AspectScript.i13n.propRead(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"board"),y),x)){ var newY = AspectScript.i13n.call2(this,"getY",[],this) + AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"board"),"length") - 1 - x; var newX = AspectScript.i13n.call2(this,"getX",[],this) + y; if(newY >= AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"area"),"y")){ return false; } if(newX < 0){ return false; } if(newX >= AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"area"),"x")){ return false; } if(AspectScript.i13n.call2(AspectScript.i13n.propRead(this,"area"),"getBlock",[newY, newX],this)){ return false; } } } } return true; }})})); AspectScript.i13n.propWrite(this,"rotate",AspectScript.i13n.wrap(function(){return (function (){ {arguments.callee = arguments.callee.wrapper;var puzzle = AspectScript.i13n.call2(this,"createEmptyPuzzle",[AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"board"),"length"), AspectScript.i13n.propRead(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"board"),0),"length")],this); for(var y = 0;y < AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"board"),"length");y++){ for(var x = 0;x < AspectScript.i13n.propRead(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"board"),y),"length");x++){ if(AspectScript.i13n.propRead(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"board"),y),x)){ var newY = AspectScript.i13n.propRead(puzzle,"length") - 1 - x; var newX = y; var el = AspectScript.i13n.propRead(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"board"),y),x); var moveY = newY - y; var moveX = newX - x; AspectScript.i13n.propWrite(AspectScript.i13n.propRead(el,"style"),"left",AspectScript.i13n.propRead(el,"offsetLeft") + (moveX * AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"area"),"unit")) + "px"); AspectScript.i13n.propWrite(AspectScript.i13n.propRead(el,"style"),"top",AspectScript.i13n.propRead(el,"offsetTop") + (moveY * AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"area"),"unit")) + "px"); AspectScript.i13n.propWrite(AspectScript.i13n.propRead(puzzle,newY),newX,el); } } } AspectScript.i13n.propWrite(this,"board",puzzle); }})})); AspectScript.i13n.propWrite(this,"mayMoveDown",AspectScript.i13n.wrap(function(){return (function (){ {arguments.callee = arguments.callee.wrapper;for(var y = 0;y < AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"board"),"length");y++){ for(var x = 0;x < AspectScript.i13n.propRead(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"board"),y),"length");x++){ if(AspectScript.i13n.propRead(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"board"),y),x)){ if(AspectScript.i13n.call2(this,"getY",[],this) + y + 1 >= AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"area"),"y")){ AspectScript.i13n.propWrite(this,"stopped",true); return false; } if(AspectScript.i13n.call2(AspectScript.i13n.propRead(this,"area"),"getBlock",[AspectScript.i13n.call2(this,"getY",[],this) + y + 1, AspectScript.i13n.call2(this,"getX",[],this) + x],this)){ AspectScript.i13n.propWrite(this,"stopped",true); return false; } } } } return true; }})})); AspectScript.i13n.propWrite(this,"moveDown",AspectScript.i13n.wrap(function(){return (function (){ {arguments.callee = arguments.callee.wrapper;for(var i = 0;i < AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"elements"),"length");i++){ AspectScript.i13n.propWrite(AspectScript.i13n.propRead(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"elements"),i),"style"),"top",AspectScript.i13n.propRead(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"elements"),i),"offsetTop") + AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"area"),"unit") + "px"); } AspectScript.i13n.propIncr(this,"y",1,true); }})})); AspectScript.i13n.propWrite(this,"mayMoveLeft",AspectScript.i13n.wrap(function(){return (function (){ {arguments.callee = arguments.callee.wrapper;for(var y = 0;y < AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"board"),"length");y++){ for(var x = 0;x < AspectScript.i13n.propRead(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"board"),y),"length");x++){ if(AspectScript.i13n.propRead(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"board"),y),x)){ if(AspectScript.i13n.call2(this,"getX",[],this) + x - 1 < 0){ return false; } if(AspectScript.i13n.call2(AspectScript.i13n.propRead(this,"area"),"getBlock",[AspectScript.i13n.call2(this,"getY",[],this) + y, AspectScript.i13n.call2(this,"getX",[],this) + x - 1],this)){ return false; } } } } return true; }})})); AspectScript.i13n.propWrite(this,"moveLeft",AspectScript.i13n.wrap(function(){return (function (){ {arguments.callee = arguments.callee.wrapper;for(var i = 0;i < AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"elements"),"length");i++){ AspectScript.i13n.propWrite(AspectScript.i13n.propRead(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"elements"),i),"style"),"left",AspectScript.i13n.propRead(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"elements"),i),"offsetLeft") - AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"area"),"unit") + "px"); } AspectScript.i13n.propIncr(this,"x",-1,true); }})})); AspectScript.i13n.propWrite(this,"mayMoveRight",AspectScript.i13n.wrap(function(){return (function (){ {arguments.callee = arguments.callee.wrapper;for(var y = 0;y < AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"board"),"length");y++){ for(var x = 0;x < AspectScript.i13n.propRead(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"board"),y),"length");x++){ if(AspectScript.i13n.propRead(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"board"),y),x)){ if(AspectScript.i13n.call2(this,"getX",[],this) + x + 1 >= AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"area"),"x")){ return false; } if(AspectScript.i13n.call2(AspectScript.i13n.propRead(this,"area"),"getBlock",[AspectScript.i13n.call2(this,"getY",[],this) + y, AspectScript.i13n.call2(this,"getX",[],this) + x + 1],this)){ return false; } } } } return true; }})})); AspectScript.i13n.propWrite(this,"moveRight",AspectScript.i13n.wrap(function(){return (function (){ {arguments.callee = arguments.callee.wrapper;for(var i = 0;i < AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"elements"),"length");i++){ AspectScript.i13n.propWrite(AspectScript.i13n.propRead(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"elements"),i),"style"),"left",AspectScript.i13n.propRead(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"elements"),i),"offsetLeft") + AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"area"),"unit") + "px"); } AspectScript.i13n.propIncr(this,"x",1,true); }})})); }})}); var random = AspectScript.i13n.wrap(function(){return (function random(i){ {var random = arguments.callee = arguments.callee.wrapper;return AspectScript.i13n.call2(AspectScript.i13n.propRead(AspectScript.globalObject,"Math"),"floor",[AspectScript.i13n.call2(AspectScript.i13n.propRead(AspectScript.globalObject,"Math"),"random",[],this) * i],this); }})}); var Highscores = AspectScript.i13n.wrap(function(){return (function Highscores(maxscores){ {var Highscores = arguments.callee = arguments.callee.wrapper;var Score = AspectScript.i13n.wrap(function(){return (function Score(name,score){ {var Score = arguments.callee = arguments.callee.wrapper;AspectScript.i13n.propWrite(this,"name",name); AspectScript.i13n.propWrite(this,"score",score); }})}); AspectScript.i13n.propWrite(this,"maxscores",maxscores); AspectScript.i13n.propWrite(this,"scores",AspectScript.i13n.creation4([])); AspectScript.i13n.propWrite(this,"load",AspectScript.i13n.wrap(function(){return (function (){ {arguments.callee = arguments.callee.wrapper;var cookie = AspectScript.i13n.creation(0,Cookie,[]); var s = AspectScript.i13n.call2(cookie,"get",["tetris-highscores"],this); AspectScript.i13n.propWrite(this,"scores",AspectScript.i13n.creation4([])); if(AspectScript.i13n.propRead(s,"length")){ var scores = AspectScript.i13n.call2(s,"split",["|"],this); for(var i = 0;i < AspectScript.i13n.propRead(scores,"length");++i){ var a = AspectScript.i13n.call2(AspectScript.i13n.propRead(scores,i),"split",[":"],this); AspectScript.i13n.call2(AspectScript.i13n.propRead(this,"scores"),"push",[AspectScript.i13n.creation(2,Score,[AspectScript.i13n.propRead(a,0), AspectScript.i13n.call(AspectScript.globalObject,AspectScript.i13n.propRead(AspectScript.globalObject,"Number"),[AspectScript.i13n.propRead(a,1)],this)])],this); } } }})})); AspectScript.i13n.propWrite(this,"save",AspectScript.i13n.wrap(function(){return (function (){ {arguments.callee = arguments.callee.wrapper;var cookie = AspectScript.i13n.creation(0,Cookie,[]); var a = AspectScript.i13n.creation4([]); for(var i = 0;i < AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"scores"),"length");++i){ AspectScript.i13n.call2(a,"push",[AspectScript.i13n.propRead(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"scores"),i),"name") + ":" + AspectScript.i13n.propRead(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"scores"),i),"score")],this); } var s = AspectScript.i13n.call2(a,"join",["|"],this); AspectScript.i13n.call2(cookie,"set",["tetris-highscores", s, 3600 * 24 * 1000],this); }})})); AspectScript.i13n.propWrite(this,"mayAdd",AspectScript.i13n.wrap(function(){return (function (score){ {arguments.callee = arguments.callee.wrapper;if(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"scores"),"length") < AspectScript.i13n.propRead(this,"maxscores")){ return true; } for(var i = AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"scores"),"length") - 1;i >= 0;--i){ if(AspectScript.i13n.propRead(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"scores"),i),"score") < score){ return true; } } return false; }})})); AspectScript.i13n.propWrite(this,"add",AspectScript.i13n.wrap(function(){return (function (name,score){ {arguments.callee = arguments.callee.wrapper;name = AspectScript.i13n.call2(name,"replace",[/[;=:|]/g, "?"],this); name = AspectScript.i13n.call2(AspectScript.i13n.call2(name,"replace",[//g, ">"],this); if(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"scores"),"length") < AspectScript.i13n.propRead(this,"maxscores")){ AspectScript.i13n.call2(AspectScript.i13n.propRead(this,"scores"),"push",[AspectScript.i13n.creation(2,Score,[name, score])],this); } else { for(var i = AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"scores"),"length") - 1;i >= 0;--i){ if(AspectScript.i13n.propRead(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"scores"),i),"score") < score){ AspectScript.i13n.call2(AspectScript.i13n.propRead(this,"scores"),"removeByIndex",[i],this); AspectScript.i13n.call2(AspectScript.i13n.propRead(this,"scores"),"push",[AspectScript.i13n.creation(2,Score,[name, score])],this); break } } } AspectScript.i13n.call2(this,"sort",[],this); AspectScript.i13n.call2(this,"save",[],this); }})})); AspectScript.i13n.propWrite(this,"getScores",AspectScript.i13n.wrap(function(){return (function (){ {arguments.callee = arguments.callee.wrapper;return AspectScript.i13n.propRead(this,"scores"); }})})); AspectScript.i13n.propWrite(this,"toHtml",AspectScript.i13n.wrap(function(){return (function (){ {arguments.callee = arguments.callee.wrapper;var s = ''; for(var i = 0;i < AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"scores"),"length");++i){ s += AspectScript.i13n.call2('',"format",[i + 1, AspectScript.i13n.propRead(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"scores"),i),"name"), AspectScript.i13n.propRead(AspectScript.i13n.propRead(AspectScript.i13n.propRead(this,"scores"),i),"score")],this); } s += '
NameScore
?.??
'; return s; }})})); AspectScript.i13n.propWrite(this,"sort",AspectScript.i13n.wrap(function(){return (function (){ {arguments.callee = arguments.callee.wrapper;var scores = AspectScript.i13n.propRead(this,"scores"); var len = AspectScript.i13n.propRead(scores,"length"); AspectScript.i13n.propWrite(this,"scores",AspectScript.i13n.creation4([])); for(var i = 0;i < len;++i){ var el = null,index = null; for(var j = 0;j < AspectScript.i13n.propRead(scores,"length");++j){ if(!el || (AspectScript.i13n.propRead(AspectScript.i13n.propRead(scores,j),"score") > AspectScript.i13n.propRead(el,"score"))){ el = AspectScript.i13n.propRead(scores,j); index = j; } } AspectScript.i13n.call2(scores,"removeByIndex",[index],this); AspectScript.i13n.call2(AspectScript.i13n.propRead(this,"scores"),"push",[el],this); } }})})); AspectScript.i13n.call2(this,"load",[],this); }})}); var Cookie = AspectScript.i13n.wrap(function(){return (function Cookie(){ {var Cookie = arguments.callee = arguments.callee.wrapper;AspectScript.i13n.propWrite(this,"get",AspectScript.i13n.wrap(function(){return (function (name){ {arguments.callee = arguments.callee.wrapper;var cookies = AspectScript.i13n.call2(AspectScript.i13n.propRead(AspectScript.i13n.propRead(AspectScript.globalObject,"document"),"cookie"),"split",[";"],this); for(var i = 0;i < AspectScript.i13n.propRead(cookies,"length");++i){ var a = AspectScript.i13n.call2(AspectScript.i13n.propRead(cookies,i),"split",["="],this); if(AspectScript.i13n.propRead(a,"length") == 2){ AspectScript.i13n.propWrite(a,0,AspectScript.i13n.call2(AspectScript.i13n.propRead(a,0),"trim",[],this)); AspectScript.i13n.propWrite(a,1,AspectScript.i13n.call2(AspectScript.i13n.propRead(a,1),"trim",[],this)); if(AspectScript.i13n.propRead(a,0) == name){ return AspectScript.i13n.call(AspectScript.globalObject,AspectScript.i13n.propRead(AspectScript.globalObject,"unescape"),[AspectScript.i13n.propRead(a,1)],this); } } } return ""; }})})); AspectScript.i13n.propWrite(this,"set",AspectScript.i13n.wrap(function(){return (function (name,value,seconds,path,domain,secure){ {arguments.callee = arguments.callee.wrapper;AspectScript.i13n.call2(this,"del",[name],this); if(!path)path = '/'; var cookie = (name + "=" + AspectScript.i13n.call(AspectScript.globalObject,AspectScript.i13n.propRead(AspectScript.globalObject,"escape"),[value],this)); if(seconds){ var date = AspectScript.i13n.creation(1,AspectScript.i13n.propRead(AspectScript.globalObject,"Date"),[AspectScript.i13n.call2(AspectScript.i13n.creation(0,AspectScript.i13n.propRead(AspectScript.globalObject,"Date"),[]),"getTime",[],this) + seconds * 1000]); cookie += ("; expires=" + AspectScript.i13n.call2(date,"toGMTString",[],this)); } cookie += (((path)?("; path=" + path):(""))); cookie += (((domain)?("; domain=" + domain):(""))); cookie += (((secure)?("; secure"):(""))); AspectScript.i13n.propWrite(AspectScript.i13n.propRead(AspectScript.globalObject,"document"),"cookie",cookie); }})})); AspectScript.i13n.propWrite(this,"del",AspectScript.i13n.wrap(function(){return (function (name){ {arguments.callee = arguments.callee.wrapper;AspectScript.i13n.propWrite(AspectScript.i13n.propRead(AspectScript.globalObject,"document"),"cookie",name + "=; expires=Thu, 01-Jan-70 00:00:01 GMT"); }})})); }})}); var self = this; AspectScript.i13n.propWrite(this,"stats",AspectScript.i13n.creation(0,Stats,[])); AspectScript.i13n.propWrite(this,"puzzle",null); AspectScript.i13n.propWrite(this,"area",null); AspectScript.i13n.propWrite(this,"unit",20); AspectScript.i13n.propWrite(this,"areaX",20); AspectScript.i13n.propWrite(this,"areaY",20); AspectScript.i13n.propWrite(this,"highscores",AspectScript.i13n.creation(1,Highscores,[10])); AspectScript.i13n.propWrite(this,"start",AspectScript.i13n.wrap(function(){return (function (){ {arguments.callee = arguments.callee.wrapper;AspectScript.i13n.call2(self,"reset",[],this); AspectScript.i13n.call2(AspectScript.i13n.propRead(self,"stats"),"start",[],this); AspectScript.i13n.propWrite(AspectScript.i13n.propRead(AspectScript.i13n.call2(AspectScript.i13n.propRead(AspectScript.globalObject,"document"),"getElementById",["tetris-nextpuzzle"],this),"style"),"display","block"); AspectScript.i13n.propWrite(AspectScript.i13n.propRead(AspectScript.i13n.call2(AspectScript.i13n.propRead(AspectScript.globalObject,"document"),"getElementById",["tetris-keys"],this),"style"),"display","none"); AspectScript.i13n.propWrite(self,"area",AspectScript.i13n.creation(4,Area,[AspectScript.i13n.propRead(self,"unit"), AspectScript.i13n.propRead(self,"areaX"), AspectScript.i13n.propRead(self,"areaY"), "tetris-area"])); AspectScript.i13n.propWrite(self,"puzzle",AspectScript.i13n.creation(2,Puzzle,[self, AspectScript.i13n.propRead(self,"area")])); if(AspectScript.i13n.call2(AspectScript.i13n.propRead(self,"puzzle"),"mayPlace",[],this)){ AspectScript.i13n.call2(AspectScript.i13n.propRead(self,"puzzle"),"place",[],this); } else { AspectScript.i13n.call2(self,"gameOver",[],this); } }})})); AspectScript.i13n.propWrite(this,"reset",AspectScript.i13n.wrap(function(){return (function (){ {arguments.callee = arguments.callee.wrapper;if(AspectScript.i13n.propRead(self,"puzzle")){ AspectScript.i13n.call2(AspectScript.i13n.propRead(self,"puzzle"),"destroy",[],this); AspectScript.i13n.propWrite(self,"puzzle",null); } if(AspectScript.i13n.propRead(self,"area")){ AspectScript.i13n.call2(AspectScript.i13n.propRead(self,"area"),"destroy",[],this); AspectScript.i13n.propWrite(self,"area",null); } AspectScript.i13n.propWrite(AspectScript.i13n.propRead(AspectScript.i13n.call2(AspectScript.i13n.propRead(AspectScript.globalObject,"document"),"getElementById",["tetris-gameover"],this),"style"),"display","none"); AspectScript.i13n.propWrite(AspectScript.i13n.propRead(AspectScript.i13n.call2(AspectScript.i13n.propRead(AspectScript.globalObject,"document"),"getElementById",["tetris-nextpuzzle"],this),"style"),"display","none"); AspectScript.i13n.propWrite(AspectScript.i13n.propRead(AspectScript.i13n.call2(AspectScript.i13n.propRead(AspectScript.globalObject,"document"),"getElementById",["tetris-keys"],this),"style"),"display","block"); AspectScript.i13n.call2(AspectScript.i13n.propRead(self,"stats"),"reset",[],this); }})})); AspectScript.i13n.propWrite(this,"gameOver",AspectScript.i13n.wrap(function(){return (function (){ {arguments.callee = arguments.callee.wrapper;AspectScript.i13n.call2(AspectScript.i13n.propRead(self,"stats"),"stop",[],this); AspectScript.i13n.call2(AspectScript.i13n.propRead(self,"puzzle"),"stop",[],this); AspectScript.i13n.propWrite(AspectScript.i13n.propRead(AspectScript.i13n.call2(AspectScript.i13n.propRead(AspectScript.globalObject,"document"),"getElementById",["tetris-nextpuzzle"],this),"style"),"display","none"); AspectScript.i13n.propWrite(AspectScript.i13n.propRead(AspectScript.i13n.call2(AspectScript.i13n.propRead(AspectScript.globalObject,"document"),"getElementById",["tetris-gameover"],this),"style"),"display","block"); if(AspectScript.i13n.call2(AspectScript.i13n.propRead(this,"highscores"),"mayAdd",[AspectScript.i13n.call2(AspectScript.i13n.propRead(this,"stats"),"getScore",[],this)],this)){ var name = AspectScript.i13n.call(AspectScript.globalObject,AspectScript.i13n.propRead(AspectScript.globalObject,"prompt"),["Game Over !\nEnter your name:", ""],this); if(name && AspectScript.i13n.propRead(AspectScript.i13n.call2(name,"trim",[],this),"length")){ AspectScript.i13n.call2(AspectScript.i13n.propRead(this,"highscores"),"add",[name, AspectScript.i13n.call2(AspectScript.i13n.propRead(this,"stats"),"getScore",[],this)],this); } } }})})); AspectScript.i13n.propWrite(this,"up",AspectScript.i13n.wrap(function(){return (function (){ {arguments.callee = arguments.callee.wrapper;if(AspectScript.i13n.propRead(self,"puzzle") && AspectScript.i13n.call2(AspectScript.i13n.propRead(self,"puzzle"),"isRunning",[],this) && !AspectScript.i13n.call2(AspectScript.i13n.propRead(self,"puzzle"),"isStopped",[],this)){ if(AspectScript.i13n.call2(AspectScript.i13n.propRead(self,"puzzle"),"mayRotate",[],this)){ AspectScript.i13n.call2(AspectScript.i13n.propRead(self,"puzzle"),"rotate",[],this); AspectScript.i13n.call2(AspectScript.i13n.propRead(self,"stats"),"setActions",[AspectScript.i13n.call2(AspectScript.i13n.propRead(self,"stats"),"getActions",[],this) + 1],this); } } }})})); AspectScript.i13n.propWrite(this,"down",AspectScript.i13n.wrap(function(){return (function (){ {arguments.callee = arguments.callee.wrapper;if(AspectScript.i13n.propRead(self,"puzzle") && AspectScript.i13n.call2(AspectScript.i13n.propRead(self,"puzzle"),"isRunning",[],this) && !AspectScript.i13n.call2(AspectScript.i13n.propRead(self,"puzzle"),"isStopped",[],this)){ if(AspectScript.i13n.call2(AspectScript.i13n.propRead(self,"puzzle"),"mayMoveDown",[],this)){ AspectScript.i13n.call2(AspectScript.i13n.propRead(self,"stats"),"setScore",[AspectScript.i13n.call2(AspectScript.i13n.propRead(self,"stats"),"getScore",[],this) + 5 + AspectScript.i13n.call2(AspectScript.i13n.propRead(self,"stats"),"getLevel",[],this)],this); AspectScript.i13n.call2(AspectScript.i13n.propRead(self,"puzzle"),"moveDown",[],this); AspectScript.i13n.call2(AspectScript.i13n.propRead(self,"stats"),"setActions",[AspectScript.i13n.call2(AspectScript.i13n.propRead(self,"stats"),"getActions",[],this) + 1],this); } } }})})); AspectScript.i13n.propWrite(this,"left",AspectScript.i13n.wrap(function(){return (function (){ {arguments.callee = arguments.callee.wrapper;if(AspectScript.i13n.propRead(self,"puzzle") && AspectScript.i13n.call2(AspectScript.i13n.propRead(self,"puzzle"),"isRunning",[],this) && !AspectScript.i13n.call2(AspectScript.i13n.propRead(self,"puzzle"),"isStopped",[],this)){ if(AspectScript.i13n.call2(AspectScript.i13n.propRead(self,"puzzle"),"mayMoveLeft",[],this)){ AspectScript.i13n.call2(AspectScript.i13n.propRead(self,"puzzle"),"moveLeft",[],this); AspectScript.i13n.call2(AspectScript.i13n.propRead(self,"stats"),"setActions",[AspectScript.i13n.call2(AspectScript.i13n.propRead(self,"stats"),"getActions",[],this) + 1],this); } } }})})); AspectScript.i13n.propWrite(this,"right",AspectScript.i13n.wrap(function(){return (function (){ {arguments.callee = arguments.callee.wrapper;if(AspectScript.i13n.propRead(self,"puzzle") && AspectScript.i13n.call2(AspectScript.i13n.propRead(self,"puzzle"),"isRunning",[],this) && !AspectScript.i13n.call2(AspectScript.i13n.propRead(self,"puzzle"),"isStopped",[],this)){ if(AspectScript.i13n.call2(AspectScript.i13n.propRead(self,"puzzle"),"mayMoveRight",[],this)){ AspectScript.i13n.call2(AspectScript.i13n.propRead(self,"puzzle"),"moveRight",[],this); AspectScript.i13n.call2(AspectScript.i13n.propRead(self,"stats"),"setActions",[AspectScript.i13n.call2(AspectScript.i13n.propRead(self,"stats"),"getActions",[],this) + 1],this); } } }})})); AspectScript.i13n.propWrite(this,"space",AspectScript.i13n.wrap(function(){return (function (){ {arguments.callee = arguments.callee.wrapper;if(AspectScript.i13n.propRead(self,"puzzle") && AspectScript.i13n.call2(AspectScript.i13n.propRead(self,"puzzle"),"isRunning",[],this) && !AspectScript.i13n.call2(AspectScript.i13n.propRead(self,"puzzle"),"isStopped",[],this)){ AspectScript.i13n.call2(AspectScript.i13n.propRead(self,"puzzle"),"stop",[],this); AspectScript.i13n.call2(AspectScript.i13n.propRead(self,"puzzle"),"forceMoveDown",[],this); } }})})); var helpwindow = AspectScript.i13n.creation(1,Window,["tetris-help"]); var highscores = AspectScript.i13n.creation(1,Window,["tetris-highscores"]); AspectScript.i13n.propWrite(AspectScript.i13n.call2(AspectScript.i13n.propRead(AspectScript.globalObject,"document"),"getElementById",["tetris-menu-start"],this),"onclick",AspectScript.i13n.wrap(function(){return (function (){ {arguments.callee = arguments.callee.wrapper;AspectScript.i13n.call2(helpwindow,"close",[],this); AspectScript.i13n.call2(highscores,"close",[],this); AspectScript.i13n.call2(self,"start",[],this); AspectScript.i13n.call2(this,"blur",[],this); }})})); AspectScript.i13n.propWrite(AspectScript.i13n.call2(AspectScript.i13n.propRead(AspectScript.globalObject,"document"),"getElementById",["tetris-menu-reset"],this),"onclick",AspectScript.i13n.wrap(function(){return (function (){ {arguments.callee = arguments.callee.wrapper;AspectScript.i13n.call2(helpwindow,"close",[],this); AspectScript.i13n.call2(highscores,"close",[],this); AspectScript.i13n.call2(self,"reset",[],this); AspectScript.i13n.call2(this,"blur",[],this); }})})); AspectScript.i13n.propWrite(AspectScript.i13n.call2(AspectScript.i13n.propRead(AspectScript.globalObject,"document"),"getElementById",["tetris-menu-help"],this),"onclick",AspectScript.i13n.wrap(function(){return (function (){ {arguments.callee = arguments.callee.wrapper;AspectScript.i13n.call2(highscores,"close",[],this); AspectScript.i13n.call2(helpwindow,"activate",[],this); AspectScript.i13n.call2(this,"blur",[],this); }})})); AspectScript.i13n.propWrite(AspectScript.i13n.call2(AspectScript.i13n.propRead(AspectScript.globalObject,"document"),"getElementById",["tetris-help-close"],this),"onclick",AspectScript.i13n.propRead(helpwindow,"close")); AspectScript.i13n.propWrite(AspectScript.i13n.call2(AspectScript.i13n.propRead(AspectScript.globalObject,"document"),"getElementById",["tetris-menu-highscores"],this),"onclick",AspectScript.i13n.wrap(function(){return (function (){ {arguments.callee = arguments.callee.wrapper;AspectScript.i13n.call2(helpwindow,"close",[],this); AspectScript.i13n.propWrite(AspectScript.i13n.call2(AspectScript.i13n.propRead(AspectScript.globalObject,"document"),"getElementById",["tetris-highscores-content"],this),"innerHTML",AspectScript.i13n.call2(AspectScript.i13n.propRead(self,"highscores"),"toHtml",[],this)); AspectScript.i13n.call2(highscores,"activate",[],this); AspectScript.i13n.call2(this,"blur",[],this); }})})); AspectScript.i13n.propWrite(AspectScript.i13n.call2(AspectScript.i13n.propRead(AspectScript.globalObject,"document"),"getElementById",["tetris-highscores-close"],this),"onclick",AspectScript.i13n.propRead(highscores,"close")); var keyboard = AspectScript.i13n.creation(0,Keyboard,[]); AspectScript.i13n.call2(keyboard,"set",[AspectScript.i13n.propRead(keyboard,"n"), AspectScript.i13n.propRead(this,"start")],this); AspectScript.i13n.call2(keyboard,"set",[AspectScript.i13n.propRead(keyboard,"r"), AspectScript.i13n.propRead(this,"reset")],this); AspectScript.i13n.call2(keyboard,"set",[AspectScript.i13n.propRead(keyboard,"up"), AspectScript.i13n.propRead(this,"up")],this); AspectScript.i13n.call2(keyboard,"set",[AspectScript.i13n.propRead(keyboard,"down"), AspectScript.i13n.propRead(this,"down")],this); AspectScript.i13n.call2(keyboard,"set",[AspectScript.i13n.propRead(keyboard,"left"), AspectScript.i13n.propRead(this,"left")],this); AspectScript.i13n.call2(keyboard,"set",[AspectScript.i13n.propRead(keyboard,"right"), AspectScript.i13n.propRead(this,"right")],this); AspectScript.i13n.call2(keyboard,"set",[AspectScript.i13n.propRead(keyboard,"space"), AspectScript.i13n.propRead(this,"space")],this); AspectScript.i13n.propWrite(AspectScript.i13n.propRead(AspectScript.globalObject,"document"),"onkeydown",AspectScript.i13n.propRead(keyboard,"event")); }})}); if(!AspectScript.i13n.propRead(AspectScript.i13n.propRead(AspectScript.i13n.propRead(AspectScript.globalObject,"String"),"prototype"),"trim")){ AspectScript.i13n.propWrite(AspectScript.i13n.propRead(AspectScript.i13n.propRead(AspectScript.globalObject,"String"),"prototype"),"trim",AspectScript.i13n.wrap(function(){return (function (){ {arguments.callee = arguments.callee.wrapper;return AspectScript.i13n.call2(this,"replace",[/^\s*|\s*$/g, ""],this); }})})); } if(!AspectScript.i13n.propRead(AspectScript.i13n.propRead(AspectScript.i13n.propRead(AspectScript.globalObject,"Array"),"prototype"),"removeByIndex")){ AspectScript.i13n.propWrite(AspectScript.i13n.propRead(AspectScript.i13n.propRead(AspectScript.globalObject,"Array"),"prototype"),"removeByIndex",AspectScript.i13n.wrap(function(){return (function (index){ {arguments.callee = arguments.callee.wrapper;AspectScript.i13n.call2(this,"splice",[index, 1],this); }})})); } if(!AspectScript.i13n.propRead(AspectScript.i13n.propRead(AspectScript.i13n.propRead(AspectScript.globalObject,"String"),"prototype"),"format")){ AspectScript.i13n.propWrite(AspectScript.i13n.propRead(AspectScript.i13n.propRead(AspectScript.globalObject,"String"),"prototype"),"format",AspectScript.i13n.wrap(function(){return (function (){ {arguments.callee = arguments.callee.wrapper;if(!AspectScript.i13n.propRead(arguments,"length")){ throw "String.format() failed, no arguments passed, this = " + this } var tokens = AspectScript.i13n.call2(this,"split",["?"],this); if(AspectScript.i13n.propRead(arguments,"length") != (AspectScript.i13n.propRead(tokens,"length") - 1)){ throw "String.format() failed, tokens != arguments, this = " + this } var s = AspectScript.i13n.propRead(tokens,0); for(var i = 0;i < AspectScript.i13n.propRead(arguments,"length");++i){ s += (AspectScript.i13n.propRead(arguments,i) + AspectScript.i13n.propRead(tokens,i + 1)); } return s; }})})); }