/**
 * 过关方式类型
 */
var SpPassType = new Class({
	initialize : function(index, passMatchs) {
		this.value = 1 << index; // 值，用第几位二进制表示当前过关类型
		this.passMatchs = passMatchs; // 过关数组，注：[2]表示要过两关，[2,3]表示要过两关和三关，[1,2,3]表示要过单关，两关和三关
		this.matchCount = this.passMatchs[this.passMatchs.length - 1]; // 此过关类型所需选择的场次数目

		var units = 0;
		for ( var i = 0, len = this.passMatchs.length; i < len; i++) {
			units += comp(this.passMatchs[i], this.matchCount);
		}
		this.units = units;// 此过关类型单选时的注数

		if (this.matchCount == 1) {
			this.text = '单关';// 过关类型名称
			this.key = 'P1';// 过关类型内部名称
		} else {
			this.text = this.matchCount + '串' + this.units;// 过关类型名称
			this.key = 'P' + this.matchCount + '_' + this.units;// 过关类型内部名称
		}
	}
});

( function() {
	var arr = [
       [1],
       [2],
       [1,2],
       [3],
       [2,3],
       [1,2,3],
       [4],
       [3,4],
       [2,3,4],
       [1,2,3,4],
       [5],
       [4,5],
       [3,4,5],
       [2,3,4,5],
       [1,2,3,4,5],
       [6],
       [5,6],
       [4,5,6],
       [3,4,5,6],
       [2,3,4,5,6],
       [1,2,3,4,5,6],
       [7],
       [8],
       [9],
       [10],
       [11],
       [12],
       [13],
       [14],
       [15]
	];
	
	var values = [];
	for ( var i = 0, len = arr.length; i < len; i++) {
		var passType = new SpPassType(i, arr[i]);
		SpPassType[passType.key] = passType;
		values.push(passType);
	}
	
	SpPassType.values = function(){
		return values;
	};
	
	// 获取当前可选的普通过关类型，matchCount是当前选中的场次数目
	SpPassType.getSimplePassType = function(matchCount) {
		if (matchCount < 1 || matchCount > 15) {
			return null;
		}
		var simpleTypes = [];
		simpleTypes.push(values[0]);
		if (matchCount > 1) {
			for ( var i = 0, len = values.length; i < len; i++) {
				var passType = values[i];
				if (passType.matchCount == matchCount) {
					simpleTypes.push(passType)
				} else if (passType.matchCount > matchCount) {
					break;
				}
			}
		}
		return simpleTypes;
	}
	
	// 获取当前可选的多选过关类型，matchCount是当前选中的场次数目
	SpPassType.getMultiplePassType = function(matchCount) {
		var multipleTypes = [];
		if (matchCount < 1 || matchCount > 15) {
			return multipleTypes;
		}
		for ( var i = 0, len = values.length; i < len; i++) {
			var passType = values[i];
			if (passType.matchCount <= matchCount && passType.units == 1) {
				multipleTypes.push(passType)
			} else if (passType.matchCount > matchCount) {
				break;
			}
		}
		return multipleTypes;
	}
})();
