<commit_before>/** 
* 画布对象
*
* @module canvasModel
* @namespace fan1xia.model
* @main canvasModel
* @author 颜海镜
* @version 2012-09-29 15:20:04
*/
(function($, window){
	'use strict';
	var Canvas,
		Timer,
		Store,
		Score;
	/**
	* 画布类
	* @class Canvas
	* @constructor
	* @extends fan1xia.model.Canvas.prototype
	*/
	Canvas = function(){
	    /**
	     * 时间对象
	     * @property timer
	     * @type Object
	     * @default null
	     */
		this.timer = null;
		
		/**
         * 分数对象
         * @property score
         * @type Object
         * @default null
         */
		this.score = null;
		
		/**
         * 存数对象
         * @property store
         * @type Object
         * @default null
         */
		this.store = null;
		
		/**
         * 图片对象
         * @property images
         * @type Object
         * @default null
         */
		this.images = null;
		
		/**
         * 声音对象
         * @property sound
         * @type Object
         * @default null
         */
		this.sound = new window.yan.Sound();
	};
	
	/**
	* Canvas构造函数的原型对象
	* @class Canvas.prototype
	* @static
	*/
	Canvas.prototype = {
		/**
		 * 初始化
		 * @method init 
		 */
		init:function(level, grad){
		    var
		        score = new Score(),
                timer = new Timer(),
                store = new Store();
                
            this.score = score;
            this.timer = timer;
            this.store = store;
			this.bindClickEvent();		
			this.images = new window.fan1xia.model.Images();
			this.images.init();	
		},
		
		/**
		 * 刷新画布元素
		 * @method refresh 
		 * @param {Number} level游戏的级别
		 * @param {Number} grad 游戏单个图象重复的次数
		 */
		refresh:function(level, grad){
			var images = this.images,
			imgDoms = [],
			$table = $('#canvas table'),
			score = this.score,
			timer = this.timer,
			store = this.store;

			//收起 散开
			$table.yanVhSlideCenter(0, function(){
				$table.yanVhSlideSide('slow');
			});
			
			//清空元素
			this.reset();
			//加载imagesdom
			imgDoms = images.getImages(level*level, grad);
			//构造html添加到画布元素
			this.createHtml(imgDoms, level);
			//更新分数面板
			score.reset(level);
			
			//更新时钟
			timer.init((new Date()).getTime() + (level*level)*1000 + level*20*1000);
			//更新储物箱
			store.reset();
		},
		
		/**
		 * 构造html
		 * @method createHtml
		 * @param {Array} imgDoms 图象dom数组元素
		 * @param {Number} level 级别 
		 */
		createHtml:function(imgDoms, level){
			var 
				_$ = $,
				$tbody = $('#canvas table tbody'),
				len = imgDoms.length,
				i = 0,
				j = 0,
				$tr = [],
				$td = [];
				
			for(i; i<level; i++){
				$tr[i] = _$('<tr></tr>');
				for(j=0; j<level; j++){
					$td[i*level + j] = _$('<td></td>');
					$td[i*level + j].append(imgDoms[i*level + j]);
					$tr[i].append($td[i*level + j]);
				}
				
				$tbody.append($tr[i]);
			}	
		},
		
		/**
		 * 初始化画布元素
		 * @method initCanvas 
		 * @param {Array} imgDoms 
		 */
		initCanvas:function(imgDoms){
			var len = imgDoms.lenght;
		},
		/**
		 * 重置画布
		 * @method reset 
		 */
		reset:function(){
			var 
			score = this.score,
			timer = this.timer,
			store = this.store;
			
			$('#canvas table tbody').empty();
			score.reset();
			timer.reset();
			store.reset();
		},
		
		/**
		 * 绑定单击事件
		 * @event bindClickEvent 
		 */
		bindClickEvent:function(){
			var 
				$goHome = $('#go-home'),
				$table = $('#canvas '),
				that = this,
				$preImg = null,
				sound = this.sound,
				score = this.score,
                store = this.store,
				success = function(){},
				failed = function(){},
				first = function(){};
			
			//成功的事件
			success = function($currentImg){
				sound.play('./media/spread.wav');
				$preImg.attr({src:'', rel:''});
				$currentImg.attr({src:'', rel:''});
				//更新当前图象
				$preImg = null;
				store.pull();
				//更新已经消除次数
				score.decreaseRemainNumber();
			};	
			
			//失败的事件
			failed = function($currentImg){
				//翻到不相同图象
				that.unclockRotate180($preImg, function(){});
				that.unclockRotate180($currentImg, function(){});
					
				//更新当前图象
				$preImg = null;
				sound.play('./media/Click.wav');
				
				//更新失败次数
				score.addErrorCount();
			};	
			
			//初次点击事件
			first = function($currentImg){
				//第一次开始翻
				$preImg = $currentImg;
			};
			
			//绑定图片的点击事件	
			$table.delegate('img[rel!=""]:not(.front)', 'touchstart', function(e){
				var 
					$this = $(this),
					preSrc = $preImg !==null && $preImg.attr('rel'),
					currentSrc = $this.attr('rel');

				//更新点击次数<commit_msg>thtt2<commit_after>/** 
* 画布对象
*
* @module canvasModel
* @namespace fan1xia.model
* @main canvasModel
* @author 颜海镜
* @version 2012-09-29 15:20:04
*/
(function($, window){
	'use strict';
	var Canvas,
		Timer,
		Store,
		Score;
	/**
	* 画布类
	* @class Canvas
	* @constructor
	* @extends fan1xia.model.Canvas.prototype
	*/
	Canvas = function(){
	    /**
	     * 时间对象
	     * @property timer
	     * @type Object
	     * @default null
	     */
		this.timer = null;
		
		/**
         * 分数对象
         * @property score
         * @type Object
         * @default null
         */
		this.score = null;
		
		/**
         * 存数对象
         * @property store
         * @type Object
         * @default null
         */
		this.store = null;
		
		/**
         * 图片对象
         * @property images
         * @type Object
         * @default null
         */
		this.images = null;
		
		/**
         * 声音对象
         * @property sound
         * @type Object
         * @default null
         */
		this.sound = new window.yan.Sound();
	};
	
	/**
	* Canvas构造函数的原型对象
	* @class Canvas.prototype
	* @static
	*/
	Canvas.prototype = {
		/**
		 * 初始化
		 * @method init 
		 */
		init:function(level, grad){
		    var
		        score = new Score(),
                timer = new Timer(),
                store = new Store();
                
            this.score = score;
            this.timer = timer;
            this.store = store;
			this.bindClickEvent();		
			this.images = new window.fan1xia.model.Images();
			this.images.init();	
		},
		
		/**
		 * 刷新画布元素
		 * @method refresh 
		 * @param {Number} level游戏的级别
		 * @param {Number} grad 游戏单个图象重复的次数
		 */
		refresh:function(level, grad){
			var images = this.images,
			imgDoms = [],
			$table = $('#canvas table'),
			score = this.score,
			timer = this.timer,
			store = this.store;

			//收起 散开
			$table.yanVhSlideCenter(0, function(){
				$table.yanVhSlideSide('slow');
			});
			
			//清空元素
			this.reset();
			//加载imagesdom
			imgDoms = images.getImages(level*level, grad);
			//构造html添加到画布元素
			this.createHtml(imgDoms, level);
			//更新分数面板
			score.reset(level);
			
			//更新时钟
			timer.init((new Date()).getTime() + (level*level)*1000 + level*20*1000);
			//更新储物箱
			store.reset();
		},
		
		/**
		 * 构造html
		 * @method createHtml
		 * @param {Array} imgDoms 图象dom数组元素
		 * @param {Number} level 级别 
		 */
		createHtml:function(imgDoms, level){
			var 
				_$ = $,
				$tbody = $('#canvas table tbody'),
				len = imgDoms.length,
				i = 0,
				j = 0,
				$tr = [],
				$td = [];
				
			for(i; i<level; i++){
				$tr[i] = _$('<tr></tr>');
				for(j=0; j<level; j++){
					$td[i*level + j] = _$('<td></td>');
					$td[i*level + j].append(imgDoms[i*level + j]);
					$tr[i].append($td[i*level + j]);
				}
				
				$tbody.append($tr[i]);
			}	
		},
		
		/**
		 * 初始化画布元素
		 * @method initCanvas 
		 * @param {Array} imgDoms 
		 */
		initCanvas:function(imgDoms){
			var len = imgDoms.lenght;
		},
		/**
		 * 重置画布
		 * @method reset 
		 */
		reset:function(){
			var 
			score = this.score,
			timer = this.timer,
			store = this.store;
			
			$('#canvas table tbody').empty();
			score.reset();
			timer.reset();
			store.reset();
		},
		
		/**
		 * 绑定单击事件
		 * @event bindClickEvent 
		 */
		bindClickEvent:function(){
			var 
				$goHome = $('#go-home'),
				$table = $('#canvas '),
				that = this,
				$preImg = null,
				sound = this.sound,
				score = this.score,
                store = this.store,
				success = function(){},
				failed = function(){},
				first = function(){};
			
			//成功的事件
			success = function($currentImg){
				sound.play('./media/spread.wav');
				$preImg.attr({src:'', rel:''});
				$currentImg.attr({src:'', rel:''});
				//更新当前图象
				$preImg = null;
				store.pull();
				//更新已经消除次数
				score.decreaseRemainNumber();
			};	
			
			//失败的事件
			failed = function($currentImg){
				//翻到不相同图象
				that.unclockRotate180($preImg, function(){});
				that.unclockRotate180($currentImg, function(){});
					
				//更新当前图象
				$preImg = null;
				sound.play('./media/Click.wav');
				
				//更新失败次数
				score.addErrorCount();
			};	
			
			//初次点击事件
			first = function($currentImg){
				//第一次开始翻
				$preImg = $currentImg;
			};
			
			//绑定图片的点击事件	
			$table.delegate('img[rel!=""]:not(.front)', 'click', function(e){
				var 
					$this = $(this),
					preSrc = $preImg !==null && $preImg.attr('rel'),
					currentSrc = $this.attr('rel');

				//更新点击次数
{'fraction_non_alphanumeric': 0.17562521217607785, 'fraction_numerical': 0.00848704311417902, 'mean_word_length': 1.9371884346959123, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4856956', 'n_tokens_mistral': 4144, 'n_tokens_neox': 3397, 'n_words': 595}