diff options
Diffstat (limited to 'lib/customs/graphical_board.js')
-rw-r--r-- | lib/customs/graphical_board.js | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/lib/customs/graphical_board.js b/lib/customs/graphical_board.js new file mode 100644 index 0000000..57df226 --- /dev/null +++ b/lib/customs/graphical_board.js @@ -0,0 +1,46 @@ +var GraphicalBoard = Class.create(); +GraphicalBoard.prototype = { + // pos : a literal array of two integers => e.g [3,10] + // cellSize : an integer + // stage : createjs stage + initialize: function(pos, cellSize, stage){ + this.pos = pos; + this.cellSize = cellSize; + this.stage = stage; + }, + getX: function(){ + return this.pos[0]; + }, + getY: function(){ + return this.pos[1]; + }, + getCellSize: function(){ + return this.cellSize; + }, + // file : (0..7) + getFileX: function(file){ + return this.pos[0] + file * this.cellSize; + }, + // rank : (0..7) + getRankY: function(rank){ + return this.pos[1] + (7-rank) * this.cellSize; + }, + addToStage: function(){ + for (var rank = 0; rank < 8; rank++){ + for (var file = 0; file < 8; file++){ + var color; + if ((rank+file) % 2 !== 0) color = "#FFDB58"; + else color = "#6F4E37"; + + var rectangle = new createjs.Shape(); + rectangle.graphics.beginFill(color).drawRect( + this.getFileX(file), this.getRankY(rank), this.cellSize, this.cellSize + ); + + this.stage.addChild(rectangle); + } + } + this.stage.update(); + } + +};
\ No newline at end of file |