-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrobo.js
80 lines (74 loc) · 2.37 KB
/
robo.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
68
69
70
71
72
73
74
75
76
77
78
79
80
const robo = {
x: null,
y: null,
currentCell: null,
hasBox: false,
show: function (newX, newY) {
if (newX !== null && newX !== undefined) {
this.x = parseInt(newX);
}
if (newY !== null && newY !== undefined) {
this.y = parseInt(newY);
}
if (this.hasBox) {
box.x = this.x;
box.y = this.y;
}
this.currentCell = document.getElementById("cell_" + this.x.toString() + this.y.toString());
if (!(this.currentCell)) {
return false;
}
if (box.x == this.x && box.y == this.y) {
if (this.hasBox) {
this.currentCell.style.backgroundImage = "url('box.png'), url('robo.png')";
this.currentCell.style.backgroundSize = "50%, cover";
} else {
this.currentCell.style.backgroundImage = "url('robo.png'), url('box.png')";
this.currentCell.style.backgroundSize = "cover, cover";
}
} else {
this.currentCell.style.backgroundImage = "url('robo.png')";
this.currentCell.style.backgroundSize = "cover";
}
return true;
},
hide: function () {
if (this.currentCell) {
this.currentCell.style.backgroundImage = null;
this.currentCell = null;
if (!(this.hasBox) && box.x == this.x && box.y == this.y) {
box.show();
}
}
},
move: function (newX, newY) {
this.hide();
return this.show(newX, newY);
},
getBox: function () {
if (box.x == this.x && box.y == this.y) {
this.hasBox = true;
return this.show();
} else {
return false;
}
},
dropBox: function () {
if (this.hasBox) {
this.hasBox = false;
return this.show();
} else {
return false;
}
},
say: function (text) {
const tooltip = document.getElementById("tooltip_" + this.x.toString() + this.y.toString());
tooltip.appendChild(document.createTextNode(text));
tooltip.style.visibility = "visible";
},
shutUp: function () {
const tooltip = document.getElementById("tooltip_" + this.x.toString() + this.y.toString());
tooltip.style.visibility = "hidden";
tooltip.innerHTML = "";
}
}