日期:2014-05-16 浏览次数:20622 次
// author:小弟 // MY QQ : 285037039 // PLAY FOR FUN // OH i love POINT :-) // 如果您对该CODE有什么建议和意见,请MAIL:285037039@qq.com // 功能简单,支持下棋、悔棋和棋盘翻转 function Character() { this.x = 0; this.y = 0; this.width = 0; this.height = 0; /**0普通1DEAD*/ this.state = 0; this.id = ""; /** 1车2马3相4士5帅6炮7卒子*/ this.type = 0; /**方向,为卒子准备的 1↓走 2↑ - -。。*/ this.dir = 1; this.boardpos = 0; this.instance = {}; this.prepare = 0; this.aniTime = 500; this.show = function() { $("#"+this.id).css("left",this.x); $("#"+this.id).css("top",this.y); }; this.init = function() { var _this = this; $("#"+this.id).bind("click",function(){ _this.updateShow(); }); $("#"+this.id).show(); } this.aniMove = function(despos) { var _this = this; var _srcpos = this.boardpos; $("#"+this.id).animate({left:this.instance.board[despos].x,top:this.instance.board[despos].y},200,"swing",function(){ _this.aniEat(_srcpos,despos); }); } this.aniEat = function(_srcpos,despos) { var hasindex = this.hasChessIndex(this.id,despos); if(hasindex != 0) { this.deleteChess(hasindex); var posstr = this.id + "|" + _srcpos + "|" + despos + "|" + this.instance.chessman[hasindex].id; this.instance.history.push(posstr); } else { var posstr = this.id + "|" + _srcpos + "|" + despos + "|" + ""; this.instance.history.push(posstr); } //alert(this.boardpos); this.instance.filp(); } this.deleteChess = function(index) { if(index != 0) { $("#" + this.instance.chessman[index].id).hide(); this.instance.chessman[index].boardpos = 0; if(this.instance.chessman[index].id == "a5" || this.instance.chessman[index].id == "b5" ) { alert("GAME OVER!"); } } } this.hasChessIndex = function(exceptid,pos) { for( var ic = 1;ic <= 32; ic++) { if(this.instance.chessman[ic].boardpos == pos && this.instance.chessman[ic].id != exceptid) { return ic; } } return 0; } this.updateShow = function() { var id = (this.id.substring(0,1)); //alert(this.dir + " " + this.instance.turn); if(id == "a" && this.instance.turn == 1) { //alert(this.prepare); if(this.prepare == 0) { this.prepare0(); this.prepare = 1; } else { if(this.instance.indacatorsrcPos == this.boardpos) { return false; } if(!this.validation(this.boardpos,this.instance.indacatorsrcPos)) { return false; } this.prepare1();