0

好的,我到处搜索,但没有找到对我特别有用的东西。我正在尝试使用纯 JavaScript 编写 BreakOut 游戏。作为初学者,我经历了起起落落,但我成功地展示和控制了球拍和球拍。但我似乎太愚蠢了,无法建造砖墙让球摧毁。我正在处理更多的 .js 文件,因此代码不会被塞入一个文件中。

砖块应在 BreakOutGame.js(主文件)中初始化,但砖块的绘制需要在文件 Brick.js 中完成

这是 BreakOutGame.Js 中的代码

function privateInitContent(){
var bricks = [];
for (var r = 0; r < BRICK_ROWS; r++){
 for (var c = 0; c < BRICK_COLUMNS; c++){
  var brick[r][c] = new Brick(privateContext, BRICK_XPOS, BRICK_YPOS, BRICK_COLOR, BRICK_WIDTH, BRICK_HEIGHT);
   bricks[r][c].push(brick);
  }
 }
}

这似乎不起作用。这是 Brick.js 文件的内容:

var Brick = function(context, xPos, yPos, color, width, height) {

this.context = context;

this.BrickXPos = xPos;
this.BrickYPos = yPos;
this.BrickWidth = width;
this.BrickHeight = height;

this.BrickColor = color;

}

Brick.prototype.draw = function() {

this.context.fillStyle = this.color;
 this.context.fillRect(this.BrickXPos,this.BrickYPos,this.BrickWidth,this.BrickHeight);


}

谁能给我一个想法?我真的需要这个:/

4

0 回答 0