看你有多色游戏源码

Rect.js

function Rect(n,color){					//function Rect(n,color,RectColor);n小方块横向或纵向个数,color当前默认颜色,RectColor点击颜色
	createjs.Shape.call(this);
	this.setRectType = function (type){
		this._RectType = type;
		switch(type){
			case 1:
				this.setColor(color);
				break;
			case 2:
				this.setColor("#ff0000");
				break;
		}
	}
	this.setColor = function(colorString){
		this.graphics.beginFill(colorString);		//开始绘制
		this.graphics.drawRect(0,0,400/n-5,400/n-5);//左居左为0,上居上为0,右居左为宽400px/n-5(计算列数,-5是为了设置列间距),下居上为400/n-5(正好为正方形)
		this.graphics.endFill();					//结束绘制
	}
	//设置类型
	this.getRectType = function(){
		return this._RectType;
	}
	this.setRectType(1);
}
//初始化
Rect.prototype = new createjs.Shape();

app.js

var stage = new createjs.Stage("gameView");
createjs.Ticker.setFPS(30);
createjs.Ticker.addEventListener("tick",stage);
var gameView = new createjs.Container();
stage.addChild(gameView);
var n=2;
function addRect(){
	var cl = parseInt(Math.random()*1000000);
	var color="#"+cl;
	var x= parseInt(Math.random()*n);
	var y= parseInt(Math.random()*n);
	
	for(var indexX = 0;indexX

index.html



	
		
		看你有多色
		
		
	
	
		
		
		
	

 

你可能感兴趣的:(web)