问答详情
源自:2-5 落子实现

按老师做的,在已经有落子的地方点一下,再点击空白地方,颜色变了,怎么搞

chess.onclick = function(e){

var x = e.offsetX;

var y = e.offsetY;

var i = Math.floor(x/30);

var j = Math.floor(y/30);

if(chessBoard[i][j]==0){

oneStep(i,j,me);

if(me){

chessBoard[i][j] = 1;

}else{

chessBoard[i][j] = 2;

}

}

me = !me;

}


提问者:童可可3783675 2018-03-11 17:45

个回答

  • 慕粉1855108958
    2018-03-31 22:16:09

    chess.onclick=function (e) {

        var x=e.offsetX;

    var y=e.offsetY;

    //向下取整

    var i=Math.floor(x/30);

    var j=Math.floor(y/30);

       if(chessBoard[i][j]==0){

    oneStep(i,j,me);

    if(me){

             chessBoard[i][j]=1;


    }else{

             chessBoard[i][j]=2;


    }

    me=!me;


       }


    };


    //备注:你的问题是 me!=me  位置错了!应该在 oneStep 方法调用后 改变 me!=me !

    海贼头像很帅气吗!