-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrick.js
executable file
·6 lines (6 loc) · 2.32 KB
/
brick.js
1
2
3
4
5
6
var bricks=[],num_dead_bricks=0;function Brick(f,a,d,b,e){this.color=f;this.x=a;this.y=d;this.height=e;this.width=b;"red"===this.color?this.value=100:"yellow"===this.color&&(this.value=200)}Brick.prototype.draw=function(){ctx.save();ctx.fillStyle=this.color;ctx.strokeStyle="indigo";ctx.fillRect(this.x,this.y,this.width,this.height);ctx.strokeRect(this.x+1,this.y+1,this.width-2,this.height-2);ctx.restore()};
Brick.prototype.remove=function(){ctx.clearRect(this.x,this.y,this.width,this.height);score+=this.value;console.log("brick value = "+this.value+" score = "+score)};function SpeedBrick(f,a,d,b,e,g){Brick.call(this,f,a,d,b,e);this.effect=g;"green"===this.color?this.value=400:"orange"===this.color&&(this.value=50)}SpeedBrick.prototype=new Brick;SpeedBrick.prototype.constructor=SpeedBrick;
SpeedBrick.prototype.remove=function(){Brick.prototype.remove.call(this);"fast"===this.effect?(clearInterval(intervalId),speed=speed_fast,intervalId=setInterval(moveBall,speed)):"slow"===this.effect&&(clearInterval(intervalId),speed=speed_slow,intervalId=setInterval(moveBall,speed))};function SizeBrick(f,a,d,b,e,g){Brick.call(this,f,a,d,b,e);this.effect=g;"blue"===this.color?this.value=50:"purple"===this.color&&(this.value=300)}SizeBrick.prototype=new Brick;SizeBrick.prototype.constructor=SizeBrick;
SizeBrick.prototype.remove=function(){Brick.prototype.remove.call(this);"expand"===this.effect&&100>=paddle_width?(paddle_width*=1.5,half_paddle_width=paddle_width/2):"contract"===this.effect&&25<=paddle_width&&(paddle_width/=1.5,half_paddle_width=paddle_width/2)};function DeadBrick(f,a,d,b,e){Brick.call(this,f,a,d,b,e);this.value=0}DeadBrick.prototype=new Brick;DeadBrick.prototype.constructor=DeadBrick;DeadBrick.prototype.remove=function(){};
function drawBricks(f){for(var a=0,d=5,b="none",e=0;e<f.length;e++)for(var g=0;g<f[0].length;g++){var c=f[e][g];if(0!=c)if(a=40*g,d=15*e+10,1===c||2===c)1===c?b="red":2===c&&(b="yellow"),a=new Brick(b,a,d,35,10),a.draw(),bricks.push(a);else if(3===c||4===c){var h="none";3===c?(b="green",h="fast"):4===c&&(b="orange",h="slow");a=new SpeedBrick(b,a,d,35,10,h);a.draw();bricks.push(a)}else 5===c||6===c?(h="none",5===c?(b="blue",h="expand"):6===c&&(b="purple",h="contract"),a=new SizeBrick(b,a,d,35,10,h),
a.draw(),bricks.push(a)):7===c&&(b="black",a=new DeadBrick(b,a,d,35,10),a.draw(),num_dead_bricks++,bricks.push(a))}};