Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

added a circle on last move #1

Merged
merged 1 commit into from

2 participants

@xcombelle

I did this modification more to comes for example clickable goban

@walf443
Owner

oh nice!

@walf443 walf443 merged commit 4a65246 into walf443:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 23, 2012
  1. @xcombelle

    add circle on last move

    xcombelle authored
This page is out of date. Refresh to see the latest.
Showing with 36 additions and 3 deletions.
  1. +35 −2 goban.js
  2. +1 −1  sample.html
View
37 goban.js
@@ -74,6 +74,7 @@ var Goban = (function() {
this.point(x, y, this.turn);
this.evaluate(x, y);
this.changeTurn();
+ this.lastMove= { x:x, y:y };
} else {
throw "Can't move to this position";
}
@@ -183,6 +184,9 @@ var Goban = (function() {
this.drawStone(i, j);
}
}
+ if (undefined != this.board.lastMove ) {
+ this.drawCircle(this.board.lastMove.x,this.board.lastMove.y);
+ }
};
this.drawStone = function(x, y) {
@@ -206,6 +210,27 @@ var Goban = (function() {
}
+ this.drawCircle = function(x, y) {
+ var value = this.board.data[y * this.board.size + x];
+ switch (value) {
+ case undefined:
+ this.canvas.fillStyle = 'rgb(0, 0, 0, 0)';
+ this.canvas.strokeStyle = 'rgb(0, 0, 0)';
+ break;
+ case goban.BLACK:
+ this.canvas.fillStyle = 'rgb(0, 0, 0,0)';
+ this.canvas.strokeStyle = 'rgb(255, 255, 255)';
+ break;
+ case goban.WHITE:
+ this.canvas.fillStyle = 'rgb(0, 0, 0,0)';
+ this.canvas.strokeStyle = 'rgb(0, 0, 0)';
+ break;
+ }
+ var unit_radius = this.dom.width / this.board.size / 4 * 0.8;
+ this.point(x, y, unit_radius,true);
+
+ }
+
this.drawBoard = function() {
this.drawBackground();
this.canvas.fillStyle = 'rgb(0, 0, 0)';
@@ -269,12 +294,20 @@ var Goban = (function() {
}
};
- this.point = function(x, y, r) {
+ this.point = function(x, y, r, width) {
var coordinates = this.getCoordinate(x, y);
+
this.canvas.beginPath();
this.canvas.arc(coordinates[0], coordinates[1], r, 0, Math.PI * 2, false);
this.canvas.closePath();
- this.canvas.fill();
+
+
+ if(width!=undefined) {
+ this.canvas.stroke();
+ } else {
+ this.canvas.fill();
+ }
+
};
// return real coordinates from virtual coodinate.
View
2  sample.html
@@ -7,7 +7,7 @@
</head>
<body>
<p>碁盤アプリのデモです</p>
- <canvas id="goban" width="300" height="300" />
+ <canvas id="goban" width="600" height="600" />
<script>
"use strict";
var board = new Goban.Board({
Something went wrong with that request. Please try again.