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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,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.pswp.cn/news/444615.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/444615.shtml
英文地址,請注明出處:http://en.pswp.cn/news/444615.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

ubuntu nginx配置負載均衡篇(二)

這里提供部分我的配置文件: nginx.conf: user www-data; worker_processes auto; pid /run/nginx.pid; include /etc/nginx/modules-enabled/*.conf;events {worker_connections 768;# multi_accept on; }http {### Basic Settings##sendfile on;tcp_nopush on;tcp_nodelay…

Papar Notes List

PaperNotes(1)-Modeling the World from Internet Photo Collections PaperNotes(2)-Generative Adversarial Nets PaperNotes(3)-圖像分割-RCNN-FCN-Boxsup PaperNotes(4)-高質量圖像生成-cgan,stackgan,lapgan,cyclegan,pix2pixgan PaperNotes(5)-Conditional Generative Adv…

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…

Machine Learning List

機器學習&#xff1a; 每多加一個符號&#xff0c;就多加一個變量。 每次確定給定量&#xff0c;其余均可變&#xff0c;方便分析問題。 MachineLearning(1)-激活函數sigmoid、損失函數MSE、CrossEntropyLoss MachineLearning(2)-圖像分類常用數據集 MachineLearning(3)-流型 …

反編譯用unity打包的資源文件

如何反編譯破解別人家的游戲包,美術資源是維權和侵權一直杠下去的話題,如果作為商業用途,我是反對破壞原作者的創意,侵害作者的勞動果實行為。但是如果是僅僅為了學習,實驗,不妨參考我的文章,我相信你可以從我的文章里獲取如何破解通過unity打包的移動游戲美術資源。 之…

看這玩意復習你還會掛科?《網絡原理篇》

第一章 概述 計算機網絡的功能 連通性、共享 【連通性&#xff1a;是計算機網絡使上網用戶之間都可以交換信息&#xff0c;好像這些用戶的計算機都可以彼此直接連接一樣。用戶之間的距離也似乎因此而變近了。共享&#xff1a;是指資源共享&#xff0c;它的含義是多方面的&…

蘋果訂閱服務器端開發

有時候我們想做一個蘋果訂閱功能,需要在蘋果開發者后臺添加訂閱商品productid/ 訂閱需要增加一個參數: password: 秘鑰, 就可以了, 但是官方文檔說秘鑰僅僅用在自動續訂上面 大家叫后臺加個驗證,如果蘋果驗證返回21004的話(21004 你提供的共享密鑰和賬戶的共享密鑰不一致)…

Mysql服務器線上配置主從同步

我們一般在線上搭建MYSQL都會部署一套主從同步方案: 當master(主)庫的數據發生變化的時候,變化會實時的同步到slave(從)庫。 主從復制的過程: Mysql同步過程的第一部分就是master服務器記錄二進制日志。在每個事務更新數據完成之前,master在二日志記錄這些改變。MySQL將事…

nginx代理配置根據ip地址來轉發到不同的地址端口

最近我們在開發的某SLG游戲的某業務要做如下場景: 要求在全球各個區域訪問離他最近的服務器節點:用戶通過訪問域名A,在服務器端解析用戶來源,根據ip地址來源來轉發到對應的最近的服務器節點。 由于我們之前的業務一些設計很難調整,所以我將通過代碼層面來進行做轉發處理,…

看這玩意復習你還會掛科?《web開發1篇》

#第一章 Web基礎知識 Web開發基本概念 1、萬維網是一個由許多相互鏈接的超文本組成的系統&#xff0c;通過互聯網訪問。 2、web&#xff1a;worldwideweb&#xff0c;萬維網&#xff0c;簡稱web&#xff0c;www&#xff0c;通常稱為網頁。 3、web開發&#xff1a;進行網頁頁…

如何禁止掉root登錄,使用key密鑰登錄

在Linux系統下執行命令&#xff1a; ssh-keygen -t rsa cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys vim /etc/ssh/sshd_config AuthorizedKeysFile .ssh/authorized_keys RSAAuthentication yes PubkeyAuthentication yes PasswordAuthentication n…

編譯原理end

#include<bits/stdc.h> using namespace std;const int max_word 505; //關鍵字 const char keyWord[13][20] {"main","if","else","do","while","for","switch", "case","int…

做了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 上都能查看…

JDK和Spring中的設計模式

JDK中的設計模式&#xff08;17&#xff09; 創建型 1&#xff09;工廠方法 Collection.iterator() 由具體的聚集類來確定使用哪一個Iterator 2&#xff09;單例模式 Runtime.getRuntime() 3&#xff09;建造者模式 StringBuilder 4&#xff09;原型模式 Java中的Clon…

解決蘋果發布正式環境后支付拉不起來或獲取商品列表為空問題

最近在海外蘋果商店發布新游戲,經歷了一個操蛋的兩天: 產品在提交testflight沙盒環境下是可以獲取到蘋果商品列表,并且測試支付可以拉起并到賬,等到我通過TF轉發布到正式環境后,游戲點擊游戲內商店獲取商品列表就為空,更別提拉起支付了。 最開始先檢查了蘋果開發者后臺的…

根據當前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;有一個搜索也是膽子不夠大…