Javascript版五子棋
Javascript版五子棋,无禁手。欢迎提出算法的改进意见。
2. [代码]HTML
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<link rel="stylesheet" type="text/css" href="./main.css?v=12" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script type="text/javascript" src="./locale.js"></script>
<script type="text/javascript" src="./gomoku.js?v=2.2"></script>
<script type="text/javascript">
var turn = 1, role = ['AI', 'human'];
$(function() {
var gomoku = new Gomoku();
gomoku.init(role[turn]);
//turn = turn === 0 ? 1 : 0;
$('#restart').click(function() {
gomoku.restart.call(gomoku, role[turn]);
// turn = turn === 0 ? 1 : 0;
});
$('#regret').click(function() {
gomoku.regret.call(gomoku);
});
});
</script>
</head>
<body>
<div id="toolbar">
<div class="top">
<span class="switch-lang">
<a href="javascript:;" id="zh-cn">简体中文</a>
<a href="javascript:;" id="en">English</a>
</span>
<span class="copy">
©<a href="http://lovebing.org">lovebing</a>
</span>jQuery特效
</div>
You: Black, AI: White, Round: <span id="round">0</span>
<button id="restart">Restart</button>
<button id="regret">Regret</button>
</div>http://www.huiyi8.com/jiaoben/
<div id="output"></div>
<div id="main"></div>
</body>
</html>
3. [代码]gomoku.js部分代码
/**
* Javascript 版五子棋(无禁手)
* Author: lovebing
* Depends: jquery.js
* Created: 2013-06
* Last updated: 2013-12-18
* Copyright 2013 lovebing.org
*/
function Gomoku() {
this.chessboardSize = 15;// 棋盘大小
this.chessState = [];// 保存落子情况,二维数组,i表示行,j表示列
this.gameover = false;
this.round = 0;
this.chessCount = 0;
this.gameResult = '';
this.operationLog = [];
this.chess = ['', 'black', 'white'];
this.role = {
human: 1, // 'black'
AI: 2 //'white'
};
this.turn = this.role.human;
this.chessClass = {
white: 'white-chess',
black: 'black-chess',
last: 'last-chess'
};
this.locale = {};
}
4. [代码]locale.js
var locale = [];
locale['en'] = {
gomoku: 'Gomoku Powered by Lovebing',
restart: 'Restart',
regret: 'Regret',
staleBrowser: 'Your browser\'s version is stale! Please use the browser supported HTML5 like Google chrome.',
youLose: 'You lose!',
youWin: 'You win!',
whiteChess: 'White',
blackChess: 'Black'
};
locale['zh-cn'] = {
gomoku: '五子棋 Powered by Lovebing',
restart: '重新开始',
regret: '悔棋',
staleBrowser: '你的浏览器版本过旧,请使用支持HTML5的浏览器,如Google Chrome。',
youLose: '你输了!',
youWin: '你赢了!',
whiteChess: '白棋',
blackChess: '黑棋'
};

浙公网安备 33010602011771号