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,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,3,3,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,2,2,2,2,2,2,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,2,2,2,2,2,2,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,2,2,7,7,2,2,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,2,2,7,7,2,2,0,0,0,0,0,0,0,0]];

index.html

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>坦克大战</title>
<meta content="坦克大战" name="keywords" />
<meta content="坦克大战," name="description" />
<script src="js/jquery-1.3.2.min.js"></script>
<script src="js/map.js"></script>
<script>
~function(){var mainTank;   //主坦克
var subTank;    //副坦克
var eTanks = [];       //敌坦克
var plays;             //单人或者双人模式    
var eTankLife = 20;    //敌坦克总数量
var level = 1;         //当前关数
var eTanksLength = 3;  //每次显示的敌坦克数量
var maps = [map1, map2, map3]; //地图
var map;               //当前地图
var u;         //长定时器
var xs = [[0,12,22], [0, 8, 16, 22], [0, 6, 12, 18, 22] ];
var Gb = {attr : function(){if (arguments.length == 1){return Gb[arguments[0]];}else if (arguments.length == 2){Gb[arguments[1]] = arguments[0]return Gb;}}	}//--------------------------------------Mover类---------------------------------------------
function Mover(){};Mover.prototype = {locked : false      //是否允许移动,stepLocked : false         //移动间隔锁,der : false        //移动方向,obj : null         //占位,子类对应的dom,speed : 20         //移动速度,moveRepeat : false  //是否重复移动,默认否,setXy : function(y, x){this.obj.css({top:y, left:x}); return this;},useGird : function(){      //占据网格var x = this.x, y = this.y;map[y][x].type = map[y][x+1].type = map[y+1][x].type = map[y+1][x+1].type = this.type;map[y][x].span = map[y][x+1].span = map[y+1][x].span = map[y+1][x+1].span = this;},freeGird : function(){     //释放网格var x = this.x, y = this.y;map[y][x].type = map[y][x+1].type = map[y+1][x].type = map[y+1][x+1].type = 0;return this;},move : function(fn){       //移动, fn: 撞击之后触发函数if (this.stepLocked || this.locked || this.reliveLocked) return;    //如果被锁定if (this.toBorder(this.der, fn)) {    //如果撞到边界return;}this.freeGird();            if (this.hit(fn) == 1) return;     //如果遇到障碍this.stepLocked = true;                //加锁var der = this.der, w, d;          switch(der){                       //计算下个网格的x,ycase 0: this.x -= 1; w = 'left'; d = -2; break;case 2: this.x += 1; w = 'left'; d = 2; break;case 1: this.y -= 1; w = 'top'; d = -2; break;case 3: this.y += 1; w = 'top'; d = 2; break;}this.useGird();                      //占据网格var obj = this.obj.get(0);for (var i = 0; i < 10; i++){      //移动var closure = ~function(i, t){var s = setTimeout(function(){obj.style[w] = parseInt(obj.style[w]) + d + 'px';clearTimeout(s);if (i == 9){closure = null;t.stepLocked = false;          //移动完成的时候释放移动锁t.moveRepeat && t.move(fn);   //是否重复移动}}, i*t.speed)}(i, this);}},toBorder : function(der, fn){        //撞到边界if (der == 1 && this.y == 0 || der == 3 && this.y == 22 || der == 0 && this.x == 0 || der == 2 && this.x == 22) {if (jQuery.isFunction(fn)) fn();return true;}},probe : function(){                  //探测var x = this.x, y = this.y;var baffles = [];                   //前方障碍switch(this.der){case 0 : baffles[0] = [y, x-1]; baffles[1] = [y+1, x-1]; break;   //左case 2 : baffles[0] = [y, x+2]; baffles[1] = [y+1, x+2]; break;  //右case 1 : baffles[0] = [y-1, x]; baffles[1] = [y-1, x+1]; break;  //上case 3 : baffles[0] = [y+2, x]; baffles[1] = [y+2, x+1]; break;  //下}return baffles;}
}//--------------------------------------------------------坦克--------------------------------------function Tank(obj, speed, x, y, der){this.obj = obj;                    //spanthis.type = 5;this.speed = speed;                this.x = x;                        this.y = y;this.der = der;                    //移动方向this.fx = x;                       //初始x,坦克复活的时候使用this.fy = y;											 //初始ythis.fder = der;				   				 //初始移动方向this.clipLength = 3;               //弹夹大小,最多存放3个子弹this.clip = [];                    //弹夹this.clipLocked = false;           //弹夹锁this.fireLocked = true;           this.life = 3;this.exp = [];                     //爆炸效果this.invTime = 2000;          		//无敌时间this.reliveLocked = false;          //复活锁,复活期间不能移动
}Tank.prototype = new Mover;   //继承MoverTank.prototype.init = function(){this.setPos(this.der);                           //设置坦克方向this.setXy(this.y*20, this.x*20);       //设置位置this.useGird(this);                      //占据网格this.initClip();                         //初始化弹夹if (this.invTime) this.invincible(this.invTime);           //无敌  return this;
}Tank.prototype.initClip = function(){      //初始化弹夹for (var i = 0;i < this.clipLength; i++) {this.exp.push($('.explode').eq(0).clone().appendTo(Gb.attr('gameMap')));     //爆炸效果this.clip.push(new Ball(this, 7));}
}Tank.prototype.setPos = function(der){     //设置移动方向if (der == 0) this.der = 0;else this.der = der || this.fder;this.obj.css('background-position', '0px -'+ [3, 0, 1, 2][this.der]*40 +'px');this.bobDer = der;				               //记录子弹方向return this;
}Tank.prototype.hit = function(){           //碰撞var baffles = this.probe();              //前方物体for (var i = 0; i < baffles.length; i++){var type = map[baffles[i][0]][baffles[i][1]].type;if ( (/^2|3|4|5|6|7$/).test(type)) return 1;            //遇到障碍if (type == 'speed' || type == 'hide' || type == 'life' || type == 'power' || type == 'defense') {		if (this == mainTank || this == subTank){Gb.attr('.prop').hide();Props[type](this);    //吃道具      }}}return 0;
}Tank.prototype.fire = function(){          //开火if (this.reliveLocked || this.clipLocked == true || this.clip.length <= 0) {return;}this.clipLocked = true;              //发射后锁定弹夹this.clip.pop().init();           	 //取出一个子弹并发射var self = this;setTimeout(function(){               //子弹间隔时间self.clipLocked = false;}, 600)return this;
}Tank.prototype.relive = function(){    //复活this.life ? this.life-- : eTankLife--;if (this.showInfo() == 1){this.freeGird();if (this == mainTank){mainTank = false;}else if (this == subTank){subTank = false;}return;};this.locked = true;this.der = this.fder;var me = this;setTimeout(function(){me.freeGird();me.x = me.fx;me.y = me.fy;if( me != mainTank && me != subTank ) me.locked = false;me.reliveLocked = false;me.clipLocked = false;me.setXy(me.y*20, me.x*20);me.setPos(me.fder);me.useGird();me.invincible(me == mainTank ? 3000 : 1500);}, 500);return this;
}Tank.prototype.showInfo = function(){if ((plays == 1 && !mainTank.life) || (plays == 2 && !mainTank.life && !subTank.life)){setTimeout(function(){ $('#gameOver').show(); return}, 1000);}var ary = this == mainTank ? [Gb.attr('P1'), '1P'] : [Gb.attr('P2'), '2P'];ary[0].html(ary[1]+' *  ' +this.life);if (this.life <= 0) return 1;
}Tank.prototype.invincible = function(time){             //坦克无敌this.invTime = time;var i = 0, me = this;var u = setInterval(function(){me.obj[i++ % 2 == 0 ? 'show' : 'hide']();if (i >= time/150){me.obj.show();	me.invTime = 0;clearTimeout(u);}}, 150);
}//---------------------------------------------敌方坦克-----------------------------------------------
var ETank = function(obj, speed, x, y, der){this.obj = obj;                    //spanthis.speed = speed;this.x = x;this.y = y;this.type = 6;this.der = der;this.fx = x;this.fy = y;this.fder = der;this.life = false;this.clip = [];                    //弹夹this.exp = [];                     //爆炸效果this.invTime = 0;          		   //无敌状态
}ETank.prototype = new Tank;ETank.prototype.showInfo = function(){$('.etankSam').eq(0).remove();if (eTankLife <= 0){if (level == 3){alert ('没有地图了,算你过关  - -!');window.location.reload();return;}level++;setTimeout(function(){mapReload()}, 100);return 1;}if (eTankLife <= eTanksLength-1){this.freeGird();return 1;}
}ETank.prototype.Ai = function(){this.move();var self = this;var m = Math.round(Math.random()*100);var ary = $.grep([0,1,2,3,3,2,3,1], function(n, i){return n != self.der;});var len = ary.length;          for (var i = 0 ; i < len ; i++){        //洗牌,下一次的方向var num = parseInt(Math.random()*len);var tmp = ary[num];ary[num] = ary[i];ary[i] = tmp;}var nextDer = ary[0];if (this.toBorder(this.der) || this.hit() == 1){var s1 = setTimeout(function(){self.setPos(nextDer).fire();self.move();var s2 = setTimeout(function(){self.Ai();clearTimeout(s2);}, 400)clearTimeout(s1);}, 400);return;}if (m < 20){this.setPos(nextDer).fire();}else if (m < 60) this.fire();var s3 = setTimeout(function(){self.Ai();clearTimeout(s3);}, 200)
}
//----------------------------------------------------------------------------------------------------
//---------------------------------------------------------炮弹---------------------------------------function Ball(pTank, speed){this.obj = $('.ball').eq(0).clone().appendTo(Gb.attr('gameMap'));this.speed = speed;this.pTank = pTank;this.type = 10;this.moveRepeat = true;
}Ball.prototype = new Mover;Ball.prototype.init = function(){this.reviseXy(); var self = this;this.move(function(){self.freeGird();self.explode();self.recover();        //爆炸并回收子弹});self.pTank.useGird();              //还原坦克所占网格
}Ball.prototype.reviseXy = function(){          //调整子弹位置var x = this.x = this.pTank.x, y = this.y = this.pTank.y;this.der = this.pTank.bobDer || 0;  //确认子弹发射方向switch(this.der){case 0: x -= 1; break;  //左  case 1: y -= 1; break;  //上case 2: x += 1; break;  //右case 3: y += 1; break;  //下}this.setXy(y*20, x*20);
}Ball.prototype.hit = function(fn){var ret = 0;var baffles = this.probe();                //前方物体for (var i = 0; i < baffles.length; i++){var y = baffles[i][0], x = baffles[i][1], baffle = map[y][x], type = baffle.type, span = baffle.span;if (type == 'speed' || type == 'hide' || type == 'life' || type == 'power' || type == 'defense'){   //击中道具if ($.isFunction(fn)) { fn()};      //爆炸this.clearUi(y, x, span);Gb.attr('.prop').hide();            //隐藏物品return 1;	}if ((/^2|3|4|5|6|7$/).test(type)) {      //爆炸if (type == 4) {this.freeGird().recover();          //击中海洋,回收子弹但不爆炸.return 1;}if (type == 6 && this.pTank.type == 6) {     //敌方坦克互相击中无效this.freeGird().recover();return 1;}if (type == 5 || type == 6) {if (span.invTime) {                       //如果处在无敌状态this.freeGird().recover();              //回收子弹但不爆炸.return 1;}if ($.isFunction(fn)) { fn()};span.obj.hide();span.reliveLocked = true;span.invTime = 1; //无敌span.relive(); //坦克复活return 1;}if ($.isFunction(fn)) { fn()};if (type == 7) { $('#gameOver').show(); return};if (type == 2 || (this.type == 11 && type == 3)) {this.clearUi(y, x, span);       //清除砖块ret = 1;}else if (type == 3){return 1;}}}return ret;
}Ball.prototype.explode = function(){              //子弹爆炸var explode = this.pTank.exp.pop();if (!explode) return;var x = this.x, y = this.y, der = this.der;           der == 0 ? x -= 1 : (der == 1 ? y -= 1 : '');		//调整爆炸位置explode.show().css( {top: y*20, left: x*20} );var m = Math.random()>.2;for (var i = 0; i < 8; i++){var closure = ~function(i, t){var s = setTimeout(function(){explode.css('background-position', '0px -'+i*60+'px');if (i == 7) {explode.hide();t.pTank.exp.push(explode);}clearTimeout(s);closure = null;}, (m ? Math.sqrt(i): i*1.2)*100)}(i, this);}return this;
};Ball.prototype.clearUi = function(y, x, span){map[y][x].type = 0;if (span.length) span.attr('className', 'aa');
}Ball.prototype.recover = function(){         //回收子弹this.obj.css('left', '-1000px');           //扔到屏幕外var clip = this.pTank.clip;if(clip.length < 3) clip.push(this);       //回收子弹,重新装入弹夹
}//------------------------------------------道具-----------------------------------------------$(document).ready(function(){Gb.attr($('#gameMap'), 'gameMap');$('#bottomBg img').each(function(i){$(this).click(function(){plays = i == 0 ? 1 : 2;$('#gameBg').remove();createMap();});$(this).hover(function(){$(this).attr('src', i == 0 ? 'img/play12.jpg' : 'img/play22.jpg');},function(){$(this).attr('src', i == 0 ? 'img/play11.jpg' : 'img/play21.jpg');})});$(document).keydown(function(event){var k = event.keyCode;if ( (/^65|87|68|83$/).test(k) ) {mainTank.der = {'65':0,'87':1,'68':2,'83':3}[k];mainTank.locked = false;}if (k == 32) mainTank.fireLocked = false;if (plays == 1) return;if ( (/^37|38|39|40$/).test(k) ) {subTank.der = k - 37;subTank.locked = false;}if (k == 76) subTank.fireLocked = false;})$(document).keyup(function(event){var k = event.keyCode;if ( (/^65|87|68|83$/).test(k) ) mainTank.locked = true;if (k == 32) mainTank.fireLocked = true;if (plays == 1) return;if ((/^37|38|39|40$/).test(k) ) subTank.locked = true;if (k == 76) subTank.fireLocked = true;})})function createMap(){var _class = ['aa', 'wall', 'ston', 'steel', 'sea'];map = maps[level-1];$(map).each(function(i, n){$(n).each(function(j, n){map[i][j] = { type : n, span : $('<span class='+_class[n]+'></span>').appendTo(Gb.attr('gameMap'))};})})$('<span class=AC></span>').appendTo(Gb.attr('gameMap'));$('<span class=tank></span>').appendTo(Gb.attr('gameMap'));$('<span class=etank></span>').appendTo(Gb.attr('gameMap'));$('<span class=ball></span>').appendTo(Gb.attr('gameMap'));$('<span class=explode></span>').appendTo(Gb.attr('gameMap'));$('<span class=props></span>').appendTo(Gb.attr('gameMap'));Gb.attr($('#infoBottom'), '#infoBottom').attr($('.props'), '.prop').attr($('#gameInfo'), 'gameInfo').attr($('.tank'), '.tank').attr($('.etank'), '.etank').attr('$(.ball)', '.ball');$('.AC').css({top : '440px',left : '240px'});mainTank = new Tank(Gb.attr('.tank'), 15, 8, 22, 1).init();mainTank.locked = true;if (plays == 2){subTank = new Tank(Gb.attr('.tank').clone().appendTo(Gb.attr('gameMap')), 15, 16, 22, 1).init();subTank.locked = true;}for (var i = 0; i < eTanksLength; i++){var x = xs[level -1];eTanks[i] = new ETank(Gb.attr('.etank').eq(0).clone().appendTo(Gb.attr('gameMap')), 20, x[i], 0, 3).init().Ai();}for (var i = 0; i < eTankLife; i++){$('<span class=etankSam></span>').appendTo(Gb.attr('gameInfo'));}$('<span class=play1>1P *  ' +mainTank.life+ '</span>').appendTo(Gb.attr('#infoBottom'));if (plays == 2) $('<span class=play2>2P *  ' +subTank.life+ '</span>').appendTo(Gb.attr('#infoBottom'));$('<span class=level>第 ' +level+ ' 关</span>').appendTo(Gb.attr('#infoBottom'));Gb.attr($('.play1'), 'P1').attr($('.play2'), 'P2');Props.init();   //道具初始化u = setInterval(function(){if (mainTank) mainTank.setPos(mainTank.der).move();if (mainTank && !mainTank.fireLocked) mainTank.fire();if (plays == 1) return;if (subTank) subTank.setPos(subTank.der).move();if (subTank && !subTank.fireLocked) subTank.fire();}, 19);}var Props = {          //道具类Ui : [0, 0],init : function(){setInterval(function(){if (Props.use) {Gb.attr('.prop').hide();Props.use = false;return;}var fn = ['speed', 'hide', 'life', 'power', 'defense'][Math.round(Math.random()*4)];var Ui = Props.getUi();Props.Ui = Ui;map[Ui[0]][Ui[1]].type = fn;Props.use = true;Gb.attr('.prop').css({'background' : 'url(img/'+ fn +'.jpg)', top : Ui[0]*20, left : Ui[1]*20} ).show();}, Math.max(10000, Math.round(Math.random()*20000)));},use : false,speed : function(obj){obj.speed = obj.speed / 2;setTimeout(function(){obj.speed = obj.speed * 2;Props.use = false;map[Props.Ui[0]][Props.Ui[1]].type = 0;}, 15000);},hide : function(obj){obj.invincible(5000);setTimeout(function(){Props.use = false;map[Props.Ui[0]][Props.Ui[1]].type = 0;}, 10000);},life : function(obj){obj.life++;obj.showInfo();Props.use = false;map[Props.Ui[0]][Props.Ui[1]].type = 0;},power : function(obj){for (var i = 0; i < obj.clip.length; i++){obj.clip[i].type = 11;}setTimeout(function(){for (var i = 0; i < obj.clip.length; i++){obj.clip[i].type = 10;}}, 10000)	},defense : function(obj){var ary = [[21, 11], [21, 12], [21, 13], [21, 14], [22, 11], [22, 14], [23, 11], [23, 14]];for (var i = 0; i < ary.length; i++){var y = ary[i][0], x = ary[i][1];map[y][x].type = 3;map[y][x].span.attr('className', 'steel');}setTimeout(function(){for (var i = 0; i < ary.length; i++){var y = ary[i][0], x = ary[i][1];map[y][x].type = 2;map[y][x].span.attr('className', 'ston');}}, 15000)},fn : false,getUi : function(){var i = Math.round(Math.random()*23);var j = Math.round(Math.random()*23);if (map[j][i].type == 0) {return [j, i];}else {return this.getUi();}}
}function mapReload(){Gb.attr('gameMap').empty();Gb.attr('#infoBottom').empty();$(document).keydown(function(event){return false;});$(document).keyup(function(event){return false;});clearInterval(u);mainTank = null;subTank = null;eTanks = [];eTankLife = 20;map = maps[level-1];eTanksLength++;if (level == 3) {eTanksLength = 12;xs[2] = [0,2,4,6,8,10,12,14,16,18,20,22];}createMap();}}();</script><style>html, body{overflow:hidden}#game{width:650px;margin:0 auto;overflow:hidden;position:relative;height:600px;}#gameBg{height:480px;width:650px;margin:3px auto;border:10px ridge #eee;background:#000;overflow:hidden;position:absolute;left:00px;top:8%;z-index:1000}#gameBg div {width:100%;height:50%}#gameBg #topBg img {margin:30px auto;display:block}#gameBg #bottomBg img {margin:20px auto;display:block;cursor:pointer;height:40px;width:150px}#gameMap{height:480px;width:480px;margin:3px auto;border:10px ridge #eee;background:#000;overflow:hidden;position:absolute;left:00px;top:8%;float:left}#gameInfo{height:480px;width:150px;margin:3px auto;border:10px ridge #eee;background:#000;overflow:hidden;position:absolute;left:490px;top:8%}#gameMap span{width:20px;height:20px;float:left}#gameMap span.steel{background:url(img/steel.gif) no-repeat}#gameMap span.sea{background:url(img/sea.gif) no-repeat}#gameMap span.wall{background:url(img/wall.gif) no-repeat;position:relative;z-index:104}#gameMap span.ston{background:url(img/ston.gif) no-repeat}#gameMap span.tank{position:absolute;background:url(img/tank.gif) no-repeat; width:40px; height:40px;z-index:101}#gameMap span.etank{background:url(img/etank.gif) no-repeat; position:absolute; width:40px; height:40px;z-index:101}#gameMap span.ball{background:url(img/ball.gif) no-repeat; position:absolute; width:40px; height:40px;z-index:103}#gameMap span.aa{background:url(); width:20px; height:20px}#gameMap span.explode{background:url(img/explode.gif) no-repeat; position:absolute; width:60px; height:60px;z-index:103}#gameMap span.props{background:url(); width:20px; height:20px; position:absolute;z-index:101}#gameMap span.info{position:absolute; width:60px; height:60px; top:100;left:100;z-index:102}#gameMap span.AC{background:url(img/1.gif) no-repeat;position:absolute; width:40px; height:40px;z-index:102}#gameInfo span.etankSam{background:url(img/etank.gif) no-repeat 0px -80px; width:40px; height:40px;float:left;margin-right:10px}#gameInfo span.play1, .play2{background:url(img/tank.gif) no-repeat; width:100%; height:40px;float:left;margin-top:25px;margin-left:10px;color:#fff;text-indent:60px;Font-weight:bold;font-size:1.2em;line-height:40px}#gameInfo span.level{width:100%;height:30px;float:left;margin-top:20px;color:#fff;text-align:center;font-weight:bold;font-size:1.2em;line-height:30px;letter-spacing:5px}#gameInfo #infoBottom{position:absolute; width:100%; height:200px; top:295px;left:0px}#gameOver{height:480px;width:650px;margin:3px auto;border:10px ridge #eee;background:#000;overflow:hidden;position:absolute;left:0px;top:8%;display:none;z-index:1001}#gameOver img{height:100%;width:100%}#desc img{width:100%;}
</style>
</head><body><div id="game"><div id="gameBg"><div id="topBg"><img src="img/bg.jpg"></img></div><div id="bottomBg"><img src="img/play11.jpg"></img><img src="img/play21.jpg"></img></div></div><div id="gameMap"> </div><div id="gameInfo"> <div id="infoBottom"></div></div><div id="gameOver"><img src="img/gameover.jpg"></img></div><div id="desc">说明:js版坦克大战, 主坦克方向:WASD,空格发射炮弹; 副坦克方向:上下左右,L发射炮弹.</div>
</div></body></html>

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/444615.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

windows安装 MySQL5.7服务端

1,安装https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.30-winx64.zip mysql安装包。 2. 自己配置my.ini [client] port=3306 [mysql] default-character-set=utf8[mysqld] character-set-server=utf8 port=3306 basedir="D:/mysql-5.7.30-winx64/" datad…

screen命令使用说明

有些程序写的很操蛋&#xff0c;比如放到后台执行&#xff0c;但后边还需要再切回前台来重新执行&#xff0c;这个时候我们选择screen工具&#xff1a; screen -d -m -S LoginServer[6001] ./run_login_server.sh 具体的screen命令包含哪些参数&#xff0c;可以参考scree…

看这玩意复习你还会挂科?《数据结构篇》

一&#xff0e;绪论 1.何谓程序设计&#xff1f; 程序 算法 数据结构 2.数据结构的定义 是相互之间存在一种或多种特定关系的数据元素的集合 3.数据、数据元素、数据对象的概念 数据&#xff08;data&#xff09;&#xff1a;对客观事物的符号表示&#xff0c;含义很广&am…

苹果订阅服务器端开发

有时候我们想做一个苹果订阅功能,需要在苹果开发者后台添加订阅商品productid/ 订阅需要增加一个参数: password: 秘钥, 就可以了, 但是官方文档说秘钥仅仅用在自动续订上面 大家叫后台加个验证,如果苹果验证返回21004的话(21004 你提供的共享密钥和账户的共享密钥不一致)…

nginx代理配置根据ip地址来转发到不同的地址端口

最近我们在开发的某SLG游戏的某业务要做如下场景: 要求在全球各个区域访问离他最近的服务器节点:用户通过访问域名A,在服务器端解析用户来源,根据ip地址来源来转发到对应的最近的服务器节点。 由于我们之前的业务一些设计很难调整,所以我将通过代码层面来进行做转发处理,…

做了nginx反向代理之后常见问题汇总

1.客户端无缘无故的主动断开和服务器的连接&#xff0c;如图&#xff1a; 服务器端收到了FIN包&#xff0c;查看了nginx 的配置有个选项&#xff1a;proxy_timeout选项 设置为30s。 注意&#xff1a;“proxy_timeout”这个参数可以写在stream节点下&#xff0c;所有server都生效…

在GoogPlay上发布的包Facebook登录失败提示签名问题

在googplay提审的包发布后,发现Facebook登录功能异常,提示如下: 意识到可能是hashkey出问题了,但是之前测试都是好的,原来是上传包到googlePlay后有个二次签名,会修改hashkey的,所以需要在Facebook后台添加下重新签名的hashkey。 基本签名信息在Google Play 上都能查看…

根据当前docker容器生成镜像提交到远端服务器

docker commit 4d6883e5fa21 gaoke/koa_ios docker push gaoke/koa_ios 然后在远端可看到

2019我做成的事情

1、ccpc河北金 这个省赛可能是退役赛了&#xff0c;因为下半年写项目&#xff0c;明年实习&#xff0c;没机会参加省赛、区预赛了。 2019.5大二的时候参加的&#xff0c;记得敲了个区间dp&#xff0c;大模拟&#xff0c;队友数学没搞出来&#xff0c;有一个搜索也是胆子不够大…

TCP: request_sock_TCP: Possible SYN flooding on port 80. Sending cookies. Check SNMP counters

最近老发现服务器丢包严重,想通过ssh登录查看原因,但是仍然失败,后来重启云服务器后通过单用户模式进入查看系统日志: TCP: request_sock_TCP: Possible SYN flooding on port 80. Sending cookies. Check SNMP counters 系统的内存,CPU资源是没问题的,足够当前的业务量…

Redis你不得不探索的11个问题

1. 说说Redis基本数据类型有哪些吧 字符串&#xff1a;redis没有直接使用C语言传统的字符串表示&#xff0c;而是自己实现的叫做简单动态字符串SDS的抽象类型。C语言的字符串不记录自身的长度信息&#xff0c;而SDS则保存了长度信息&#xff0c;这样将获取字符串长度的时间由O(…

折纸的折痕(RVL中序遍历)

这个题我见到过不止一次。笔试面试。 你拿个纸折一折会发现是这样的&#xff1a; 这棵树左子树是纸的下半部分&#xff0c;右子树是纸的上半部分。 下折痕指的是折痕突起的方向是纸的背面。 可以看出折痕是一棵满二叉树&#xff0c;根节点是下折痕&#xff0c;每一棵子树的左…

动态规划做多了以后,总结的相关知识

动态规划 Dynamic Programming DP 准则 动态规划的本质&#xff0c;是对问题状态的定义和状态转移方程的定义。 动态规划是通过拆分问题&#xff0c;定义问题状态和状态之间的关系&#xff0c;使得问题能够以递推&#xff08;或者说分治&#xff09;的方式去解决。 如何拆分…

(十三) 深入浅出TCPIP之TCP套接字参数

专栏其他文章&#xff1a; 理论篇&#xff1a; &#xff08;一&#xff09;深入浅出TCPIP之理解TCP报文格式和交互流程 (二&#xff09;深入浅出TCPIP之再识TCP&#xff0c;理解TCP三次握手&#xff08;上&#xff09; (三&#xff09;深入浅出TCPIP之再识TCP&#xff0c;理解…

Linux必懂知识大总结(上)

CPU top top&#xff1a;查看每个进程的情况 在top模式下&#xff0c;输入1&#xff1a;查看每个CPU的性能数据&#xff0c;注意观察是否有CPU100%占用率 CPU参数含义&#xff1a; 1&#xff09;us过高表示Java应用程序消耗了大量CPU&#xff0c;需要定位是哪一个线程&#x…

如何抓住QQ小游戏买量红利:休闲与内购小游戏买量优化方法分享

2019年5月&#xff0c;Qzone小游戏、玩一玩整合升级为全新QQ小游戏平台&#xff0c;其以开放的社交生态和关系链&#xff0c;为开发者带来了巨大的流量红利。 为了帮助更多开发者适应和了解新市场。本文将介绍QQ小游戏投放规模现状以及各项扶持政策&#xff0c;并解读轻度小游…

(一)容器从入门到深入-容器和镜像

一、容器与镜像 什么是容器&#xff1f; 在介绍容器的具体概念之前&#xff0c;先简单回顾一下操作系统是如何管理进程的。 首先&#xff0c;当我们登录到操作系统之后&#xff0c;可以通过 ps 等操作看到各式各样的进程&#xff0c;这些进程包括系统自带的服务和用户的应用…

记一次海外大型SLG游戏服务器进程被OOM的修复经历

事情经过 最近刚接手一个多次获得海外GooglePlay推荐的SLG的游戏项目,服务器是java的netty框架写的,客户端是cocos lua。 好吧既然服务器进程运行在jvm之上,吃内存倒是挺厉害的,我一个16G内存的服务器被吃的满满的,这个时候为了解决内存不足,我开启了4G的虚拟内存,方法…

(一)nodejs循序渐进-nodejs环境安装(基础篇)

目录 Node Node的优点 Node.js 安装配置 使用nvm管理不同版本的 node 与 npm nvm 与 n 的区别 卸载全局安装的 node/npm Windows 安装 Linux 安装 安装多版本 node/npm 在不同版本间切换 列出已安装实例 在多环境中&#xff0c;npm该如何使用呢&#xff1f; 其他命…

(二)nodejs循序渐进-nodejs基本类型和循环条件语法篇(基础篇)

目录 入门之helloworld 进阶之helloworld http服务器 步骤一、引入 required 模块 步骤二、创建服务器 基本语法篇 变量声明 基础类型 if else 循环语句 for for ... in while do和do while 运算符 加减乘除 , , !, ! typeof null&#xff0c;undefine…