Skip to content

Commit

Permalink
add circle on last move
Browse files Browse the repository at this point in the history
  • Loading branch information
xcombelle committed Feb 23, 2012
1 parent 0d61377 commit 7cc39f2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
37 changes: 35 additions & 2 deletions goban.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ var Goban = (function() {
this.point(x, y, this.turn); this.point(x, y, this.turn);
this.evaluate(x, y); this.evaluate(x, y);
this.changeTurn(); this.changeTurn();
this.lastMove= { x:x, y:y };
} else { } else {
throw "Can't move to this position"; throw "Can't move to this position";
} }
Expand Down Expand Up @@ -183,6 +184,9 @@ var Goban = (function() {
this.drawStone(i, j); this.drawStone(i, j);
} }
} }
if (undefined != this.board.lastMove ) {
this.drawCircle(this.board.lastMove.x,this.board.lastMove.y);
}
}; };


this.drawStone = function(x, y) { this.drawStone = function(x, y) {
Expand All @@ -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.drawBoard = function() {
this.drawBackground(); this.drawBackground();
this.canvas.fillStyle = 'rgb(0, 0, 0)'; this.canvas.fillStyle = 'rgb(0, 0, 0)';
Expand Down Expand Up @@ -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); var coordinates = this.getCoordinate(x, y);

this.canvas.beginPath(); this.canvas.beginPath();
this.canvas.arc(coordinates[0], coordinates[1], r, 0, Math.PI * 2, false); this.canvas.arc(coordinates[0], coordinates[1], r, 0, Math.PI * 2, false);
this.canvas.closePath(); this.canvas.closePath();
this.canvas.fill();

if(width!=undefined) {
this.canvas.stroke();
} else {
this.canvas.fill();
}

}; };


// return real coordinates from virtual coodinate. // return real coordinates from virtual coodinate.
Expand Down
2 changes: 1 addition & 1 deletion sample.html
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</head> </head>
<body> <body>
<p>碁盤アプリのデモです</p> <p>碁盤アプリのデモです</p>
<canvas id="goban" width="300" height="300" /> <canvas id="goban" width="600" height="600" />
<script> <script>
"use strict"; "use strict";
var board = new Goban.Board({ var board = new Goban.Board({
Expand Down

1 comment on commit 7cc39f2

@walf443
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh nice!

Please sign in to comment.