完成游戏制作教程并尝试加载我的不同jquery文件,但它们似乎无法正常工作。这是我的代码的缩写版本:
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script>
function getScripts(scripts, callback) {
var progress = 0;
var internalCallback = function () {
if (++progress == scripts.length) { callback(); }
};
scripts.forEach(function(script) { $.getScript(script, internalCallback); });
};
getScripts(["_js/ui.js", "_js/bubble.js", "_js/game.js"], function () {
function();
$(function(){
var game = new BubbleShoot.Game();
game.init();
})
});
</script>
</head>
<body>
<div id="start_game" class="dialog">
<div id="start_game_message">
<h2>Start a new game</h2>
</div>
<div class="but_start_game button">
New Game
</div>
</body>
然后我有三个非常基本的jQuery文件: ui.js
var BubbleShoot = window.BubbleShoot || {};
BubbleShoot.ui = (function($){
var ui = {
init : function(){
},
hideDialog : function(){
$(".dialog").fadeOut(300);
}
};
return ui;
})(jQuery);
bubble.js
var BubbleShoot = window.BubbleShoot || {};
BubbleShoot.Bubble = (function($){
var Bubble = function(sprite){
var that = this;
this.getSprite = function(){return sprite;};
};
Bubble.create = function(){
var sprite = $(document.createElement ("div"));
sprite.addClass("bubble");
sprite.addClass("bubble_0");
var bubble = new Bubble(sprite);
return bubble;
};
return Bubble;
})(jQuery);
和game.js
BubbleShoot.Game = (function($){
var Game = function(){
var curBubble;
this.init = function(){
$(".but_start_game").bind("click",startGame);
};
var startGame = function(){
$(".but_start_game").unbind("click");
BubbleShoot.ui.hideDialog();
curBubble = getNextBubble();
};
var getNextBubble = function(){
var bubble = BubbleShoot.Bubble.create();
bubble.getSprite().addClass("cur_bubble");
$("#board").append(bubble.getSprite());
return bubble;
};
};
return Game;
})(jQuery);
我已尝试单独加载脚本或将其加载到文件正文中,但它们似乎无法正常工作。
提前致谢。