javascriptで三目ならべのプログラムを作ったのですが、勝敗判定がうまく動作しません。
どの部分が良くないのでしょうか。
教えてください。
なお勝敗判定は省スペース化のため現在のところ、1行目に○がそろった時のみ勝利としたプログラムにしています。
うまくいかないというのは、1行目に○が3つそろってもアラートが発生せずに、9マス最後まで三目並べができてしまうことです。
<DOCTYPE html> <html lang-"ja"> <head> <style> .cell{width:50px; height:50px; font-size:30pt;} </style> </head> <body> <script type="text/javascript" language="JavaScript"> function clickA(a) { if(count++%2==0){a.textContent="○";} else {a.textContent="×";} judge(); } for(count=0; count< 9; count++) { $[count] = document.getElementById('$'+count); $[count].onclick = function(){clickA(this);} } function judge() { if($["0"].value=="○"&&$["1"].value=="○"&&$["2"].value=="○" ) {alert("○の勝ち");} return; } </script> <table border="1"> <tr> <td class="cell" id="$0" onclick="clickA(this);"> </td> <td class="cell" id="$1" onclick="clickA(this);"> </td> <td class="cell" id="$2" onclick="clickA(this);"> </td> </tr> <tr> <td class="cell" id="$3" onclick="clickA(this);"> </td> <td class="cell" id="$4" onclick="clickA(this);"> </td> <td class="cell" id="$5" onclick="clickA(this);"> </td> </tr> <tr> <td class="cell" id="$6" onclick="clickA(this);"> </td> <td class="cell" id="$7" onclick="clickA(this);"> </td> <td class="cell" id="$8" onclick="clickA(this);"> </td> </tr> </table> </body> </html>
回答3件
あなたの回答
tips
プレビュー