使用OOP的JavaScript小游戏

使用OOP的JavaScript小游戏,javascript,Javascript,考虑以下代码: window.requestAnimFrame=(函数(回调){ 返回window.requestAnimationFrame | | | window.webkitRequestAnimationFrame | | | window.mozRequestAnimationFrame | | window.oRequestAnimationFrame | | window.msRequestAnimationFrame|| 函数(回调){ 设置超时(回调,1000/60); }

考虑以下代码:

window.requestAnimFrame=(函数(回调){
返回window.requestAnimationFrame | | | window.webkitRequestAnimationFrame | | | window.mozRequestAnimationFrame | | window.oRequestAnimationFrame | | window.msRequestAnimationFrame||
函数(回调){
设置超时(回调,1000/60);
};
})();
(功能(){
var FPS=60;
var默认值_宽度=600;
功能绘图板(){
this.dimensions=drawBoard.defaultDimensions;
this.config=drawBoard.config;
this.init();
}
drawBoard.config={
加速度:0.001,
初始反弹速度:12,
最小跳跃高度:35,
}
drawBoard.defaultDimensions={
宽度:默认宽度,
身高:150
};
drawBoard.prototype={
init:function(){
这是调整尺寸();
this.containerell=document.getElementById('canvasBox');
this.canvas=createCanvas(this.containeerl,this.dimensions.WIDTH,this.dimensions.HEIGHT,0);
this.canvasCtx=this.canvas.getContext('2d');
this.canvasCtx.fillStyle='#f7f7f7';
this.canvasCtx.fill();
},
调整维度:函数(){
this.canvas.width=this.dimensions.width;
this.canvas.height=this.dimensions.height;
}
}
函数createCanvas(容器、宽度、高度、opt_类名称){
var canvas=document.createElement('canvas');
canvas.id=“myCanvas”;
画布宽度=宽度;
canvas.height=高度;
container.appendChild(画布);
返回画布
}
}());

新的抽油板()首先,在定义函数运行器之后,直接检查他们在做什么。他们正在将其添加到窗口对象中。这就是让他们直接在底部称呼它的原因

尝试从以下内容开始:

function drawBoard(){
    this.dimensions = drawBoard.defaultDimensions;
    this.config = drawBoard.config;
    this.init();
}

window['drawBoard'] = drawBoard;

好的,太好了,我一直在玩弄它。在某一点上,我的代码中也包含了这一点。我不熟悉javascript,但我喜欢编写示例代码的模块化风格。我很感激你给我指点方向。试了一下,成功了。这么简单的事情。。。再次感谢你的帮助。