`
guoxuepeng
  • 浏览: 38596 次
文章分类
社区版块
存档分类
最新评论

纯JS五子棋(各浏览器兼容)

 
阅读更多

纯JS五子棋(各浏览器兼容)

效果图:




HTML代码


<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;">
<title>五子棋</title>
<link rel="stylesheet" type="text/css" href="http://sandbox.runjs.cn/uploads/rs/102/r2dy3tyw/reset.css">
<script type="text/javascript" src="http://sandbox.runjs.cn/uploads/rs/102/r2dy3tyw/CookieHandle.js"></script>
<script type="text/javascript" src="http://sandbox.runjs.cn/uploads/rs/102/r2dy3tyw/jquery-1.7.2.js"></script>
<style>
.wrapper {
width: 600px;
position: relative;
}


/* 棋盘 */
div.chessboard {
margin: 30px 0 0 50px;
width: 542px;
background: url(http://sandbox.runjs.cn/uploads/rs/102/r2dy3tyw/chessboard.png) no-repeat 14px 14px rgb(250, 250, 250);
overflow: hidden;
box-shadow: 2px 2px 8px #888;
-webkit-box-shadow: 2px 2px 8px #888;
-moz-box-shadow: 2px 2px 8px #888;
}


div.chessboard div {
float: left;
width: 36px;
height: 36px;
border-top: 0px solid #ccc;
border-left: 0px solid #ccc;
border-right: 0;
border-bottom: 0;
cursor: pointer;
}


/* 棋子 */
div.chessboard div.black {
background: url(http://sandbox.runjs.cn/uploads/rs/102/r2dy3tyw/black.png) no-repeat 4px 4px;
}
div.chessboard div.white {
background: url(http://sandbox.runjs.cn/uploads/rs/102/r2dy3tyw/white.png) no-repeat 4px 4px;
}
div.chessboard div.hover {
background: url(http://sandbox.runjs.cn/uploads/rs/102/r2dy3tyw/hover.png) no-repeat 1px 1px;
}
div.chessboard div.hover-up {
background: url(http://sandbox.runjs.cn/uploads/rs/102/r2dy3tyw/hover_up.png) no-repeat 1px 1px;
}
div.chessboard div.hover-down {
background: url(http://sandbox.runjs.cn/uploads/rs/102/r2dy3tyw/hover_down.png) no-repeat 1px 1px;
}
div.chessboard div.hover-up-left {
background: url(http://sandbox.runjs.cn/uploads/rs/102/r2dy3tyw/hover_up_left.png) no-repeat 1px 1px;
}
div.chessboard div.hover-up-right {
background: url(http://sandbox.runjs.cn/uploads/rs/102/r2dy3tyw/hover_up_right.png) no-repeat 1px 1px;
}
div.chessboard div.hover-left {
background: url(http://sandbox.runjs.cn/uploads/rs/102/r2dy3tyw/hover_left.png) no-repeat 1px 1px;
}
div.chessboard div.hover-right {
background: url(http://sandbox.runjs.cn/uploads/rs/102/r2dy3tyw/hover_right.png) no-repeat 1px 1px;
}
div.chessboard div.hover-down-left {
background: url(http://sandbox.runjs.cn/uploads/rs/102/r2dy3tyw/hover_down_left.png) no-repeat 1px 1px;
}
div.chessboard div.hover-down-right {
background: url(http://sandbox.runjs.cn/uploads/rs/102/r2dy3tyw/hover_down_right.png) no-repeat 1px 1px;
}
div.chessboard div.white-last {
background: url(http://sandbox.runjs.cn/uploads/rs/102/r2dy3tyw/white_last.png) no-repeat 4px 4px;
}
div.chessboard div.black-last {
background: url(http://sandbox.runjs.cn/uploads/rs/102/r2dy3tyw/black_last.png) no-repeat 4px 4px;
}


/* 右侧 */


div.operating-panel {
position: absolute;
left: 610px;
top: 150px;
width: 200px;
text-align: center;
}


.operating-panel a {
display: inline-block;
padding: 10px 15px;
margin-bottom: 39px;
margin-right: 8px;
margin-left: 8px;
background: rgb(100, 167, 233);
text-decoration: none;
color: #333;
font-weight: bold;
font-size: 16px;
font-family: "微软雅黑", "宋体";
}


.operating-panel a:hover {
background: rgb(48, 148, 247);
text-decoration: none;
}


.operating-panel a.disable, .operating-panel a.disable:hover {
cursor: default;
background: rgb(197, 203, 209);
color: rgb(130, 139, 148);
}


.operating-panel a.selected {
border: 5px solid #F3C242;
padding: 5px 10px;
}


#result_tips {
color: #CE4242;
font-size: 26px;
font-family: "微软雅黑";
}


#result_info {
margin-bottom: 26px;
}
</style>
<script>
$(document).ready(function() {
fiveChess.init();
});


var fiveChess = {
NO_CHESS: 0,
BLACK_CHESS: -1,
WHITE_CHESS: 1,
chessArr: [], //记录棋子
chessBoardHtml: "",
humanPlayer: "black",//玩家棋子颜色
AIPlayer: "white",//AI棋子颜色
isPlayerTurn: true, //轮到player下棋
totalGames: cookieHandle.getCookie("totalGames") || 0,//总局数
winGames: cookieHandle.getCookie("winGames") || 0,//玩家赢局数
isGameStart: false,//游戏已经开始
isGameOver: false, //游戏结束
playerLastChess: [], //玩家最后下子位置
AILastChess: [], //AI最后下子位置


init: function () {
this.chessBoardHtml = $("div.chessboard").html();
var _fiveChess = this;
//右侧操作按钮
$(".operating-panel a").click(function (event) {
event.preventDefault();
var id = $(this).attr("id");
if (_fiveChess.isGameStart && id !== "replay_btn" ) { return; }//正在游戏 不操作
switch (id) {
case "black_btn":
_fiveChess.humanPlayer = "black";
_fiveChess.AIPlayer = "white";
break;
case "white_btn":
_fiveChess.humanPlayer = "white";
_fiveChess.AIPlayer = "black";
break;
case "first_move_btn":
_fiveChess.isPlayerTurn = true;
break;
case "second_move_btn":
_fiveChess.isPlayerTurn = false;
break;
case "replay_btn":
_fiveChess.resetChessBoard();
if (_fiveChess.isGameStart) {//点重玩
_fiveChess.gameOver();
}
else { //点开始
_fiveChess.gameStart();
}
break;
}
if (id !== "replay_btn") {
$(this).addClass("selected").siblings().removeClass("selected");
}
});
this.resetChessBoard();
$("#result_info").html("胜率:" + (this.winGames * 100 / this.totalGames | 0) + "%");
},
//重置棋盘
resetChessBoard: function () {
$("div.chessboard").html(this.chessBoardHtml);
$("#result_tips").html("");
this.isGameOver = false;
this.isPlayerTurn = $("#first_move_btn").hasClass("selected");
//初始化棋子状态
var i, j;
for (i = 0; i < 15; i++) {
this.chessArr[i] = [];
for (j = 0; j < 15; j++) {
this.chessArr[i][j] = this.NO_CHESS;
}
}
//player下棋事件
var _fiveChess = this;
$("div.chessboard div").click(function () {
if (!_fiveChess.isPlayerTurn || _fiveChess.isGameOver) {
return;
}
if (!_fiveChess.isGameStart) {
_fiveChess.gameStart();
}
var index = $(this).index(),
i = index / 15 | 0,
j = index % 15;
if (_fiveChess.chessArr[i][j] === _fiveChess.NO_CHESS) {
_fiveChess.playChess(i, j, _fiveChess.humanPlayer);
if (i === 0 && j === 0) {
$(this).removeClass("hover-up-left");
}
else if (i === 0 && j === 14) {
$(this).removeClass("hover-up-right");
}
else if (i === 14 && j === 0) {
$(this).removeClass("hover-down-left");
}
else if (i === 14 && j === 14) {
$(this).removeClass("hover-down-right");
}
else if (i === 0) {
$(this).removeClass("hover-up");
}
else if (i === 14) {
$(this).removeClass("hover-down");
}
else if (j === 0) {
$(this).removeClass("hover-left");
}
else if (j === 14) {
$(this).removeClass("hover-right");
}
else {
$(this).removeClass("hover");
}
_fiveChess.playerLastChess = [i, j];
_fiveChess.playerWinOrNot(i, j);
}
});
//鼠标在棋盘上移动效果
$("div.chessboard div").hover(
function () {
if (!_fiveChess.isPlayerTurn || _fiveChess.isGameOver) { return; }
var index = $(this).index(),
i = index / 15 | 0,
j = index % 15;
if (_fiveChess.chessArr[i][j] === _fiveChess.NO_CHESS) {
if (i === 0 && j === 0) {
$(this).addClass("hover-up-left");
}
else if (i === 0 && j === 14) {
$(this).addClass("hover-up-right");
}
else if (i === 14 && j === 0) {
$(this).addClass("hover-down-left");
}
else if (i === 14 && j === 14) {
$(this).addClass("hover-down-right");
}
else if (i === 0) {
$(this).addClass("hover-up");
}
else if (i === 14) {
$(this).addClass("hover-down");
}
else if (j === 0) {
$(this).addClass("hover-left");
}
else if (j === 14) {
$(this).addClass("hover-right");
}
else {
$(this).addClass("hover");
}
}
},
function () {
if (!_fiveChess.isPlayerTurn || _fiveChess.isGameOver) { return; }
var index = $(this).index(),
i = index / 15 | 0,
j = index % 15;
if (i === 0 && j === 0) {
$(this).removeClass("hover-up-left");
}
else if (i === 0 && j === 14) {
$(this).removeClass("hover-up-right");
}
else if (i === 14 && j === 0) {
$(this).removeClass("hover-down-left");
}
else if (i === 14 && j === 14) {
$(this).removeClass("hover-down-right");
}
else if (i === 0) {
$(this).removeClass("hover-up");
}
else if (i === 14) {
$(this).removeClass("hover-down");
}
else if (j === 0) {
$(this).removeClass("hover-left");
}
else if (j === 14) {
$(this).removeClass("hover-right");
}
else {
$(this).removeClass("hover");
}
}
);
},
gameStart: function () {
this.totalGames++;
cookieHandle.setCookie({ name: "totalGames", value: this.totalGames, expiresHours: 365 * 24 });
//AI先手
if (!this.isPlayerTurn) {
this.AImoveChess();
}
this.isGameStart = true;
$(".operating-panel p a").addClass("disable");
$("#replay_btn").html("重玩");
},
gameOver: function () {
this.isGameStart = false;
$(".operating-panel a").removeClass("disable");
$("#replay_btn").html("开始");
$("#result_info").html("胜率:" + (this.winGames * 100 / this.totalGames | 0) + "%");
},


//下棋 i行,j列,color颜色
playChess: function (i, j, color) {
this.chessArr[i][j] = color === "black" ? this.BLACK_CHESS : this.WHITE_CHESS;
if (color === this.AIPlayer) {
$("div.chessboard div." + color + "-last").addClass(color).removeClass(color + "-last");
$("div.chessboard div:eq(" + (i * 15 + j) + ")").addClass(color + "-last");
}
else {
$("div.chessboard div:eq(" + (i * 15 + j) + ")").addClass(color);
}
},
//玩家是否取胜
playerWinOrNot: function (i, j) {
var nums = 1, //连续棋子个数
chessColor = this.humanPlayer === "black" ? this.BLACK_CHESS : this.WHITE_CHESS,
m, n;
//x方向
for (m = j - 1; m >= 0; m--) {
if (this.chessArr[i][m] === chessColor) {
nums++;
}
else {
break;
}
}
for (m = j + 1; m < 15; m++) {
if (this.chessArr[i][m] === chessColor) {
nums++;
}
else {
break;
}
}
if (nums >= 5) {
this.playerWin();
return;
}
else {
nums = 1;
}
//y方向
for (m = i - 1; m >= 0; m--) {
if (this.chessArr[m][j] === chessColor) {
nums++;
}
else {
break;
}
}
for (m = i + 1; m < 15; m++) {
if (this.chessArr[m][j] === chessColor) {
nums++;
}
else {
break;
}
}
if (nums >= 5) {
this.playerWin();
return;
}
else {
nums = 1;
}
//左斜方向
for (m = i - 1, n = j - 1; m >= 0 && n >= 0; m--, n--) {
if (this.chessArr[m][n] === chessColor) {
nums++;
}
else {
break;
}
}
for (m = i + 1, n = j + 1; m < 15 && n < 15; m++, n++) {
if (this.chessArr[m][n] === chessColor) {
nums++;
}
else {
break;
}
}
if (nums >= 5) {
this.playerWin();
return;
}
else {
nums = 1;
}
//右斜方向
for (m = i - 1, n = j + 1; m >= 0 && n < 15; m--, n++) {
if (this.chessArr[m][n] === chessColor) {
nums++;
}
else {
break;
}
}
for (m = i + 1, n = j - 1; m < 15 && n >= 0; m++, n--) {
if (this.chessArr[m][n] === chessColor) {
nums++;
}
else {
break;
}
}
if (nums >= 5) {
this.playerWin();
return;
}
this.AImoveChess();
},
playerWin: function () {
this.winGames++;
cookieHandle.setCookie({ name: "winGames", value: this.winGames, expiresHours: 365 * 24 });
this.showResult(true);
this.gameOver();
},
//AI下棋
AImoveChess: function () {
this.isPlayerTurn = false;
var maxX = 0,
maxY = 0,
maxWeight = 0,
i, j, tem;
for (i = 14; i >= 0; i--) {
for (j = 14; j >= 0; j--) {
if (this.chessArr[i][j] !== this.NO_CHESS) {
continue;
}
tem = this.computeWeight(i, j);
if (tem > maxWeight) {
maxWeight = tem;
maxX = i;
maxY = j;
}
}
}
this.playChess(maxX, maxY, this.AIPlayer);
this.AILastChess = [maxX, maxY];
if ((maxWeight >= 100000 && maxWeight < 250000) || (maxWeight >= 500000)) {
this.showResult(false);
this.gameOver();
}
else {
this.isPlayerTurn = true;
}
},
showResult: function(isPlayerWin) {
if (isPlayerWin) {
$("#result_tips").html("恭喜你获胜!");
}
else {
$("#result_tips").html("哈哈,你输咯!");
}
this.isGameOver = true;
this.showWinChesses(isPlayerWin);
},
//标记显示获胜棋子
showWinChesses: function (isPlayerWin) {
var nums = 1, //连续棋子个数
lineChess = [],//连续棋子位置
i,
j,
chessColor,
m, n;
if (isPlayerWin) {
chessColor = this.humanPlayer === "black" ? this.BLACK_CHESS : this.WHITE_CHESS;
i = this.playerLastChess[0];
j = this.playerLastChess[1];
}
else {
chessColor = this.AIPlayer === "black" ? this.BLACK_CHESS : this.WHITE_CHESS;
i = this.AILastChess[0];
j = this.AILastChess[1];
}
$("div.chessboard div." + this.AIPlayer + "-last").addClass(this.AIPlayer).removeClass(this.AIPlayer + "-last");
//x方向
lineChess[0] = [i];
lineChess[1] = [j];
for (m = j - 1; m >= 0; m--) {
if (this.chessArr[i][m] === chessColor) {
lineChess[0][nums] = i;
lineChess[1][nums] = m;
nums++;
}
else {
break;
}
}
for (m = j + 1; m < 15; m++) {
if (this.chessArr[i][m] === chessColor) {
lineChess[0][nums] = i;
lineChess[1][nums] = m;
nums++;
}
else {
break;
}
}
if (nums >= 5) {
for (k = nums - 1; k >= 0; k--) {
this.markChess(lineChess[0][k] * 15 + lineChess[1][k], isPlayerWin ? this.humanPlayer : this.AIPlayer);
}
return;
}
//y方向
nums = 1;
lineChess[0] = [i];
lineChess[1] = [j];
for (m = i - 1; m >= 0; m--) {
if (this.chessArr[m][j] === chessColor) {
lineChess[0][nums] = m;
lineChess[1][nums] = j;
nums++;
}
else {
break;
}
}
for (m = i + 1; m < 15; m++) {
if (this.chessArr[m][j] === chessColor) {
lineChess[0][nums] = m;
lineChess[1][nums] = j;
nums++;
}
else {
break;
}
}
if (nums >= 5) {
for (k = nums - 1; k >= 0; k--) {
this.markChess(lineChess[0][k] * 15 + lineChess[1][k], isPlayerWin ? this.humanPlayer : this.AIPlayer);
}
return;
}
//左斜方向
nums = 1;
lineChess[0] = [i];
lineChess[1] = [j];
for (m = i - 1, n = j - 1; m >= 0 && n >= 0; m--, n--) {
if (this.chessArr[m][n] === chessColor) {
lineChess[0][nums] = m;
lineChess[1][nums] = n;
nums++;
}
else {
break;
}
}
for (m = i + 1, n = j + 1; m < 15 && n < 15; m++, n++) {
if (this.chessArr[m][n] === chessColor) {
lineChess[0][nums] = m;
lineChess[1][nums] = n;
nums++;
}
else {
break;
}
}
if (nums >= 5) {
for (k = nums - 1; k >= 0; k--) {
this.markChess(lineChess[0][k] * 15 + lineChess[1][k], isPlayerWin ? this.humanPlayer : this.AIPlayer);
}
return;
}
//右斜方向
nums = 1;
lineChess[0] = [i];
lineChess[1] = [j];
for (m = i - 1, n = j + 1; m >= 0 && n < 15; m--, n++) {
if (this.chessArr[m][n] === chessColor) {
lineChess[0][nums] = m;
lineChess[1][nums] = n;
nums++;
}
else {
break;
}
}
for (m = i + 1, n = j - 1; m < 15 && n >= 0; m++, n--) {
if (this.chessArr[m][n] === chessColor) {
lineChess[0][nums] = m;
lineChess[1][nums] = n;
nums++;
}
else {
break;
}
}
if (nums >= 5) {
for (k = nums - 1; k >= 0; k--) {
this.markChess(lineChess[0][k] * 15 + lineChess[1][k], isPlayerWin ? this.humanPlayer : this.AIPlayer);
}
}
},
markChess: function (pos, color) {
$("div.chessboard div:eq(" + pos + ")").removeClass(color).addClass(color + "-last");
},
//下子到i,j X方向 结果: 多少连子 两边是否截断
putDirectX: function (i, j, chessColor) {
var m, n,
nums = 1,
side1 = false,
side2 = false;
for (m = j - 1; m >= 0; m--) {
if (this.chessArr[i][m] === chessColor) {
nums++;
}
else {
if (this.chessArr[i][m] === this.NO_CHESS) {
side1 = true;
}
break;
}
}
for (m = j + 1; m < 15; m++) {
if (this.chessArr[i][m] === chessColor) {
nums++;
}
else {
if (this.chessArr[i][m] === this.NO_CHESS) {
side2 = true;
}
break;
}
}
return {"nums": nums, "side1": side1, "side2": side2};
},
//下子到i,j Y方向 结果
putDirectY: function (i, j, chessColor) {
var m, n,
nums = 1,
side1 = false,
side2 = false;
for (m = i - 1; m >= 0; m--) {
if (this.chessArr[m][j] === chessColor) {
nums++;
}
else {
if (this.chessArr[m][j] === this.NO_CHESS) {
side1 = true;
}
break;
}
}
for (m = i + 1; m < 15; m++) {
if (this.chessArr[m][j] === chessColor) {
nums++;
}
else {
if (this.chessArr[m][j] === this.NO_CHESS) {
side2 = true;
}
break;
}
}
return {"nums": nums, "side1": side1, "side2": side2};
},
//下子到i,j XY方向 结果
putDirectXY: function (i, j, chessColor) {
var m, n,
nums = 1,
side1 = false,
side2 = false;
for (m = i - 1, n = j - 1; m >= 0 && n >= 0; m--, n--) {
if (this.chessArr[m][n] === chessColor) {
nums++;
}
else {
if (this.chessArr[m][n] === this.NO_CHESS) {
side1 = true;
}
break;
}
}
for (m = i + 1, n = j + 1; m < 15 && n < 15; m++, n++) {
if (this.chessArr[m][n] === chessColor) {
nums++;
}
else {
if (this.chessArr[m][n] === this.NO_CHESS) {
side2 = true;
}
break;
}
}
return {"nums": nums, "side1": side1, "side2": side2};
},
putDirectYX: function (i, j, chessColor) {
var m, n,
nums = 1,
side1 = false,
side2 = false;
for (m = i - 1, n = j + 1; m >= 0 && n < 15; m--, n++) {
if (this.chessArr[m][n] === chessColor) {
nums++;
}
else {
if (this.chessArr[m][n] === this.NO_CHESS) {
side1 = true;
}
break;
}
}
for (m = i + 1, n = j - 1; m < 15 && n >= 0; m++, n--) {
if (this.chessArr[m][n] === chessColor) {
nums++;
}
else {
if (this.chessArr[m][n] === this.NO_CHESS) {
side2 = true;
}
break;
}
}
return {"nums": nums, "side1": side1, "side2": side2};
},
//计算下子至i,j的权重
computeWeight: function (i, j) {
var weight = 14 - (Math.abs(i - 7) + Math.abs(j - 7)), //基于棋盘位置权重
pointInfo = {},//某点下子后连子信息
chessColor = this.AIPlayer === "black" ? this.BLACK_CHESS : this.WHITE_CHESS;
//x方向
pointInfo = this.putDirectX(i, j, chessColor);
weight += this.weightStatus(pointInfo.nums, pointInfo.side1, pointInfo.side2, true);//AI下子权重
pointInfo = this.putDirectX(i, j, -chessColor);
weight += this.weightStatus(pointInfo.nums, pointInfo.side1, pointInfo.side2, false);//player下子权重
//y方向
pointInfo = this.putDirectY(i, j, chessColor);
weight += this.weightStatus(pointInfo.nums, pointInfo.side1, pointInfo.side2, true);//AI下子权重
pointInfo = this.putDirectY(i, j, -chessColor);
weight += this.weightStatus(pointInfo.nums, pointInfo.side1, pointInfo.side2, false);//player下子权重
//左斜方向
pointInfo = this.putDirectXY(i, j, chessColor);
weight += this.weightStatus(pointInfo.nums, pointInfo.side1, pointInfo.side2, true);//AI下子权重
pointInfo = this.putDirectXY(i, j, -chessColor);
weight += this.weightStatus(pointInfo.nums, pointInfo.side1, pointInfo.side2, false);//player下子权重
//右斜方向
pointInfo = this.putDirectYX(i, j, chessColor);
weight += this.weightStatus(pointInfo.nums, pointInfo.side1, pointInfo.side2, true);//AI下子权重
pointInfo = this.putDirectYX(i, j, -chessColor);
weight += this.weightStatus(pointInfo.nums, pointInfo.side1, pointInfo.side2, false);//player下子权重
return weight;
},
//权重方案   独:两边为空可下子,单:一边为空
weightStatus: function (nums, side1, side2, isAI) {
var weight = 0;
switch (nums) {
case 1:
if (side1 && side2) {
weight = isAI ? 15 : 10;//独一
}
break;
case 2:
if (side1 && side2) {
weight = isAI ? 100 : 50;//独二
}
else if (side1 || side2) {
weight = isAI ? 10 : 5;//单二
}
break;
case 3:
if (side1 && side2) {
weight = isAI ? 500 : 200;//独三
}
else if (side1 || side2) {
weight = isAI ? 30 : 20;//单三
}
break;
case 4:
if (side1 && side2) {
weight = isAI ? 5000 : 2000;//独四
}
else if (side1 || side2) {
weight = isAI ? 400 : 100;//单四
}
break;
case 5:
weight = isAI ? 100000 : 10000;//五
break;
default:
weight = isAI ? 500000 : 250000;
break;
}
return weight;
}
};
</script>
</head>
<body>
<div class="wrapper">
<div class="chessboard">
<!-- top line -->
<div class="chess-top"></div>
<div class="chess-top"></div>
<div class="chess-top"></div>
<div class="chess-top"></div>
<div class="chess-top"></div>
<div class="chess-top"></div>
<div class="chess-top"></div>
<div class="chess-top"></div>
<div class="chess-top"></div>
<div class="chess-top"></div>
<div class="chess-top"></div>
<div class="chess-top"></div>
<div class="chess-top"></div>
<div class="chess-top"></div>
<div class="chess-top chess-right"></div>
<!-- line 1 -->
<div class="chess-left"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-right"></div>
<!-- line 2 -->
<div class="chess-left"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-right"></div>
<!-- line 3 -->
<div class="chess-left"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-right"></div>
<!-- line 4 -->
<div class="chess-left"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-right"></div>
<!-- line 5 -->
<div class="chess-left"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-right"></div>
<!-- line 6 -->
<div class="chess-left"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-right"></div>
<!-- line 7 -->
<div class="chess-left"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-right"></div>
<!-- line 8 -->
<div class="chess-left"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-right"></div>
<!-- line 9 -->
<div class="chess-left"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-right"></div>
<!-- line 10 -->
<div class="chess-left"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-right"></div>
<!-- line 11 -->
<div class="chess-left"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-right"></div>
<!-- line 12 -->
<div class="chess-left"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-right"></div>
<!-- line 13 -->
<div class="chess-left"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-middle"></div>
<div class="chess-right"></div>
<!-- bottom line  -->
<div class="chess-bottom"></div>
<div class="chess-bottom"></div>
<div class="chess-bottom"></div>
<div class="chess-bottom"></div>
<div class="chess-bottom"></div>
<div class="chess-bottom"></div>
<div class="chess-bottom"></div>
<div class="chess-bottom"></div>
<div class="chess-bottom"></div>
<div class="chess-bottom"></div>
<div class="chess-bottom"></div>
<div class="chess-bottom"></div>
<div class="chess-bottom"></div>
<div class="chess-bottom"></div>
<div class="chess-bottom chess-right"></div>
</div>


<div class="operating-panel">
<p>
<a id="black_btn" class="btn selected" href="#">黑子</a>
<a id="white_btn" class="btn" href="#">白子</a>
</p>
<p>
<a id="first_move_btn" class="btn selected" href="#">先手</a>
<a id="second_move_btn" class="btn" href="#">后手</a>
</p>
<a id="replay_btn" class="btn" href="#">开始</a>
<p id="result_info">胜率:100%</p>
<p id="result_tips"></p>
</div>


<div style="display: none">
<!-- 图片需合并 减少http请求数 -->
<img src="http://sandbox.runjs.cn/uploads/rs/102/r2dy3tyw/black.png" alt="preload" />
<img src="http://sandbox.runjs.cn/uploads/rs/102/r2dy3tyw/white.png" alt="preload" />
<img src="http://sandbox.runjs.cn/uploads/rs/102/r2dy3tyw/hover.png" alt="preload" />
<img src="http://sandbox.runjs.cn/uploads/rs/102/r2dy3tyw/hover_up.png" alt="preload" />
<img src="http://sandbox.runjs.cn/uploads/rs/102/r2dy3tyw/hover_down.png" alt="preload" />
<img src="http://sandbox.runjs.cn/uploads/rs/102/r2dy3tyw/hover_up_left.png" alt="preload" />
<img src="http://sandbox.runjs.cn/uploads/rs/102/r2dy3tyw/hover_up_right.png" alt="preload" />
<img src="http://sandbox.runjs.cn/uploads/rs/102/r2dy3tyw/hover_left.png" alt="preload" />
<img src="http://sandbox.runjs.cn/uploads/rs/102/r2dy3tyw/hover_right.png" alt="preload" />
<img src="http://sandbox.runjs.cn/uploads/rs/102/r2dy3tyw/hover_down_left.png" alt="preload" />
<img src="http://sandbox.runjs.cn/uploads/rs/102/r2dy3tyw/hover_down_right.png" alt="preload" />
<img src="http://sandbox.runjs.cn/uploads/rs/102/r2dy3tyw/black_last.png" alt="preload" />
<img src="http://sandbox.runjs.cn/uploads/rs/102/r2dy3tyw/white_last.png" alt="preload" />
</div>
</div>
</body>
</html>




分享到:
评论

相关推荐

    纯Js写的五子棋

    纯Js写的五子棋 各个浏览器兼容 各个浏览器兼容

    纯JS实现五子棋游戏兼容各浏览器(附源码)

    总结来说,纯JavaScript实现的五子棋游戏涵盖了HTML页面构建、CSS样式设计、JavaScript编程逻辑和浏览器兼容性处理等多个方面的知识点。源码的公开不仅让开发者可以学习到实现五子棋游戏的完整过程,还能够从中学习...

    js前端五子棋,直接运行,带Ai功能

    8. **优化与兼容性**:为了确保游戏在不同浏览器和设备上的良好运行,开发者可能已经考虑了性能优化和跨平台兼容性问题,比如使用现代JavaScript语法但同时兼容旧版本浏览器,或者使用响应式设计适应不同屏幕尺寸。...

    wuziqi.zip_五子棋 js_五子棋js

    【五子棋.js】是一个基于JavaScript编写的纯前端五子棋游戏。JavaScript是一种广泛应用于网页和网络应用开发的脚本语言,它可以直接在用户的浏览器上运行,无需服务器支持,这使得五子棋游戏可以在任何支持...

    js 五子棋(IE中有声音)

    在本项目中,我们关注的是一个使用JavaScript实现的五子棋游戏。JavaScript是一种广泛用于网页开发的编程语言,它可以为网站添加动态功能和交互性。五子棋是一种经典的双人策略游戏,目标是在棋盘上首先形成连续的五...

    javascript编写的对战五子棋

    **JavaScript编写的对战五子棋** 在网页端游戏开发中,JavaScript是一种常见的编程语言,因其在浏览器中直接运行的特性而被广泛用于创建交互式网页应用,包括各种在线游戏。本项目“javascript编写的对战五子棋”...

    wuziqi.rar_javascript_五子棋

    本篇文章将深入探讨如何使用JavaScript这一强大的网页编程语言来实现一个与各浏览器兼容的五子棋应用。 一、JavaScript基础 JavaScript,简称JS,是Web开发中最常用的脚本语言,用于控制网页的动态行为。它支持...

    网页五子棋(这个是用纯html写的)

    此外,考虑到浏览器兼容性,开发者可能使用了现代JavaScript语法,并配合使用工具如Babel将ES6+代码转换为更广泛支持的ES5语法,确保在旧版本浏览器中也能正常运行。 总的来说,这个纯HTML编写的五子棋游戏展现了...

    HTML5网页版五子棋小游戏源码下载.zip

    9. 浏览器兼容性:虽然HTML5是现代浏览器的标准,但仍然需要注意不同浏览器之间的兼容性问题。开发者可能使用了像Modernizr这样的库来检测浏览器特性,并提供必要的polyfills以确保游戏在旧版浏览器中也能正常运行。...

    javascript实现的五子棋人机对战游戏源码

    10. **浏览器兼容性**:由于JavaScript代码是在客户端运行的,因此开发者需要考虑不同浏览器之间的差异,确保代码在主流浏览器上都能正常工作。 总的来说,这个项目涵盖了JavaScript基础、前端开发、游戏逻辑设计、...

    js五子棋游戏(修改后缀为html即可)

    一个由js写的五子棋游戏 ,修改文件后缀为.html即可,兼容所有浏览器,即用即玩,学习用

    html5五子棋游戏可设置难度.rar

    10. **浏览器兼容性**: HTML5五子棋游戏需要考虑到各种现代浏览器的兼容性,确保在Chrome、Firefox、Safari、Edge等主流浏览器上都能流畅运行。 综上所述,这个HTML5五子棋游戏的开发涉及到前端技术的多个方面,...

    五子棋游戏的设计与实现毕业设计(含论文)

    9. **兼容性考虑**: 游戏设计考虑到了跨浏览器兼容性,确保在谷歌、火狐及360等主流浏览器以及移动端设备上都能流畅运行。 10. **页面布局**: 页面采用上中下和左右两种格局,这可能是为了提供清晰的导航和内容展示...

    html五子棋游戏

    此外,由于游戏是在浏览器环境下运行,所以兼容性也是需要考虑的问题。这里提到可以直接在Chrome上运行,意味着开发人员可能已经针对Chrome的渲染引擎进行了优化,确保游戏在其他浏览器上可能无法正常工作或效果不佳...

    五子棋人机对战web版

    这款应用专为谷歌浏览器优化,对于其他浏览器,特别是IE浏览器,兼容性可能不佳。该项目不仅是娱乐工具,更是学习和提升JavaScript技能的理想实践平台,特别是对JavaScript参数传递和AI设计的理解。 1. **...

    五子棋 HTML5(不含与电脑博弈)

    6. **浏览器兼容性**: 虽然HTML5在大多数现代浏览器中都得到了很好的支持,但为了确保广泛的用户群体,开发者可能还需要考虑老版本浏览器的兼容性问题,可能需要引入polyfills或其他技术。 综上所述,这个五子棋...

    h5小游戏-五子棋.rar_H5游戏_h5五子棋_h5小游戏_五子棋_五子棋 h5

    JavaScript是实现五子棋游戏逻辑的关键。首先,我们需要定义棋盘的结构,可以使用二维数组来表示每个格子的状态(空、黑棋、白棋)。然后,编写下棋的函数,根据用户点击的位置判断是否合法并更新棋盘状态。接着,...

    网页游戏五子棋Flash+PHP+文本数据库

    网页游戏五子棋Flash+PHP+文本数据库是一个基于经典五子棋...同时,它也提醒我们,随着技术的发展(如HTML5、JavaScript框架的崛起和Flash的逐渐淘汰),类似的项目可能需要考虑采用更现代的技术栈以保持兼容性和性能。

    五子棋小游戏HTML5源码.zip

    5. **响应式设计**: 由于源码未明确提及,但一个好的网页游戏应当考虑不同设备的兼容性。因此,源码可能包含了响应式设计,确保游戏在手机、平板和桌面电脑上都能良好显示。 6. **用户交互**: 五子棋游戏需要响应...

Global site tag (gtag.js) - Google Analytics