html五子棋对战源代码
导读:HTML 五子棋对战源代码 五子棋对战 .board { border: 1px solid black; display: flex;...
HTML 五子棋对战源代码
五子棋对战 .board {
border: 1px solid black;
display: flex;
flex-wrap: wrap;
width: 500px;
height: 500px;
margin: auto;
margin-top: 50px;
}
.board div {
flex: 0 0 62.5px;
height: 62.5px;
border: 1px solid black;
}
.board div.disabled {
background-color: gray;
}
.board .black {
background-color: black;
border-radius: 50%;
}
.board .white {
background-color: white;
border-radius: 50%;
}
let current_color = 'black';
let disabled = false;
let checked_board = new Array(15).fill(null).map(() =>
new Array(15).fill(false));
function render_board() {
const board = document.querySelector('.board');
for (let i = 0;
i 0 &
&
checked_board[i - 1][j] === color) {
i--;
count++;
}
i = x;
while(i = 5) return color;
count = 1;
while(j >
0 &
&
checked_board[i][j - 1] === color) {
j--;
count++;
}
j = y;
while(j = 5) return color;
count = 1;
while(i >
0 &
&
j >
0 &
&
checked_board[i - 1][j - 1] === color) {
i--;
j--;
count++;
}
i = x;
j = y;
while(i = 5) return color;
count = 1;
while(i >
0 &
&
j 0 &
&
checked_board[i + 1][j - 1] === color) {
i++;
j--;
count++;
}
if (count >
= 5) return color;
return null;
}
function show_result(winner) {
disabled = true;
alert(`${
winner == 'black' ? '黑方' : '白方'}
胜利`);
}
render_board();
声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!
若转载请注明出处: html五子棋对战源代码
本文地址: https://pptw.com/jishu/535473.html
