この記事では、JS Mini Gamesの高速ランニングソースコードについて説明し、参照のために共有されています。詳細は次のとおりです。
ゲームが実行された後、次の図が表示されます。
JavaScriptコードの一部は次のとおりです。
/**速度実行*著者:fdipzone*日付:2012-07-15* ver:1.0*/var gameimg = ['images/start.png' '、'/start_over.png ''、 'images/go_over.png'、 'images/go_over.png' '、' images/running.gif '、' image/run_start1.gif ' 'image/run_start3.gif']; var speed_obj = new speedclass(); window.onload = function(){var callback = function(){speed_obj.init(); } img_preload(gameimg、callback);} // speed classfunction speedclass(){this.levelset = [8,5,8,12]; //難易度パラメーターthis.playerlist = null; //プレーヤーリストthis.player = 0; //選択されたプレーヤーthis.level = 2; //難易度this.lock = 0; // this.isstart = 0; // this.isover = 0を開始するかどうか。 //終了するかどうか} // initspeedclass.prototype.init = function(){this.reset(); this.create_player(); this.create_event();} // resetspeedclass.prototype.reset = function(){this.player = 0; this.level = $( 'level')。value; // this.playerlist = $ _tag( 'li'、 'playerlist'); for(var i = 0; i <this.playerlist.length; i ++){this.playerlist [i] .classname = ''; } disp( 'start_btn'、 'show'、 'start_btn'); disp( 'go_btn'、 'hide'、 'go_btn'); this.lock = 0; // this.isstart = 0;のロックを解除します。 // this.isover = 0; // unover} // playerspeedclass.prototype.create_player = function(){var runway = []; var playerlist = []; for(var i = 1; i <= 8; i ++){runway [i] = '<li> <div id = "player' +(9-i) + '"> </div> </li>'; playerlist [i] = '<li>' + i + '</li>'; } $( 'runway')。innerhtml = runway.join( ''); $( 'playerlist')。innerhtml = playerlist.join( '');滑走路= null; playerlist = null;} // eventspeedclass.prototype.create_event = function(){var self = this; this.playerList = $ _tag( 'li'、 'playerlist'); for(var i = 0; i <this.playerlist.length; i ++){this.playerlist [i] .onmouseover = function(){if(this.classname!= 'on'){this.classname = 'over'; }} this.playerlist [i] .onmouseout = function(){if(this.classname!= 'on'){this.classname = ''; }} this.playerlist [i] .onclick = function(o、c){return function(){if(self.lock == 0){o.playerlist [c] .classname = 'on'; if(o.player!= 0 && o.player!= c+1){// 0に等しくなく、o.playerlist [o.player-1] .classname = ''; } o.player = c + 1; }}}}(self、i); } $( 'start_btn')。onmouseover = function(){this.classname = 'start_over_btn'; } $( 'start_btn')。onmouseout = function(){this.classname = 'start_btn'; } $( 'start_btn')。onclick = function(){if(self.player == 0){return alert( 'サポートするプレーヤーを選択してください'); } else {self.lock = 1; // locked disp( 'start_btn'、 'hide'); disp( 'go_btn'、 'show'); for(var i = 1; i <= 8; i ++){self.start(i); }}} $( 'go_btn')。onmouseover = function(){this.classname = 'go_over_btn'; } $( 'go_btn')。onmouseout = function(){this.classname = 'go_btn'; } $( 'go_btn')。onclick = function(){self.go(); }} // gamespeedclass.prototype.start = function(c){var o = $( 'player' + c); var step = 1; var self = this; var ext = 0; O.Style.MarginLeft = '62px'; // init var et = setInterval(function(){if(step <4){//ステップ1-3の準備ができているo.classname = 'run_status' + step;} else {// run if(o.classname!= 'running'){o.classname = 'running';} (self.isover == 1){clear interval(et); Math.floor()+4 +'px'; function(){if(this.isstart == 1 && this.isover == 0){var o = $( 'player' + this.player); var ext = math.floor(math.random()*3)+2; // 2-5 O.Style.MarginLeft = ParSeint(O.Style.MarginLeft) + Evert + 'PX'; } return false;} // gameoverspeedclass.prototype.gameover = function(id){id = id.replace( 'player'、 ''); var self = this; var msg = ''; if(id == this.player){msg = "おめでとうございます、あなたがサポートするプレイヤーはwon/n/n"; } else {msg = "悲しいことに、あなたがサポートするプレイヤーは勝ちませんでした、勝ったのは" + id + "select/n/n"; } if(confism(msg + 'それは再び起動しますか?')== true){setimeout(function(){self.init();}、1000); } else {return false; }}/** common function*/// get document.getElementby(id)function $(id){this.id = id; document.getElementbyId(id);} // document.getElementsByTagnameFunction $ _TAG(name、id){if(typeof(id)!= 'undefined'){return $(id).getelementsbytagname(name); } else {return document.getElementsByTagname(name); }}/* div show show and hided* @param id dom id* @paramハンドルショーまたは非表示* @param classname*/function disp(id、handle、classname){if(handle == 'show'){$(id).style.display = 'block'; } else {$(id).style.display = 'none'; } if(typeof(classname)!= 'undefined'){$(id).classname = classname; }}/* img preload* @param img画像配列がロードされる* @paramコールバックメソッド画像が正常に読み込まれた後*/function img_preload(img、callback){var onload_img = 0; var tmp_img = []; for(var i = 0、imgnum = img.length; i <imgnum; i ++){tmp_img [i] = new image(); tmp_img [i] .src = img [i]; if(tmp_img [i] .complete){onload_img ++; } else {tmp_img [i] .onload = function(){onload_img ++; }}}} var et = setInterval(function(){if(onload_img == img.length){// Callback clearInterval(et); callback(}}、200);}完全なサンプルコードをダウンロードするには、ここをクリックしてください。
この記事には、全員のJavaScriptゲームデザインの特定の参照値があると思います。