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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
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.coordsFontSize = cellSize * 0.7;
this.stage = stage;
var addSimpleCoord = function(self, textValue, position){
var text = new createjs.Text(textValue, self.coordsFontSize + "px Arial bold", "#000");
text.x = position[0];
text.y = position[1];
self.stage.addChild(text);
return [text.getMeasuredWidth(), text.getMeasuredHeight()];
};
var addCoordsTexts = function(self){
self.coordsTextDim = addSimpleCoord(self, "1", [self.pos[0], self.pos[1] + 7*self.cellSize + self.cellSize * 0.1]);
addSimpleCoord(self, "2", [self.pos[0], self.pos[1] + 6*self.cellSize + self.cellSize * 0.1]);
self.coordsTextWidth = addSimpleCoord(self, "3", [self.pos[0], self.pos[1] + 5*self.cellSize + self.cellSize * 0.1]);
addSimpleCoord(self, "4", [self.pos[0], self.pos[1] + 4*self.cellSize + self.cellSize * 0.1]);
addSimpleCoord(self, "5", [self.pos[0], self.pos[1] + 3*self.cellSize + self.cellSize * 0.1]);
addSimpleCoord(self, "6", [self.pos[0], self.pos[1] + 2*self.cellSize + self.cellSize * 0.1]);
addSimpleCoord(self, "7", [self.pos[0], self.pos[1] + 1*self.cellSize + self.cellSize * 0.1]);
addSimpleCoord(self, "8", [self.pos[0], self.pos[1] + 0*self.cellSize + self.cellSize * 0.1]);
addSimpleCoord(self, "A", [self.pos[0] + self.coordsTextDim[0] + self.cellSize * 0.4 + 0 * self.cellSize, self.pos[1] + 8*self.cellSize + self.cellSize * 0.1]);
addSimpleCoord(self, "B", [self.pos[0] + self.coordsTextDim[0] + self.cellSize * 0.4 + 1 * self.cellSize, self.pos[1] + 8*self.cellSize + self.cellSize * 0.1]);
addSimpleCoord(self, "C", [self.pos[0] + self.coordsTextDim[0] + self.cellSize * 0.4 + 2 * self.cellSize, self.pos[1] + 8*self.cellSize + self.cellSize * 0.1]);
addSimpleCoord(self, "D", [self.pos[0] + self.coordsTextDim[0] + self.cellSize * 0.4 + 3 * self.cellSize, self.pos[1] + 8*self.cellSize + self.cellSize * 0.1]);
addSimpleCoord(self, "E", [self.pos[0] + self.coordsTextDim[0] + self.cellSize * 0.4 + 4 * self.cellSize, self.pos[1] + 8*self.cellSize + self.cellSize * 0.1]);
addSimpleCoord(self, "F", [self.pos[0] + self.coordsTextDim[0] + self.cellSize * 0.4 + 5 * self.cellSize, self.pos[1] + 8*self.cellSize + self.cellSize * 0.1]);
addSimpleCoord(self, "G", [self.pos[0] + self.coordsTextDim[0] + self.cellSize * 0.4 + 6 * self.cellSize, self.pos[1] + 8*self.cellSize + self.cellSize * 0.1]);
addSimpleCoord(self, "H", [self.pos[0] + self.coordsTextDim[0] + self.cellSize * 0.4 + 7 * self.cellSize, self.pos[1] + 8*self.cellSize + self.cellSize * 0.1]);
};
addCoordsTexts(this);
},
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] + this.coordsTextDim[0] + this.cellSize * 0.2 + file * this.cellSize;
},
// rank : (0..7)
getRankY: function(rank){
return this.pos[1] + (7-rank) * this.cellSize;
},
getWidth: function(){
return this.coordsTextDim[0] + this.cellSize * 0.2 + 8 * this.cellSize;
},
getHeight: function(){
return this.cellSize * 0.2 + this.coordsTextDim[1] + 8 * 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();
}
};
|