html
在和龍等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供網(wǎng)站制作、成都網(wǎng)站設(shè)計 網(wǎng)站設(shè)計制作定制設(shè)計,公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),品牌網(wǎng)站制作,全網(wǎng)整合營銷推廣,成都外貿(mào)網(wǎng)站建設(shè)公司,和龍網(wǎng)站建設(shè)費(fèi)用合理。
head
title貪吃蛇 Snake v2.4/title
style
body{
font-size:9pt;
}
table{
border-collapse: collapse;
border:solid #333 1px;
}
td{
height: 10px;
width: 10px;
font-size: 0px;
}
.filled{
background-color:blue;
}
/style
/head
script
function $(id){return document.getElementById(id);}
/**************************************************************
* javascript貪吃蛇 v2.4 br /
* author: sunxing007 05/14/2009br /
* 轉(zhuǎn)載請注明來自 謝謝!br /
* v2.4修正了蛇身顏色可以隨著蛇前進(jìn)而移動
**************************************************************/
//貪吃蛇類
var Snake = {
tbl: null,
/**
* body: 蛇身,數(shù)組放蛇的每一節(jié),
* 數(shù)據(jù)結(jié)構(gòu){x:x0, y:y0, color:color0},
* x,y表示坐標(biāo),color表示顏色
**/
body: [],
//當(dāng)前移動的方向,取值0,1,2,3, 分別表示向上,右,下,左, 按鍵盤方向鍵可以改變它
direction: 0,
//定時器
timer: null,
//速度
speed: 250,
//是否已經(jīng)暫停
paused: true,
//行數(shù)
rowCount: 30,
//列數(shù)
colCount: 30,
//初始化
init: function(){
var colors = ['red','orange','yellow','green','blue','purple','#ccc'];
this.tbl = $("main");
var x = 0;
var y = 0;
var colorIndex = 0;
//產(chǎn)生初始移動方向
this.direction = Math.floor(Math.random()*4);
//構(gòu)造table
for(var row=0;rowthis.rowCount;row++){
var tr=this.tbl.insertRow(-1);
for(var col=0;colthis.colCount;col++) {
var td=tr.insertCell(-1);
}
}
//產(chǎn)生20個松散節(jié)點(diǎn)
for(var i=0; i10; i++){
x = Math.floor(Math.random()*this.colCount);
y = Math.floor(Math.random()*this.rowCount);
colorIndex = Math.floor(Math.random()*7);
if(!this.isCellFilled(x,y)){
this.tbl.rows[y].cells[x].style.backgroundColor = colors[colorIndex];
}
}
//產(chǎn)生蛇頭
while(true){
x = Math.floor(Math.random()*this.colCount);
y = Math.floor(Math.random()*this.rowCount);
if(!this.isCellFilled(x,y)){
this.tbl.rows[y].cells[x].style.backgroundColor = "black";
this.body.push({x:x,y:y,color:'black'});
break;
}
}
this.paused = true;
//添加鍵盤事件
document.onkeydown= function(e){
if (!e)e=window.event;
switch(e.keyCode | e.which | e.charCode){
case 13: {
if(Snake.paused){
Snake.move();
Snake.paused = false;
}
else{
//如果沒有暫停,則停止移動
Snake.pause();
Snake.paused = true;
}
break;
}
case 37:{//left
//阻止蛇倒退走
if(Snake.direction==1){
break;
}
Snake.direction = 3;
break;
}
case 38:{//up
//快捷鍵在這里起作用
if(event.ctrlKey){
Snake.speedUp(-20);
break;
}
if(Snake.direction==2){//阻止蛇倒退走
break;
}
Snake.direction = 0;
break;
}
case 39:{//right
if(Snake.direction==3){//阻止蛇倒退走
break;
}
Snake.direction = 1;
break;
}
case 40:{//down
if(event.ctrlKey){
Snake.speedUp(20);
break;
}
if(Snake.direction==0){//阻止蛇倒退走
break;
}
Snake.direction = 2;
break;
}
}
}
},
//移動
move: function(){
this.timer = setInterval(function(){
Snake.erase();
Snake.moveOneStep();
Snake.paint();
}, this.speed);
},
//移動一節(jié)身體
moveOneStep: function(){
if(this.checkNextStep()==-1){
clearInterval(this.timer);
alert("Game over!\nPress Restart to continue.");
return;
}
if(this.checkNextStep()==1){
var _point = this.getNextPos();
var _x = _point.x;
var _y = _point.y;
var _color = this.getColor(_x,_y);
this.body.unshift({x:_x,y:_y,color:_color});
//因?yàn)槌粤艘粋€食物,所以再產(chǎn)生一個食物
this.generateDood();
return;
}
//window.status = this.toString();
var point = this.getNextPos();
//保留第一節(jié)的顏色
var color = this.body[0].color;
//顏色向前移動
for(var i=0; ithis.body.length-1; i++){
this.body[i].color = this.body[i+1].color;
}
//蛇尾減一節(jié), 蛇尾加一節(jié),呈現(xiàn)蛇前進(jìn)的效果
this.body.pop();
this.body.unshift({x:point.x,y:point.y,color:color});
//window.status = this.toString();
},
//探尋下一步將走到什么地方
pause: function(){
clearInterval(Snake.timer);
this.paint();
},
getNextPos: function(){
var x = this.body[0].x;
var y = this.body[0].y;
var color = this.body[0].color;
//向上
if(this.direction==0){
y--;
}
//向右
else if(this.direction==1){
x++;
}
//向下
else if(this.direction==2){
y++;
}
//向左
else{
x--;
}
//返回一個坐標(biāo)
return {x:x,y:y};
},
//檢查將要移動到的下一步是什么
checkNextStep: function(){
var point = this.getNextPos();
var x = point.x;
var y = point.y;
if(x0||x=this.colCount||y0||y=this.rowCount){
return -1;//觸邊界,游戲結(jié)束
}
for(var i=0; ithis.body.length; i++){
if(this.body[i].x==xthis.body[i].y==y){
return -1;//碰到自己的身體,游戲結(jié)束
}
}
if(this.isCellFilled(x,y)){
return 1;//有東西
}
return 0;//空地
},
//擦除蛇身
erase: function(){
for(var i=0; ithis.body.length; i++){
this.eraseDot(this.body[i].x, this.body[i].y);
}
},
//繪制蛇身
paint: function(){
for(var i=0; ithis.body.length; i++){
this.paintDot(this.body[i].x, this.body[i].y,this.body[i].color);
}
},
//擦除一節(jié)
eraseDot: function(x,y){
this.tbl.rows[y].cells[x].style.backgroundColor = "";
},
paintDot: function(x,y,color){
this.tbl.rows[y].cells[x].style.backgroundColor = color;
},
//得到一個坐標(biāo)上的顏色
getColor: function(x,y){
return this.tbl.rows[y].cells[x].style.backgroundColor;
},
//用于調(diào)試
toString: function(){
var str = "";
for(var i=0; ithis.body.length; i++){
str += "x:" + this.body[i].x + " y:" + this.body[i].y + " color:" + this.body[i].color + " - ";
}
return str;
},
//檢查一個坐標(biāo)點(diǎn)有沒有被填充
isCellFilled: function(x,y){
if(this.tbl.rows[y].cells[x].style.backgroundColor == ""){
return false;
}
return true;
},
//重新開始
restart: function(){
if(this.timer){
clearInterval(this.timer);
}
for(var i=0; ithis.rowCount;i++){
this.tbl.deleteRow(0);
}
this.body = [];
this.init();
this.speed = 250;
},
//加速
speedUp: function(time){
if(!this.paused){
if(this.speed+time10||this.speed+time2000){
return;
}
this.speed +=time;
this.pause();
this.move();
}
},
//產(chǎn)生食物。
generateDood: function(){
var colors = ['red','orange','yellow','green','blue','purple','#ccc'];
var x = Math.floor(Math.random()*this.colCount);
var y = Math.floor(Math.random()*this.rowCount);
var colorIndex = Math.floor(Math.random()*7);
if(!this.isCellFilled(x,y)){
this.tbl.rows[y].cells[x].style.backgroundColor = colors[colorIndex];
}
}
};
/script
body onload="Snake.init();"
/*************************************************************br /
* javascript貪吃蛇 v2.4br /
* author: sunxing007 05/14/2009br /
* 轉(zhuǎn)載請注明來自 a href="";/a 謝謝!br /
**************************************************************/br /
table id="main" border="1" cellspacing="0" cellpadding="0"/table
input type="button" id="btn" value="開始/暫停" /點(diǎn)左邊按鈕或按Enter開始/暫停游戲br /
input type="button" id="reset" value="重新開始" /br /
input type="button" id="upSpeed" value="加速" /點(diǎn)左邊按鈕或按Ctrl + ↑加速br /
input type="button" id="downSpeed" value="減速" /點(diǎn)左邊按鈕或按Ctrl + ↓減速
script
$('btn').onclick = function(){
if(Snake.paused){
Snake.move();
Snake.paused = false;
}
else{
Snake.pause();
Snake.paused = true;
}
};
$("reset").onclick = function(){
Snake.restart();
this.blur();
};
$("upSpeed").onclick = function(){
Snake.speedUp(-20);
};
$("downSpeed").onclick = function(){
Snake.speedUp(20);
};
/script
/body
/html
您好,我大致研究了BAIDU MAPS API和GOOGLE MAPS API,可以通過前臺JAVA Script來顯示地圖標(biāo)識點(diǎn),如果需要實(shí)時的顯示,還需要JAX結(jié)合后臺程序來實(shí)現(xiàn),JAX完成數(shù)據(jù)的調(diào)用和地圖的刷新工作,具體的請參考JAX相關(guān)資料。另外后臺程序主要是接受JAX的請求并返回地理數(shù)據(jù)。這些API僅支持頁面前臺的數(shù)據(jù)顯示,不支持?jǐn)?shù)據(jù)庫層面的操作,JAX是個不錯的方法,當(dāng)然也可以動態(tài)生成頁面,比如由程序輸出頁面數(shù)據(jù),將地理位置直接嵌在頁面上,然后定期刷新。
li?標(biāo)簽沒有?value?屬性,如果你想自定義屬性,可以使用?data-xxxxx,xxxxx?可以為任意有效字符,通常為數(shù)字和字母,例如?data-age,?data-gender,?data-value、、、
要獲取一個元素的屬性,使用?.attr("屬性名稱");
script type="text/javascript" src=""/script
script type="text/javascript"
$(function() {
$("#list a").click(function() {
// 輸出 li的class,網(wǎng)址,文字
alert($(this).parent().attr("data-value"));
alert($(this).attr("href"));
alert($(this).text());
return false;
});
});
/script
ul id="list"
li data-value="course"a href="course_design.html"課程設(shè)計/a/li
li data-value="academic"a href="academic_thesis.html"學(xué)年論文/a/li
li data-value="graduation"a href="graduation_thesis.html"畢業(yè)論文/a/li
/ul