【www.gdgbn.com--js教程】

无聊时写的,稍作修改就可以支持多人游戏的,实在是懒得写下去了
i键:上,j键:左,k键:下,l键:右


<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;

本文来源:http://www.gdgbn.com/wangyezhizuo/8458/