blob: a6ca6555886b944c2e9851223539349c0ba590ed (
plain)
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
|
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;
},
// Just call it once.
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();
}
};
|