<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<title>겜블링 게임</title>
<style>
table {
border: 1px solid violet;
border-collapse: collapse;
}
td {
width: 50px;
height: 50px;
padding: 0px;
font: italic 50px consolas, sans-serif;
color: blue;
text-align: center;
background: linen;
}
div#msg {
font: italic 18px consolas, sans-serif;
color: magenta;
margin-top: 10px;
}
</style>
<script>
// to do
var gameon = true;
var gameArray = [0, 0, 0]
function gen(event) {
if (gameon == false) {
return;
}
// generation 0~2
// to do
else if (gameon == true) {
document.getElementById("first").innerHTML = Math.floor(Math.random() * 3);
gameArray[0] = document.getElementById("first").innerHTML;
document.getElementById("second").innerHTML = Math.floor(Math.random() * 3);
gameArray[1] = document.getElementById("second").innerHTML;
document.getElementById("third").innerHTML = Math.floor(Math.random() * 3);
gameArray[2] = document.getElementById("third").innerHTML;
if (gameArray[0] == gameArray[1] && gameArray[1] == gameArray[2]) {
document.getElementById("msg").innerHTML = "Success(click here to do again)";
gameon = false;
}
else {
document.getElementById("msg").innerHTML = "fail(click here to do again)";
}
}
}
function reset() {
for (var i = 0; i < gameArray.length; i++)
gameArray[i] = 0;
document.getElementById("first").innerHTML = 0;
document.getElementById("second").innerHTML = 0;
document.getElementById("third").innerHTML = 0;
gameon = true;
}
</script>
</head>
<body>
<h3>갬블링 게임</h3>
<hr>
<table>
<tr>
<td id="first" onclick="gen(event)">0</td>
<td id="second" onclick="gen(event)">0</td>
<td id="third" onclick="gen(event)">0</td>
</tr>
</table>
<div id="msg" onclick="reset()"></div>
</body>
</html>
每个数字变成一个从 0 到 2 的随机数字。如果每个人都得到相同的数字,他们就赢了。我想修改(else if)部分,这样如果我点击一个数字,那个数字就会改变。目前的方法是,当你点击时,所有的数字都会改变。该部分需要在不修改的情况下解决。//我应该怎么做才能只修改 //to 的底部部分?