ruby123的gravatar头像
ruby1232015-05-08 16:15:55

html5别踩白块代码写成的“就踩白块”小游戏代码

var stage = new createjs.Stage("canvasId");
var drawView = new createjs.Container();
stage.addChild(drawView);
 var timeFn;

createjs.Ticker.setFPS(30);
createjs.Ticker.addEventListener("tick" ,stage);

function init(w,h,size){
	var view = [];
	var current = 1;

	var color1= "#"+parseInt(Math.random()*1000000);
	var b_color1 = "#"+parseInt(Math.random()*1000000);
	while(true){
	if(color1 == b_color1){
		color1= "#"+parseInt(Math.random()*1000000);
	}else break;
	}
	
	for(var n = size; n >= 0; n--){
	view[n] = new createjs.Container();
	view[n].y = (3-n)*h/4;
	var white = parseInt(Math.random()*4);
	for(var l =0; l<4; l++){
		var zfx = new drawZfx(w,h,color1,b_color1);
		zfx.x = l*w/4;
		if(white == l){
		   zfx.setType(2);
		}
		view[n].addChild(zfx);
	}
	if(n == current){
		 addCurrent(current,view,h);
	
	}
	drawView.addChild(view[n]);
	
	}

}
 var text = 0;
function addCurrent(current ,view ,h){
for(var i =0; i < 4; i++){

clickFn(i,current,view,h);
}
}
 
 function clickFn(i,current,view ,h){
 
 view[current].getChildAt(i).addEventListener("click",function(){
 
	if(view[current].getChildAt(i).getType() == 1){
	alert("游戏结束,您的成绩是:" + text.toFixed(1)+"秒点击了"+(current-1)+"次白块");
	clearInterval(timeFn);
	}else if(view[current].getChildAt(i).getType() == 2){
	  
	  if(current ==1){
	  text =0;
	  timeFn = setInterval(function(){
	  text+=0.1;
	  document.getElementById("time").innerHTML = text.toFixed(1);
	  
	  
	  },100);
	  }
	  
	  drawView.y +=h/4;
	  current++;
	  addCurrent(current,view,h);
	}
 
 });
 }
 
 init(320,440,1000);

感谢网上分享资源的大神们,对代码做了一下修改。还有很多不完善的地方如点到最下层没有提示等等。。。

希望和大家一起来讨论。html5别踩白块代码写成的“就踩白块”小游戏代码

文件名:就踩白块儿.rar,文件大小:23.184K下载
  • /
      • /就踩白块儿
        • /就踩白块儿/black&white2.css
        • /就踩白块儿/black&white2.html
        • /就踩白块儿/black&white3.js
        • /就踩白块儿/drawblack&white2.js
        • /就踩白块儿/easeljs-0.7.1.min.js
顶部客服微信二维码底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友