【发布时间】:2014-01-23 03:08:19
【问题描述】:
我正在开发一个井字游戏,以自学画布元素,但转数计数器似乎没有增加。任何帮助将不胜感激。
function turn() {
var turnNum = 1;
while (turnNum <= 9) {
alert(turnNum % 2);
showCurrent(turnNum);
$(canvas).click(function(event) {
// jQuery would normalize the event
mouse = getMouse(event);
//now you can use the x and y positions
if (turnNum % 2) {
drawX(Math.floor(mouse.y / 100), Math.floor(mouse.x / 100));
} else {
drawO(Math.floor(mouse.y / 100), Math.floor(mouse.x / 100));
}
});
turnNum = turnNum++;
}
}
【问题讨论】:
-
在倒数第三行尝试
turnNum++;,而不是turnNum = turnNum++; -
谢谢!现在应该可以看到了。唯一的问题是第 138 行的警报语句。将其留在垃圾邮件警报中,但将其取出会使程序崩溃。
标签: javascript jquery canvas