-
Notifications
You must be signed in to change notification settings - Fork 1
/
goboard.js
53 lines (47 loc) · 1.26 KB
/
goboard.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Initialize a size by size board with all zeroes, meaning empty.
function initBoard() {
board = new Array(gameSize);
for (var i = 0; i < board.length; i++) {
board[i] = new Array(gameSize);
for (var j = 0; j < board[i].length; j++) {
board[i][j] = "cap";
}
}
}
// Set up the board with empty data and refresh the ui.
function clearBoard() {
initBoard();
refresh();
}
function setPositionState(x, y, color) {
if (x < 0 || y < 0 || x >= gameSize || y >= gameSize) {
return false;
}
if(color != "cap" && board[x][y] != "cap") {
return false;
}
board[x][y] = color;
return true;
}
function draw() {
canv = $("#gocanvas")[0];
context = canv.getContext("2d");
gameSize = parseInt(gup("size")) || 19;
cellSize = gameSize > 13 ? 20 : gameSize > 9 ? 30 : 40;
stoneSize = (cellSize-2)/2;
borderSize = cellSize;
window.addEventListener("mousedown", on_mousedown, false);
window.addEventListener("mouseup", on_mouseup, false);
clearBoard();
}
function gup( name )
{
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( window.location.href );
if( results == null )
return "";
else
return results[1];
}