WestFighting / 西途决斗 升级

这次在原来的基础上升级到v1.1.0版,修正或正加了一些功能如下:

1, 修正上下牛仔走动时脚没有动作的情况;
2, 不支持游戏的浏览器提示修改;
3, 族人的活动和死亡数量的实时更新;

4, 暂停后又继续时记录运行时钟钟变快,修改该问题;
5, 辅助对象名称 sysVariables 修改为 gameSystem 比较直观也好记;
6, 响应键盘的事件 keyPress()函数, keyRelease()函数 和 iniGameUI()函数更改,兼容性更好;
7, 修正牛仔向 左上,左下,右上,右下 四个方向行走时牛仔的面部和行走方向的一致性的处理,即westCowboy.move()方法修改;

8, 增加牛仔的虚弱提示,当生命值小于1000时进入虚弱期;提示几秒钟应该避免被群殴的情况, 建议一对一的单打加搏斗作战方式;

WestFighting / 西途决斗 完整代码如下, v1.1.0

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Fighting - HTML5</title>
<style type="text/css">
body{margin:0px; padding:0; overflow-x:hidden;}
body,td,div,span,input,canvas{font-family:verdana,arial; font-size:12px;}
a:link, a:visited{font-family:verdana,arial; font-size:11px; color:#006699; text-decoration:underline;}
a:hover, a:active{font-family:verdana,arial; font-size:11px; color:#FF0033; text-decoration:none;}
#gameContainer{border:1px solid red;}
#gameCanvas{font-size:12px; font-family:verdana,arial; }
#infoPanel{font-family:verdana,arial; font-size:12px; border:1px solid #D63C06; display:block; padding:5px; background-color:#F9EFE9; overflow:hidden;}
#gameInfo{font-family:verdana,arial; font-size:11px; text-align:right; font-weight:normal; display:block; border-bottom:1px solid #999999;padding-bottom:3px;}
#controlPanel{padding:10px 0;}
.num01{font-family:verdana,arial; font-size:10px; padding:0 2px; font-weight:normal;}
.num02{font-family:verdana,arial; font-size:11px; padding:0 2px; font-weight:normal; color:#990000;}
a.a01:link, a.a01:visited{font-family:verdana,arial; font-size:12px; color:#006699; border:1px solid #999999; padding:2px 4px; margin:0 5px; text-decoration:none}
a.a01:hover, a.a01:active{font-family:verdana,arial; font-size:12px; color:#FFFFCC; border:1px solid #999999; padding:2px 4px; margin:0 5px; text-decoration:none; background-color:#990000}
</style>
</head><body οnkeydοwn="javascript:keyPress(event);" οnkeyup="javascript:keyRelease(event);">
<div id="gameContainer">
<canvas id="gameCanvas" width="1024">
<div id="gbTip">请使用支持HTML5的浏览器...</div>
</canvas>
</div>
<!--start: info panel-->
<div id="infoPanel">
<div id="gameInfo"><b>West Fighting[西途决斗]</b>, Version:1.0.0, Current Time:<span class="num02" id="cTime">2010-11-30 10:20:32</span>, Run Time:<span class="num02" id="rTime">0000</span>sec, created by <a target="_blank" title="^_^ welcome..." href="http://hi.csdn.net/shenzhenNBA">shenzhenNBA[CSDN]</a>, <a target="_blank" title="^_^ welcome..." href="http://blog.csdn.net/shenzhennba/">Blog</a> 2011-12-01(商用需授权...)</div>
<div id="controlPanel">
Cowboy Life:<span class="num02" id="cowboyLife">120</span>, Position:[X:<span class="num02" id="cowboyPX">0</span>, Y:<span class="num02" id="cowboyPY">0</span>]
Tribe man Active:<span class="num02" id="tmActive">0</span>, Death:<span class="num02" id="tmDeath">0</span>
control key: [ ↑,←, ↓, → ] or [ W,A,S,D ], fast + [ Ctrl ]
<a class="a01" href="javascript:gameStart();" title="开始">Start</a> <a class="a01" href="javascript:gamePause();" title="暂停">Pause</a> <a class="a01" href="javascript:gameContinue();" title="继续">Continue</a> <a class="a01" href="javascript:gameRestart();" title="结束当前重新开始游戏">Restart</a> <a class="a01" href="javascript:gameEnd();" title="结束游戏">End</a><a class="a01" title="游戏说明" href="javascript:void(0);">How to play</a> <span id="num"></span>
</div>
</div>
<!--end: info panel-->
<script language="javascript" type="text/javascript">
//---------------------start: bloodBottle define---------------------
var bloodBottle = {//no finisth yetspeed:1,x:0,y:0,bloodValue:30,  //all valuestep:5,          //each time eat valuetouchTimes:0,  //value is [0~4] =4 then hide bottleinit: function(){},move: function(){},
};
//---------------------end: bloodBottle define---------------------//---------------------start: west cowboy define---------------------
var westCowboy={cowboyVersion:"1.0.0",  //about the west Cowboy info and refered authorcowboyPicSRC : "http://hi.csdn.net/attachment/201112/17/65387_1324102531Z4He.png",  cowboyPicObj:"",gridSize:50,  //width=height=50picSN:0,cowboyPicAuthor  : "shenzhenNBA",  initLifeValue: 5000,lifeValue   : 0,killValue   : 1,speed       : 1,qspeed      : 4,x           : 0,y           : 0,    innerXMin   : 0,innerYMin   : 0,innerXMax   : 0,    innerYMax   : 0,r           : 20,     //cowboy size:20*20isShowTip  : false,  //[show refered info, true=show, false=hide]isWeak      : false,i           : 2,init: function(){this.lifeValue=this.initLifeValue;this.innerXMin=this.r;this.innerYMin=this.r;//this.innerXMax=    gameSystem.scrW-this.r;//this.innerYMax=   gameSystem.scrH-this.r;this.innerXMax=$("gameCanvas").width-this.r;this.innerYMax=$("gameCanvas").height-this.r;          this.x=Math.floor($("gameCanvas").width/2);this.y=Math.floor($("gameCanvas").height/2);var img=new Image();img.src=this.cowboyPicSRC;this.cowboyPicObj=img;}
};westCowboy.getSpeed = function(){  //get move speed flagreturn (inputFlag.quick ? this.qspeed : this.speed);  //attend: this = westCowboy
};westCowboy.showCowboyTip = function(){
//function to show cowboy refered informationif(this.isShowTip){var c=$("gameCanvas");var cxt=c.getContext("2d");//cxt.clearRect(this.left+this.r,this.top+this.r,80,25);  //clear areacxt.font="10px Arial";cxt.fillStyle="#6600FF";   //FF6600cxt.fillText("Life:"+this.lifeValue,this.x+this.r*2,this.y+this.r);      }
};westCowboy.showThew = function(){if(this.lifeValue<1000 && this.lifeValue>0){if(this.isWeak){var c=$("gameCanvas");var cxt=c.getContext("2d");//cxt.clearRect(this.left+this.r,this.top+this.r,80,25);  //clear areacxt.font="10px Arial";cxt.fillStyle="#6600FF";   //FF6600cxt.fillText(this.lifeValue+", weak, fihging by 1:1 ...",this.x+this.r*2,this.y+this.r*2);     }   }
};westCowboy.move=function(){if(this.lifeValue>0){if (inputFlag.right)westCowboy.x+=westCowboy.getSpeed();if (inputFlag.left) westCowboy.x-=westCowboy.getSpeed();if (inputFlag.down)    westCowboy.y+=westCowboy.getSpeed();if (inputFlag.up) westCowboy.y-=westCowboy.getSpeed();}$("cowboyLife").innerHTML=westCowboy.lifeValue;$("cowboyPX").innerHTML=westCowboy.x;$("cowboyPY").innerHTML=westCowboy.y;if (westCowboy.x > westCowboy.innerXMax) westCowboy.x=westCowboy.innerXMax;//if (westCowboy.x<westCowboy.innerXMin)  westCowboy.x=westCowboy.innerXMin;if (westCowboy.x < westCowboy.r) westCowboy.x=westCowboy.innerXMin;if (westCowboy.y > westCowboy.innerYMax) westCowboy.y=westCowboy.innerYMax;//if (westCowboy.y<westCowboy.innerYMin)    westCowboy.y=westCowboy.innerYMin;if (westCowboy.y < westCowboy.r) westCowboy.y=westCowboy.innerYMin;var c=$("gameCanvas");var cxt=c.getContext("2d");       //format: drawImage(image, sx, sy, sw, sh, dx, dy, dw, dh)  if(this.lifeValue>0){ //not face touch and status is: Move or Stop, include [上下左右,左上,左下,右上,右下]if(inputFlag.left)        //move to leftcxt.drawImage(westCowboy.cowboyPicObj,westCowboy.gridSize*westCowboy.picSN,westCowboy.gridSize*3,westCowboy.gridSize,westCowboy.gridSize,this.x,this.y,westCowboy.gridSize,westCowboy.gridSize);   else if(inputFlag.right)  //move to rightcxt.drawImage(westCowboy.cowboyPicObj,westCowboy.gridSize*westCowboy.picSN,westCowboy.gridSize*4,westCowboy.gridSize,westCowboy.gridSize,this.x,this.y,westCowboy.gridSize,westCowboy.gridSize);   else if(inputFlag.up)     //move to upcxt.drawImage(westCowboy.cowboyPicObj,westCowboy.gridSize*westCowboy.picSN,westCowboy.gridSize*3,westCowboy.gridSize,westCowboy.gridSize,this.x,this.y,westCowboy.gridSize,westCowboy.gridSize);   else if(inputFlag.down)   //move to downcxt.drawImage(westCowboy.cowboyPicObj,westCowboy.gridSize*westCowboy.picSN,westCowboy.gridSize*4,westCowboy.gridSize,westCowboy.gridSize,this.x,this.y,westCowboy.gridSize,westCowboy.gridSize);   else  //stop movecxt.drawImage(westCowboy.cowboyPicObj,westCowboy.gridSize*3,westCowboy.gridSize*3,westCowboy.gridSize,westCowboy.gridSize,this.x,this.y,westCowboy.gridSize,westCowboy.gridSize);   westCowboy.picSN+=1;if(westCowboy.picSN>=4) westCowboy.picSN=0;}else{cxt.drawImage(westCowboy.cowboyPicObj,westCowboy.gridSize*4,westCowboy.gridSize*3,westCowboy.gridSize,westCowboy.gridSize,this.x,this.y,westCowboy.gridSize,westCowboy.gridSize);   }/* for TEST, ONLY draw a dot *//*cxt.fillStyle="#666666";  //draw the RED dot   //, FF0000cxt.beginPath();cxt.arc(westCowboy.x,westCowboy.y,westCowboy.r,0,Math.PI * 2,true);  //draw a dot; syntax: context.arc(centerX, centerY, radius, startingAngle, endingAngle, antiClockwise);cxt.closePath();cxt.fill();  */this.showCowboyTip();this.showThew();
};westCowboy.eat= function(){
//function to eat blood when touch blood Bottle}
//---------------------end: west cowboy define-----------------------//--------------------start: keep tribe move time define-------------
var tribeManMoveTimeController={
//function to controll the tribe man keep move in old direction some time and then change the move direction
//设置在上一次方向上持续移动的时间,超过该时间后,动态修正方向[以牛仔为目标]再持续在该方向上移动指定时间在修正方向,一直循环这个过程到死忙
//keepMoveTime 时间越短动态改变方向越快,朝牛仔目标移动越灵敏i:0,weakTipChangeTime:2,weakTipShowTime:2,t:0,timeControllerID:"",      timeOn:function(){      //----------------start: about tribe man time control--------------------for(this.t=0;this.t<gameSystem.tribeMen.length;this.t++){gameSystem.tribeMen[this.t].k+=1;         if(gameSystem.tribeMen[this.t].k==gameSystem.tribeMen[this.t].keepMoveTime){          gameSystem.tribeMen[this.t].isChangeDirection=true;gameSystem.tribeMen[this.t].k=0;}else{gameSystem.tribeMen[this.t].isChangeDirection=false;}                               }       //----------------end: about tribe man time control--------------------//----------------start: about cowboy weak tip time control--------------------this.i++;if(this.i > this.weakTipChangeTime){if(this.i >= this.weakTipChangeTime + this.weakTipShowTime) this.i = 0;westCowboy.isWeak=true;       }elsewestCowboy.isWeak=false;                  //----------------end: about cowboy weak tip time control--------------------}
};
//--------------------end: keep tribe move time define---------------//---------------------start: tribe man define-----------------------
var tribeMan=function(){//tribeman properties difine areathis.tribeManVersion="1.0.0";  //about the Tribe Man info and refered author,this.tribeManPicSRC= "http://hi.csdn.net/attachment/201112/17/65387_1324102531Z4He.png";          //tribe man picthis.tribeManPicAuthor="shenzhenNBA";this.gridSize=50;   //width=height=50this.tribeManPicObj="";this.picSN=0;this.lifeValue=800;      //value is [800~4000],default=80this.killValue=1;         //value is [1~3],default=1this.x=0;this.y=0;this.r=20;              //tribe man size:20x20this.speed=1;            //value is [1~3],default=1this.diffX=0;           //offset in X axisthis.diffY=0;            //offset in Y axisthis.moveAngle=0;        //move anglethis.isXAddFlag=true;  //this.isYAddFlag=true;    //this.canvasW=$('gameCanvas').width;this.canvasH=$('gameCanvas').height; this.isChangeDirection=true;   //change direction [ true = can change, false= can not change ]this.k=0;                         //temperate variablethis.keepMoveTime=3;     //keep move in old direction time(unit:s), random this.isShowLifeValue=false;  //show life value [true=show, false=hide(default)]//tribeman init areathis.rangeRandom=function(minValue, maxValue){       if(maxValue >= minValue)return Math.floor(Math.random()*(maxValue-minValue+1)+minValue);elsereturn Math.floor(Math.random()*(minValue-maxValue+1)+maxValue);        };this.rangeRandom2=function(minValue, maxValue,maxValuePercent){//function to get value, maxValue [percent = maxValuePercent ], minValue [percent = 1-maxValuePercent ]var mvPer=0;var v=0;try{ mvPer=parseFloat(maxValuePercent); }catch(e){ mvPer=0.8; }if(Math.random()>=mvPer) v=maxValue;elsev=minValue;return v;};this.init=function(){            //----------------------?????----------------------------------------var img=new Image();img.src=this.tribeManPicSRC;this.tribeManPicObj=img;this.keepMoveTime=this.rangeRandom(2,5);  //keep move in old direction time(unit:s), random this.lifeValue=this.rangeRandom(80,100);  //attend: this = tribethis.killValue=this.rangeRandom(1,3);this.speed=this.rangeRandom2(1,3,0.75);this.moveAngle=Math.floor(Math.random()*91);      //angle value is [0~91]var maxR=Math.floor(Math.sqrt(this.canvasW*this.canvasW+this.canvasH*this.canvasH));       //用勾股定律求画布canvas的对角线的长度var randomR=this.rangeRandom(maxR*0.5,maxR);    //value is [maxR/2 ~ maxR]//get X,Y axis position here //以对角线为最大值随机取值,以90为最大角度随机取角度,分别用三角函数求出XY值this.x=randomR*Math.sin(this.moveAngle);     //x value is [0~maxR]       this.y=randomR*Math.cos(this.moveAngle);       //x value is [0~maxR]if(this.x>this.canvasW) this.x=this.canvasW;  //限定在 canvas 内部if(this.x<0) this.x=0;if(this.y>this.canvasH) this.y=this.canvasH;if(this.y<0) this.y=0;//判断所在像限:左上[+X,+Y],右上[-X,+Y],左下[+X,-Y],右下[-X,-Y],确定增量的方向,if(this.x<this.canvasW/2 && this.y<=this.canvasH/2){  //左上,含Y中间左轴线this.isXAddFlag=true;this.isYAddFlag=true;}else if(this.x>this.canvasW/2 && this.y<=this.canvasH/2){  //右上,含Y中间右轴线 this.isXAddFlag=false;this.isYAddFlag=true;}else if(this.x<=this.canvasW/2 && this.y>this.canvasH/2){  //左下,含X中间下轴线this.isXAddFlag=true;this.isYAddFlag=false;}else{ //右下this.isXAddFlag=false;this.isYAddFlag=false;}//设置 XY 两个方向的增量方式:增或减,以及位移量this.diffX=Math.sin(Math.PI/180*this.moveAngle)*this.speed;this.diffX=this.isXAddFlag ? this.diffX : 0-this.diffX ;this.diffY=Math.cos(Math.PI/180*this.moveAngle)*this.speed;this.diffY=this.isYAddFlag ? this.diffY : 0-this.diffY;   if(this.diffX < 0.001) this.diffX=Math.random();  //diffX,diffY > 0.001, //set  the min diffX,diffYif(this.diffY < 0.001) this.diffY=Math.random();//alert('tribe init...');   //for TEST};//tribeman Action area          this.move=function(){//function to move tribemen, if death then can not move more.     var c=$('gameCanvas');var cxt=c.getContext("2d");     if(this.lifeValue>0){ //active lefevar ftFlag=this.faceTouch();         if(ftFlag){  //face touch   //face touch then fightingcxt.drawImage(this.tribeManPicObj,this.gridSize*this.picSN,this.gridSize*2,this.gridSize,this.gridSize,this.x,this.y,this.gridSize,this.gridSize);   if(westCowboy.lifeValue>0)cxt.drawImage(westCowboy.cowboyPicObj,westCowboy.gridSize*westCowboy.picSN,westCowboy.gridSize*5,westCowboy.gridSize,westCowboy.gridSize,westCowboy.x,westCowboy.y,westCowboy.gridSize,westCowboy.gridSize);   elsecxt.drawImage(westCowboy.cowboyPicObj,westCowboy.gridSize*4,westCowboy.gridSize*3,westCowboy.gridSize,westCowboy.gridSize,westCowboy.x,westCowboy.y,westCowboy.gridSize,westCowboy.gridSize);   }else{ //no face touch, move continueif(westCowboy.lifeValue<=0){ //cowboy death then tribe man walk free//-----start: walk free-----if(this.x<0) this.diffX = Math.abs(this.diffX);if(this.x>this.canvasW) this.diffX = -Math.abs(this.diffX);if(this.y<0) this.diffY = Math.abs(this.diffY);if(this.y>this.canvasH) this.diffY = -Math.abs(this.diffY);//-----end: walk free-----}else{                //-----start: walk to cowboy-----if(this.isChangeDirection){  if(westCowboy.x >= this.x) this.diffX = Math.abs(this.diffX);elsethis.diffX = -Math.abs(this.diffX);                if(westCowboy.y >= this.y) this.diffY = Math.abs(this.diffY);elsethis.diffY = -Math.abs(this.diffY);}                     //-----end: walk to cowboy-------}this.x=this.x+this.diffX;   //attend: this = tribethis.y=this.y+this.diffY;      //format: drawImage(image, sx, sy, sw, sh, dx, dy, dw, dh)  if(westCowboy.x >= this.x)  //move to rightcxt.drawImage(this.tribeManPicObj,this.gridSize*this.picSN,this.gridSize*0,this.gridSize,this.gridSize,this.x,this.y,this.gridSize,this.gridSize);   else  //move to leftcxt.drawImage(this.tribeManPicObj,this.gridSize*this.picSN,this.gridSize*1,this.gridSize,this.gridSize,this.x,this.y,this.gridSize,this.gridSize);   }      this.picSN+=1;if(this.picSN>=4) this.picSN=0;}else{  //deathcxt.drawImage(this.tribeManPicObj,this.gridSize*4,0,this.gridSize,this.gridSize,this.x,this.y,this.gridSize,this.gridSize);   }/*//only for TEST     cxt.fillStyle="#DDDDDD";  //, 0000FFcxt.beginPath();cxt.arc(this.x,this.y,this.r,0,Math.PI*2,true);          cxt.closePath();cxt.fill();         */if(this.isShowLifeValue){cxt.font="10px Arial";cxt.fillStyle="#006600";cxt.fillText("Life: "+this.lifeValue,this.x+this.r*2,this.y+this.r);    }};this.faceTouch=function(){//function to jugme tribe man face touch cowboy or else,[true=face touch, false=no touch]       var dx = Math.abs(westCowboy.x-this.x);var dy = Math.abs(westCowboy.y-this.y);var dl=dx*dx+dy*dy;       var tl=(this.r*this.r+this.r*this.r)*2;   //attend the Size of tribe man and cowboy should be the sameif(dl<tl){  return true;}else{           return false;       }       };this.showTribeTip=function(){//function to show the tribe man informationvar c=$('gameCanvas');var cxt=c.getContext("2d");     cxt.font="normal normal 11px verdana";//show tribe man lefe valuecxt.fillStyle="#0000FF";cxt.fillText("Life:"+this.lifeValue,this.x+this.r*2,this.y); //+this.r//show cowboy lefe valuecxt.fillStyle="#FF0000";//cxt.clearRect(westCowboy.x+westCowboy.r,westCowboy.y-11,10*6,11);  //format:context.clearRect(x,y,width,height);  //clear the block firstcxt.fillText("Life:"+westCowboy.lifeValue,westCowboy.x+westCowboy.r*2,westCowboy.y);       //westCowboy.r};this.showFightTip=function(){//function to show the tribe man informationvar c=$('gameCanvas');var cxt=c.getContext("2d");       cxt.font="normal normal 11px verdana";//show tribe man fighting Wordscxt.fillStyle="#0000FF";if(this.lifeValue>0) cxt.fillText("kill... kill...",this.x+this.r*2,this.y+this.r/2); elsecxt.fillText("death...",this.x+this.r*2,this.y+this.r/2);   //show cowboy fighting Wordscxt.fillStyle="#FF0000";cxt.font="normal normal 11px verdana";//cxt.clearRect(westCowboy.x+westCowboy.r,westCowboy.y-11,10*6,11);  //format:context.clearRect(x,y,width,height);  //clear the block firstif(westCowboy.lifeValue>0)cxt.fillText("fighting...fighting...",westCowboy.x+westCowboy.r*2,westCowboy.y+this.r/2);      elsecxt.fillText("death...",westCowboy.x+westCowboy.r*2,westCowboy.y+this.r/2);     };this.fighting=function(){//functionto fighting with cowboy here if face touchvar ft=this.faceTouch();       if(ft){ //face touch here                   if(this.lifeValue>0){if(westCowboy.lifeValue>0) westCowboy.lifeValue = westCowboy.lifeValue - this.killValue;            if(westCowboy.lifeValue<0) westCowboy.lifeValue=0;}if(westCowboy.lifeValue>0){if(this.lifeValue>0) this.lifeValue = this.lifeValue - westCowboy.killValue;if(this.lifeValue<0) this.lifeValue=0;}if(westCowboy.lifeValue>0){this.showTribeTip();this.showFightTip();}}else{  //face touch here            //no fighting....}};
};
//---------------------end: tribe man define-------------------------//--------------------start: global function define------------------
var $ = function(id){return "string"==typeof(id) ? document.getElementById(id) : id ;
}//定义键盘值
var KEY = { D: 68, W: 87, A: 65, S:83, DOWN:40, RIGHT:39, UP:38, LEFT:37, QUICK:17, C:67, Z:90,X:88};//定义输入标志对象
var inputFlag = {right : false,up      : false,left    : false,down    : false,quick   : false
};//按键按下相应动作修改
var keyPress = function(event){var e = event || window.event;var code = e.keyCode | e.which | e.charCode;    switch(code) {case KEY.RIGHT:case KEY.D: inputFlag.right = true; break;case KEY.UP:case KEY.W: inputFlag.up = true; break;case KEY.LEFT:case KEY.A: inputFlag.left = true; break;case KEY.DOWN:case KEY.S: inputFlag.down = true; break;case KEY.QUICK: inputFlag.quick = true; break;case KEY.C: westCowboy.isShowTip=true; break;case KEY.X: gameSystem.showTribeMenLife(); break;      }
};//按键放开相应动作修改
var keyRelease = function(event) { var e = event || window.event;var code = e.keyCode | e.which | e.charCode;    switch(code) {case KEY.RIGHT:case KEY.D: inputFlag.right = false; break;case KEY.UP:case KEY.W: inputFlag.up = false; break;case KEY.LEFT:case KEY.A: inputFlag.left = false; break;case KEY.DOWN:case KEY.S: inputFlag.down = false; break;case KEY.QUICK: inputFlag.quick = false; break;case KEY.C: westCowboy.isShowTip=false; break;case KEY.Z: if(westCowboy.lifeValue >= westCowboy.initLifeValue)westCowboy.lifeValue = westCowboy.initLifeValue;else        westCowboy.lifeValue+=2;      break;case KEY.X:gameSystem.hideTribeMenLife();break;}
};var gameSystem = {
//function to get game system variables gameName : "West Fighting......",   //about game information gameNameCN: "西途决斗......",gameVersion : "1.1.0",              //first: v1.0.0gameLastUpdate : "2011-12-23",gameAuthor : "shenzhenNBA",gameAuthorIM: "",gameAuthorEmail: "qyhzqw@163.com",//scrW : screen.width,//scrH : screen.height,       scrW : (document.compatMode == "CSS1Compat" ? document.documentElement.clientWidth : document.body.clientWidth) || screen.availWidth,scrH : (document.compatMode == "CSS1Compat" ? document.documentElement.clientHeight : document.body.clientHeight) || screen.availHeight,   tribeManNum:30,tribeMen:[], runTime: 0,runTimerID : "",gameFrameSpeed: 20,  //PFS, refresh speedgamePlayerID: "",i:0,activeTManNum:0,ua: navigator.userAgent,isSupportHTML5: function(){var bn,bv,v;try{bn=this.getBrowserName().toLowerCase();bv=parseFloat(this.getBrowserVersion());           }catch(e){}//first Support HTML5: IE v=9,Firefox v=3.5, Chrome v=3.5,Opera v=10.5, Safari v=3.0 //找的,不知是否对if(bn=="ms ie" && bv>=9){v=true;}else if(bn=="firefox" && bv>=3.5){v=true;}else if(bn=="chrome" && bv>=3.5){v=true;}else if(bn=="opera" && bv>=3.5){v=true;}else if(bn=="safari" && bv>=3.0){v=true;}else{v=false;}return v;},      getBrowserName: function(){var uai=this.ua.toLowerCase();      var bn='';   if(uai.indexOf('msie')>=0) bn="MS IE";if(uai.indexOf('firefox')>=0) bn="FireFox";if(uai.indexOf('chrome')>=0) bn="Chrome";if(uai.indexOf('opera')>=0) bn="Opera";if(uai.indexOf('safari')>=0) bn="Safari";if(bn=="") bn="Unknow browser";return bn;},   getBrowserVersion:function(){var v='';var uai=this.ua.toLowerCase();   if(s = uai.match(/msie ([\d.]+)/))  v = RegExp.$1 ; if(s = uai.match(/firefox\/([\d.]+)/))  v = RegExp.$1 ;if(s = uai.match(/chrome\/([\d.]+)/))  v = RegExp.$1 ;if(s = uai.match(/opera.([\d.]+)/))  v = RegExp.$1 ;if(s = uai.match(/version\/([\d.]+).*safari/))  v = RegExp.$1;       if(v=="") v='unknow version';return v;},showTribeMenLife: function(){var n=0;for(n=0;n<gameSystem.tribeMen.length;n++){gameSystem.tribeMen[n].isShowLifeValue=true;}},hideTribeMenLife: function(){var n=0;for(n=0;n<gameSystem.tribeMen.length;n++){gameSystem.tribeMen[n].isShowLifeValue=false;}}
};var gameUIFace=function(objCanvas){
//function to create game UI face var oGC=objCanvas;//var oGC=$('gameCanvas');     //get object directly for Testvar cxt=oGC.getContext("2d");var cx,cy,r1,r2;r1=30;    try{ cx=oGC.width/2; }catch(e){ cx=screen.width/2; };try{ cy=oGC.height/2; }catch(e2){ cy=screen.height/2; };try{ r2=oGC.height/2; }catch(e3){ r2=screen.height/2; };/*  *///----start: draw radial/gradient circle ----var rg=cxt.createRadialGradient(cx,cy,r1,cx,cy,r2);  //create object typerg.addColorStop(0,'#FF6600');  //set the start position colorrg.addColorStop(1,'#FAFAFA');  //set the end position colorcxt.fillStyle=rg;                 //set the pen style //cxt.strokeStyle=rg;          //会使用单色黑色绘制,应该使用 fillStyle cxt.beginPath();cxt.arc(cx,cy,r2,0,Math.PI*2,true);cxt.closePath();cxt.fill(); //----end: draw radial/gradient circle ----//----start: draw cowboy image ----var img=new Image();img.src="http://hi.csdn.net/attachment/201112/17/65387_13241032476Ybf.png";   cxt.globalAlpha=0.5;    //value is [0~1],0=hide[disappear], 1 = show [clear all]cxt.drawImage(img,cx/6,-20);cxt.globalAlpha=1;//----end: draw cowboy image ---- //----start: draw gradient line ----var i=0,n=100,step=0;try{ step=Math.floor(oGC.width/n); }catch(e4){ step=Math.floor(screen.width/n);}  for(i=0;i<=n;i++){var lg=cxt.createLinearGradient((cx-n/2+i),cy,i*step,cy+300);lg.addColorStop(0,'#FF3300');lg.addColorStop(1,'#FFFFFF');   //0099CC//cxt.fillStyle=lg;      //单色黑色绘制cxt.strokeStyle=lg;        //多种颜色绘制cxt.beginPath();cxt.moveTo((cx-n*2+i*4),cy+n/4);   //set the start position//cxt.moveTo((cx-n/2+i),cy);//cxt.moveTo(cx,cy);//cxt.lineCap = 'round' ;if((i % 5)==0) cxt.lineWidth=2;   //set the line size//cxt.lineJoin ="miter";elsecxt.lineWidth=1;cxt.lineTo(i*step,cy+300);cxt.stroke();//cxt.fill();cxt.closePath();     }//----end: draw gradient line ------//----start: draw game Title ------    var moveTXTPos=60;  //about game EN Namecxt.font="italic bold 45px Arial Black";   //Verdana ,format: context.font="style variant weight size line-height family"cxt.fillStyle="#0000FF";cxt.shadowColor ="#FFFF99";  //"rgb(255,0,0)"   //99CCFFcxt.shadowOffsetX=4;cxt.shadowOffsetY=3;      cxt.shadowBlur=3;cxt.fillText(gameSystem.gameName,cx-moveTXTPos*4,cy-40); cxt.font="italic bold 24px 黑体";   //Verdana,Arial Black,,华文新魏  //about game CN Namecxt.shadowColor="#FFFF99"; cxt.shadowOffsetX=2;cxt.shadowOffsetY=2;cxt.shadowBlur=2;cxt.fillStyle="#660066";cxt.fillText(gameSystem.gameNameCN,cx-moveTXTPos*1.5,cy);   cxt.font="italic normal 11px verdana";   //about game version and authorcxt.shadowOffsetX=0;cxt.shadowOffsetY=0;cxt.shadowBlur=1;cxt.fillStyle="#FF0000";cxt.fillText("Version: "+gameSystem.gameVersion+'  Author: '+gameSystem.gameAuthor,cx+moveTXTPos/4,cy+20);   //----end: draw game Title ------   }var initGameUI=function(){
//function to initialize  Game UI here//var scrW=screen.width;//var scrH=screen.height;   //var canvasW=scrW-8;  //var canvasH=scrH-infoPanelH-xBarH;   var infoPanelH=80; //var xBarH=120;    //height of x Bars var canvasW=gameSystem.scrW-6; var canvasH=gameSystem.scrH-infoPanelH-20;var paddingLR=5;  //padding of left and right in infoPanelvar bn='',bv='';bn=gameSystem.getBrowserName().toLowerCase();bv=parseFloat(gameSystem.getBrowserVersion());var oGC='';//first Support HTML5: IE v=9,Firefox v=3.5, Chrome v=3.5,Opera v=10.5, Safari v=3.0 //找的,不知是否对if((bn=="ms ie" && bv<9) || (bn=="firefox" && bv<3.5) || (bn=="chrome" && bv<3.5) || (bn=="opera" && bv<10.5) || (bn=="safari" && bv<3.0)){  //support HTML5 go hereoGC=$('gameContainer');var tempHTML='';tempHTML="<br><p><b> Error:</b></p> 您的浏览器是 "+bn+" ,版本是 "+bv +" ,还不支持 HTML5; ";tempHTML+=" 请使用下列(或更高版本)支持 HTML5 的的浏览器:<br>";tempHTML+="<ul><li>MS IE, version = 9 或更高版本</li>";tempHTML+="<li>Firefox, version = 3.5 或更高版本</li>";tempHTML+="<li>Chrome, version = 3.5  或更高版本</li>";tempHTML+="<li>Opera, version = 10.5 或更高版本</li>";tempHTML+="<li>Safari, version = 3.0 或更高版本</li></ul>";oGC.innerHTML=tempHTML;oGC.style.width=canvasW+"px";oGC.style.height=canvasH+"px";   }else{  //support HTML5 go hereoGC=$('gameCanvas');//oGC.style.width=canvasW+"px";//oGC.style.height=canvasH+"px";   oGC.width=canvasW;oGC.height=canvasH; gameUIFace(oGC);        }var oIP=$('infoPanel');oIP.style.left="0";   oIP.style.top=canvasH+2;      oIP.style.position="fixed";          oIP.style.zIndex=8000;oIP.style.width=(canvasW-paddingLR*2)+"px";   //canvasW+"px"; oIP.style.height=infoPanelH+"px";
};var curTime=function(){ //function to display current system timevar dt=new Date()var strHTML=dt.getFullYear()+"-"+(dt.getMonth()+1<10 ? ('0'+(dt.getMonth()+1)): dt.getMonth()+1);strHTML+="-"+(dt.getDate()<10 ? '0'+dt.getDate() : dt.getDate());strHTML+=" "+(dt.getHours()<10 ? '0'+dt.getHours() : dt.getHours());strHTML+=":"+(dt.getMinutes()<10 ? '0'+dt.getMinutes(): dt.getMinutes());strHTML+=":"+(dt.getSeconds()<10 ? '0'+dt.getSeconds() : dt.getSeconds());$('cTime').innerHTML=strHTML;
};var TimeOn=function(){gameSystem.runTime++;    if(gameSystem.runTime<10) $('rTime').innerHTML='000'+gameSystem.runTime;if(gameSystem.runTime>=10 && gameSystem.runTime<100) $('rTime').innerHTML='00'+gameSystem.runTime;if(gameSystem.runTime>=100 && gameSystem.runTime<1000) $('rTime').innerHTML='0'+gameSystem.runTime;if(gameSystem.runTime>=1000) $('rTime').innerHTML=gameSystem.runTime;
};var runTimeStart=function(){gameSystem.runTimerID=setInterval(function(){TimeOn();},1000);
};var runTimePause=function(){clearInterval(gameSystem.runTimerID);gameSystem.runTimerID="";
};var runTimeStop=function(){clearInterval(gameSystem.runTimerID);gameSystem.runTimerID="";
}var runTimeReset=function(){gameSystem.runTime=0;clearInterval(gameSystem.runTimerID);gameSystem.runTimerID="";$('rTime').innerHTML='0000';
};var gameFrameUpdate=function(){
//function to play next Game Framevar c=$("gameCanvas");//var cxt=c.getContext("2d");c.width=c.width;  //clear and redraw it     westCowboy.move();gameSystem.activeTManNum=0;for(gameSystem.i=0; gameSystem.i<gameSystem.tribeMen.length; gameSystem.i++){       gameSystem.tribeMen[gameSystem.i].move();       gameSystem.tribeMen[gameSystem.i].fighting();if(gameSystem.tribeMen[gameSystem.i].lifeValue>0) gameSystem.activeTManNum++ ;        }$("tmActive").innerHTML = gameSystem.activeTManNum ;$("tmDeath").innerHTML = gameSystem.tribeMen.length - gameSystem.activeTManNum ;
};var initLoad=function(){
//function to initialize when loading initGameUI(); var isSupportHTML5=gameSystem.isSupportHTML5();    if(isSupportHTML5){     setInterval('curTime()',1000);westCowboy.init();      var i=0;for(i=0;i<gameSystem.tribeManNum;i++){  var tMan=new tribeMan();tMan.init();gameSystem.tribeMen[i]=tMan;}}
}window.οnlοad=function(){
initLoad();
};var gameStart=function(){    if(gameSystem.isSupportHTML5()){runTimeStart();if(!gameSystem.gamePlayerID){initLoad();gameSystem.gamePlayerID=setInterval(function(){gameFrameUpdate()},gameSystem.gameFrameSpeed);tribeManMoveTimeController.timeControllerID=setInterval(function(){tribeManMoveTimeController.timeOn();},1000);       }elsealert('Game is running...');}elseinitGameUI();
}var gamePause=function(){if(gameSystem.isSupportHTML5()){runTimePause();      clearInterval(gameSystem.gamePlayerID); gameSystem.gamePlayerID="";clearInterval(tribeManMoveTimeController.timeControllerID);tribeManMoveTimeController.timeControllerID="";}elseinitGameUI();
}var gameContinue=function(){if(gameSystem.isSupportHTML5()){if(!gameSystem.runTimerID) runTimeStart();if(!gameSystem.gamePlayerID) gameSystem.gamePlayerID=setInterval(function(){gameFrameUpdate()},gameSystem.gameFrameSpeed);if(!tribeManMoveTimeController.timeControllerID) tribeManMoveTimeController.timeControllerID = setInterval(function(){tribeManMoveTimeController.timeOn();},1000);}elseinitGameUI();
}var gameRestart=function(){if(gameSystem.isSupportHTML5()){runTimeReset();clearInterval(gameSystem.gamePlayerID);gameSystem.gamePlayerID="";clearInterval(tribeManMoveTimeController.timeControllerID);tribeManMoveTimeController.timeControllerID="";initLoad();gameStart();   }elseinitGameUI();
}var gameEnd=function(){if(gameSystem.isSupportHTML5()){runTimeStop();westCowboy.lifeValue=0; var h=0;for(h=0;gameSystem.tribeMen.length;h++){gameSystem.tribeMen[h].lifeValue=0;}gameFrameUpdate();clearInterval(gameSystem.gamePlayerID);gameSystem.gamePlayerID="";clearInterval(tribeManMoveTimeController.timeControllerID);tribeManMoveTimeController.timeControllerID="";}elseinitGameUI();
}
//--------------------end: global function define--------------------
</script>
</body>
</html>

有些地方可能还有点小问题,或想不到的地方,希望大家指正。

WestFighting / 西途决斗 升级 - v1.1.0 版相关推荐

  1. CRMEB知识付费系统v1.6.0版

    升级说明: 更新前请务必备份你的数据库及站点源码,二开用户请谨慎选择更新,官方不做强制. 更新为增量覆盖更新,将更新包内容覆盖到项目目录,不会更新者联系群组技术. 请务必确保php版本为7.1,安装r ...

  2. 小米8android版本9,小米8已升级安卓9.0版MIUI10,版本号为:8.9.6内测版!

    原标题:小米8已升级安卓9.0版MIUI10,版本号为:8.9.6内测版! 目前MIUI稳定版正在进行灰度测试,预计下周就会迎来升级,另外一边就是安卓9.0的适配,此前MIX2S已经率先升级安卓9.0 ...

  3. 域控制器升级的先决条件验证失败新建_快应用开发工具升级v1.4.0

    IDE v1.4.0 更新日志(Release Notes) 一.[新增]IDE编译配置项 二.[新增]语法插件增加template中方法自动补全 三.[优化]IDE web预览模块增加编译失败页面, ...

  4. 乐视android版本怎么升级,乐视网android手机客户端升级推出V2.0版

    乐视网 android手机客户端V2.0版--"乐视影视"正式发布,据乐视网运营副总裁高飞介绍,"V2.0版是早期发布的乐视网android手机客户端V1.5版的升级版本 ...

  5. U大师U盘装系统——启动U盘制作(V1.2.0版)

    1.在U大师官网下载最新的U大师U盘启动盘制作工具V1.2.0 2.下载后,在存放目录中双击"U大师-U盘启动制作.exe"运行,如果在运行工具前未插上U盘,在软件界面的" ...

  6. u大师u盘启动u盘工具制作启动盘(V1.1.0版)

    1.在U大师官网下载最新的 U大师U盘启动盘制作工具V1.1.0 2.下载后,在存放目录中双击"U大师-U盘启动制作.exe"运行,如果在运行工具前未插上U盘,在软件界面的&quo ...

  7. 阿里巴巴Java开发手册v1.2.0版

    最近在忙毕设,读了阿里java开发手册后,发现可以更好的读懂别人的代码了,一些文件之间的关系通过命名就能看出了.对自己养成良好的编码风格也有极大的帮助. 本手册仅供大家交流.学习及研究使用,禁止用于商 ...

  8. U大师U盘装系统——原版XP系统安装(V1.2.0版)

    一.准备 1.U盘一个 2.启动盘制作工具,在U大师官网中下载最新版本的U盘启动盘制作工具 3.下载原版XP镜像文件,最好是附加密钥的,因为在安装过程中需要输入密钥 二.操作步骤 1.使用U大师U盘启 ...

  9. AEAI WM v1.6.0 升级说明,开源工作管理系统

    1 升级说明 AEAI WM v1.6.0版是AEAI WM v1.5.0版工作管理系统的升级版本,本次升级的系统是基于AEAI DP 3.8.0_20170228进行打包部署的,对产品中的功能及BU ...

最新文章

  1. 算法导论中求解时间复杂度的三种方法
  2. GeneXus 图片的创建与删除1
  3. 网站服务器蜘蛛日志怎么看,如何查看百度蜘蛛,google蜘蛛爬取记录?《网站日志分析篇》...
  4. 实现主成分分析和白化
  5. 程序开机全屏且不能见任何windows界面、不能使用系统热键
  6. [C#.NET 拾遗补漏]10:理解 volatile 关键字
  7. Fastest way to duplicate mongodb collection
  8. Eclipse 中修改java编译版本
  9. python爬取百度翻译返回:{'error': 997, 'from': 'zh', 'to': 'en', 'query 问题
  10. Mac 切换仓库地址后每次都要重新输入密码
  11. 查询数据库中表的空间使用情况
  12. java ping 实现的_java实现ping功能
  13. 智能家居如何让消费者心甘情愿地买单
  14. python坦克大战小游戏,打包为exe文件
  15. 算法----其他排序
  16. 第八章 拦截器机制——《跟我学Shiro》[张开涛]
  17. c语言公路竖曲线要素代码,竖曲线要素
  18. 北斗一号卫星授时技术及在电力系统中的应用
  19. 华为服务器系统图标,监控服务器图标
  20. 关于window10修改默认浏览器闪退的情况

热门文章

  1. C++笔记 命名空间 namespace,全局作用域符::的使用
  2. PyG搭建图神经网络实现多变量输入多变量输出时间序列预测
  3. 【散文】 我感恩,生命里曾经有过你
  4. 调用百度搜索接口查询
  5. 变速器matlab仿真,基于MATLAB/simulink的无级变速器控制策略的建模与仿真
  6. Python 变量类型day03
  7. HIbernate 中 is not maped. 解决方法
  8. windows 下启动 es 报 此时不应有...
  9. 心态决定命运(人生点滴)
  10. [由零开始] 容器虚拟化技术和自动化部署-Docker