我的代码在这里:
<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<style type="text/css">
#game {
padding-left: 15px;
padding-top: 15px;
width: 220px;
height: 220px;
background: orangered;
}
.block {
width: 70px;
height: 70px;
float: left;
border: 1px solid white;
box-sizing: border-box;
line-height: 70px;
text-align: center;
font-size: 50px;
text-transform: uppercase;
}
</style>
</head>
<body>
<div id="game"></div>
<script>
var kvadratiki = [];
pole();
var i;
var j;
function pole() {
for (var i=0; i<3; i++) {
kvadratiki[i]=[];
for (var j=0; j<3; j++) {
kvadratiki[i][j] = document.getElementById('game').innerHTML+='<div class="block"></div>';
};
};
};
var hod = 0;
document.getElementById('game').onclick = function(event){
console.log(event);
if (event.target.className == 'block'){
if (hod%2==0) {
event.target.innerHTML = 'x';
}
else {
event.target.innerHTML = '0';
}
hod++;
checkWinner();
}
}
var n;
var m;
function checkWinner(){
var block = document.getElementsByClassName('block');
for (var n=0; n<i; n++) {
for (var m=0; m<j; m++) {
if (kvadratiki[n][m] == kvadratiki[n+1][m+1] && 'x') {
alert('X WINS')
}
}
}
};
</script>
</body>
</html>
它的3x3字段,当你点击它时 - 你把&#39; x&#39;或者&#39; 0&#39; 0在其中一个街区 我想输入允许我检查的代码,如果我有所有&#39; x&#39;或者&#39; 0&#39; 0在行或列或对角线中,例如字段3x3 - 字段ij:
00 01 02
10 11 12
20 21 22
我无法理解如何获得如下元素:
[i][j],[i+1][j+1] - diagonal
[i][j], [i][j+1] -row
[i][j], [i+1][j] -column
我想设置警告,如果00,11,22 - 有&#39; x&#39; 如果00 01 02 - 以及 和00 10 20 - 以及