按老師做的,在已經(jīng)有落子的地方點一下,再點擊空白地方,顏色變了,怎么搞
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;
}
2018-03-31
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? 位置錯了!應(yīng)該在 oneStep 方法調(diào)用后 改變 me!=me !
海賊頭像很帥氣嗎!