最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

基于jquery的地址欄射擊游戲代碼

 更新時(shí)間:2011年03月10日 12:07:37   作者:  
地址欄射擊游戲!對(duì),你沒看錯(cuò),就是在地址欄上玩的游戲,有圖有真相!之前在網(wǎng)上看到這個(gè)小游戲,可惜在墻外,中午研究了一下,搬到國(guó)內(nèi)來(lái)了,看看吧!
演示地址:http://demo.jb51.net/js/2011/hunt/index.htm

玩法向下看
請(qǐng)看地址欄上的字母 O! 你使用O來(lái)向 a射擊。 使用鍵盤上的 左箭頭 和 右箭頭 移動(dòng)字母O. 當(dāng)O移動(dòng)到 a 上時(shí),按 空格鍵射擊! 游戲會(huì)定時(shí)30秒時(shí)間,按ESC鍵重新開始。
注:請(qǐng)使用系統(tǒng)自帶的IE瀏覽器來(lái)打開本鏈接。

你使用O來(lái)向 a射擊。 使用鍵盤上的 左箭頭 和 右箭頭 移動(dòng)字母O. 當(dāng)O移動(dòng)到 a 上時(shí),按 空格鍵射擊! 

核心代碼:
復(fù)制代碼 代碼如下:

(function() {
var Animal, Game;
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
Game = (function() {
function Game() {
this.eventReceived = __bind(this.eventReceived, this);;
this.update = __bind(this.update, this);; this.level = 1;
this.levelSize = 60;
this.playerLocation = this.levelSize / 2;
this.start();
}
Game.prototype.start = function() {
var num;
this.points = 0;
this.startTime = new Date;
this.timeLimit = 30;
this.animals = [];
for (num = 4; num >= 1; num--) {
this.addAnimal();
}
return this.interval = setInterval(this.update, 1000 / 30);
};
Game.prototype.gameOver = function() {
clearInterval(this.interval);
return location.hash = "在" + (this.elapsedTime()) + "秒中你共射中了" + this.points + "個(gè)a! (按ESC鍵重新開始)";
};
Game.prototype.elapsedTime = function() {
return Math.floor(((new Date).getTime() - this.startTime.getTime()) / 1000);
};
Game.prototype.addAnimal = function() {
var animal;
animal = new Animal(Math.floor(Math.random() * this.levelSize));
return this.animals.push(animal);
};
Game.prototype.removeAnimal = function(deadAnimal) {
var animal;
return this.animals = (function() {
var _i, _len, _ref, _results;
_ref = this.animals;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
animal = _ref[_i];
if (animal !== deadAnimal) {
_results.push(animal);
}
}
return _results;
}).call(this);
};
Game.prototype.isAnimalAt = function(position) {
var animal, matches;
matches = (function() {
var _i, _len, _ref, _results;
_ref = this.animals;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
animal = _ref[_i];
if (Math.floor(animal.position) === position) {
_results.push(animal);
}
}
return _results;
}).call(this);
return matches[0];
};
Game.prototype.update = function() {
var animal, position, timeLeft, url, _i, _len, _ref;
url = [];
_ref = this.animals;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
animal = _ref[_i];
animal.update(this.levelSize);
}
while (url.length < this.levelSize) {
position = url.length;
if (position === this.playerLocation) {
if (this.isAnimalAt(this.playerLocation)) {
url.push("@");
} else {
url.push("O");
}
} else if (this.isAnimalAt(position)) {
url.push("a");
} else {
url.push("-");
}
}
timeLeft = this.timeLimit - this.elapsedTime();
if (timeLeft <= 0) {
return this.gameOver();
} else {
if (timeLeft < 10) {
timeLeft = "0" + timeLeft;
}
location.hash = (" " + timeLeft + "|") + url.join("") + ("|" + timeLeft);
return document.title = "Points " + this.points;
}
};
Game.prototype.eventReceived = function(event) {
var animal;
switch (event.which) {
case 37:
this.playerLocation -= 1;
if (this.playerLocation < 0) {
return this.playerLocation = this.levelSize - 1;
}
break;
case 39:
this.playerLocation += 1;
return this.playerLocation %= this.levelSize;
case 38:
case 32:
animal = this.isAnimalAt(this.playerLocation);
if (animal) {
this.points += 1;
this.removeAnimal(animal);
console.log(this.animals.length);
if (this.animals.length === 0) {
return this.gameOver();
}
}
break;
case 27:
return this.start();
}
};
return Game;
})();
Animal = (function() {
function Animal(position) {
this.position = position;
this.velocityChange = Math.random() * 0.5;
this.velocityIndex = Math.random() * Math.PI;
this.dampener = 0.4;
}
Animal.prototype.update = function(levelSize) {
this.velocityIndex += Math.random() * this.velocityChange;
this.position += Math.sin(this.velocityIndex) * this.dampener;
this.position %= levelSize;
if (this.position < 0) {
return this.position += levelSize;
}
};
return Animal;
})();
$(function() {
var game;
game = new Game();
return $(document).keydown(game.eventReceived);
});
}).call(this);

相關(guān)文章

最新評(píng)論

晋宁县| 五家渠市| 濮阳县| 瑞安市| 云阳县| 新竹县| 肇州县| 高邑县| 庆安县| 庐江县| 海城市| 馆陶县| 禄丰县| 罗田县| 来安县| 绍兴市| 饶河县| 洛南县| 芦山县| 建德市| 宁河县| 渝中区| 依安县| 盐源县| 西乌珠穆沁旗| 孝昌县| 大同市| 翁源县| 宁安市| 青神县| 乌兰浩特市| 彰化市| 安庆市| 德阳市| 乌恰县| 东港市| 宁津县| 宣威市| 静宁县| 桦南县| 德兴市|