-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboard.js
67 lines (52 loc) · 1.38 KB
/
board.js
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
var gridWidth = 100;
var gridHeigh = 100;
var mouseIsDown = false;
function Tile(x,y) {
this.x = x;
this.y = y;
this.el = document.createElement('div');
this.el.className = 'tile';
this.engadged = false;
}
Tile.prototype.applyToScreen = function() {
$(this.el).css('left', this.x * 50);
$(this.el).css('top', this.y * 50);
function checkChange(evt) {
if (!mouseIsDown && evt.type !== 'mousedown') {
return;
}
if (!this.engadged) {
this.engadged = true;
$(this.el).css('background-color', 'SteelBlue');
return;
}
this.engadged = false;
$(this.el).css('background-color', 'tomato');
}
function occupyWallStreet() {
$(this.el).css('background-color', 'SeaGreen');
}
$(this.el).mouseover(checkChange.bind(this));
$(this.el).mousedown(checkChange.bind(this));
$(this.el).dblclick(occupyWallStreet.bind(this));
document.body.appendChild(this.el);
};
function bindMouseListener() {
$(document.body).mousedown(function() {
console.log('DEBUG', 'mouse is down');
mouseIsDown = true;
});
$(document.body).mouseup(function() {
console.log('DEBUG', 'mouse is up');
mouseIsDown = false;
});
}
window.createBoard = function() {
bindMouseListener();
for (var i = 0; i < gridWidth; ++i) {
for (var j = 0; j < gridHeigh; ++j) {
var tile = new Tile(i,j);
tile.applyToScreen();
}
}
};