欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時(shí)間:2011年03月10日 12:07:37   作者:  
地址欄射擊游戲!對(duì),你沒(méi)看錯(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)文章

  • jQuery Validate初步體驗(yàn)(一)

    jQuery Validate初步體驗(yàn)(一)

    jQuery 是一個(gè)快速、簡(jiǎn)單的JavaScript library, 它簡(jiǎn)化了HTML 文件的traversing,事件處理、動(dòng)畫、Ajax 互動(dòng),從而方便了網(wǎng)頁(yè)制作的快速發(fā)展。 jQuery 是為改變你編寫JavaScript 的方式而設(shè)計(jì)的,本文給大家分享jquery validate初步體驗(yàn)(一),感興趣的朋友一起學(xué)習(xí)吧
    2015-12-12
  • 即將發(fā)布的jQuery 3 有哪些新特性

    即將發(fā)布的jQuery 3 有哪些新特性

    本文主要介紹jQuery 3中一些新增的特性和一些變更的特性,以及一些廢棄刪除的特性,另外介紹了jQuery 3.0 最大的變化就是徹底放棄對(duì) IE8 的支持,大家可以先看一下。
    2016-04-04
  • jquery追加元素的所有方法全面深入實(shí)例講解(append、prepend、after、before、wrap等等)

    jquery追加元素的所有方法全面深入實(shí)例講解(append、prepend、after、before、wrap等等)

    幾乎所有網(wǎng)站的開發(fā)都離不開jQuery,jQuery可以很方便的實(shí)現(xiàn)網(wǎng)頁(yè)中的一些效果,也很輕松的對(duì)網(wǎng)頁(yè)中的一些DIV元素進(jìn)行添加,修改或刪除的操作。由于不同位置追加元素的代碼不一樣,本文實(shí)例講解如何對(duì)網(wǎng)頁(yè)中某個(gè)指定的DIV進(jìn)行元素的追加操作。
    2023-03-03
  • 基于jQuery替換table中的內(nèi)容并顯示進(jìn)度條的代碼

    基于jQuery替換table中的內(nèi)容并顯示進(jìn)度條的代碼

    這個(gè)例子使我更加明白呈現(xiàn)數(shù)據(jù)是前端工作滴一部分,如何使table中的數(shù)值變?yōu)榍逦貤l狀圖呢?聽我細(xì)細(xì)道來(lái)
    2011-08-08
  • 簡(jiǎn)單實(shí)現(xiàn)jQuery彈窗效果

    簡(jiǎn)單實(shí)現(xiàn)jQuery彈窗效果

    這篇文章主要教大家簡(jiǎn)單實(shí)現(xiàn)jQuery彈窗效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-10-10
  • uploadify多文件上傳參數(shù)設(shè)置技巧

    uploadify多文件上傳參數(shù)設(shè)置技巧

    uploadify插件配置實(shí)用比較簡(jiǎn)單,很多開發(fā)者都喜歡使用。但是它有個(gè)缺點(diǎn)就是剛加載的時(shí)候稍微慢了一秒左右,本文通過(guò)一段代碼實(shí)例給大家介紹uploadify多文件上傳參數(shù)設(shè)置技巧,朋友們一起學(xué)習(xí)吧
    2015-11-11
  • JQuery文本框高亮顯示插件代碼

    JQuery文本框高亮顯示插件代碼

    JQuery 中沒(méi)有文本框高亮顯示這個(gè)插件,自己今天寫了一個(gè)Plugin,把代碼貼出來(lái)分享一下
    2011-04-04
  • jQuery使用手冊(cè)之二 DOM操作

    jQuery使用手冊(cè)之二 DOM操作

    jQuery使用手冊(cè)之二 DOM操作...
    2007-03-03
  • NiftyCube——輕松實(shí)現(xiàn)圓角邊框

    NiftyCube——輕松實(shí)現(xiàn)圓角邊框

    這篇文章主要介紹了NiftyCube——輕松實(shí)現(xiàn)圓角邊框
    2007-02-02
  • 解決jquery版本沖突的有效方法

    解決jquery版本沖突的有效方法

    這篇文章主要介紹了解決jquery版本沖突的有效方法,對(duì)于web設(shè)計(jì)的兼容性調(diào)試很有借鑒價(jià)值,需要的朋友可以參考下
    2014-09-09

最新評(píng)論