无聊时写的,稍作修改就可以支持多人游戏的,实在是懒得写下去了
i键:上,j键:左,k键:下,l键:右
<HTML>
<style>
td {width:2pt;height:2pt;font-size:2pt;}
</style>
<script>
function Pos(x,y) {
this.x = x;
this.y = y;
return this;
}
function Snake(x,y) {
this.node = new Array();
for (var i=0;i<20;i++)
this.node[i] = new Pos(x,y);
this.direction = 0;
this.board = null;
this.setBoard = function (board) {
this.board = board;
}
this.left = function () {
var c;
with (this)
if (board.check(node[0].x-1,node[0].y)) {
clear();
moveNode();
node[0].x--;
c = board.getDot(node[0].x,node[0].y);
draw();
}
else
c = 'black';
this.direction = 2;
return c;
}
this.right = function () {
var c;
with (this)
if (board.check(node[0].x+1,node[0].y)) {
clear();
moveNode();
node[0].x++;
c = board.getDot(node[0].x,node[0].y);
draw();
}
else
c = 'black';
this.direction = 4;
return c;
}
this.up = function () {
var c;
with (this)
if (board.check(n