ruby123的gravatar头像
ruby123 2015-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
最代码最近下载分享源代码列表最近下载
刚刚好h  LV1 2022年5月23日
卟linlin  LV1 2021年5月26日
18162794490  LV1 2020年12月26日
老张家的崽儿  LV1 2020年6月22日
18326158829  LV1 2020年5月21日
谭鬼鬼  LV48 2019年10月10日
crownli  LV1 2019年7月17日
f2486976951  LV2 2019年6月3日
3151667385  LV1 2019年5月9日
翱翔子  LV10 2019年4月27日
最代码最近浏览分享源代码列表最近浏览
微信网友_6271348989300736 2022年12月21日
暂无贡献等级
157226747  LV16 2022年11月5日
刚刚好h  LV1 2022年5月23日
1525281916 2021年8月13日
暂无贡献等级
7  LV1 2021年6月16日
喵小兵  LV10 2021年6月1日
卟linlin  LV1 2021年5月26日
18162794490  LV1 2020年12月26日
liulujia  LV1 2020年8月29日
创造bug的小白  LV2 2020年8月28日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友