forked from cwthompson/mouse_ai_template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
room.js
55 lines (47 loc) · 1.36 KB
/
room.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
function Room(mazeArea) {
this.numberOfDoors = 0;
this.doors = []; // doors refer to the location to adjacent rooms
this.x = mazeArea.x;
this.y = mazeArea.y;
this.isStart = false;
this.isFinish = false;
this.setRoomDetails(mazeArea)
}
Room.prototype.setRoomDetails = function (room) {
var doors = [];
var styleClass = 'tile';
if (!room.left) {
doors.push({x: room.x - 1, y: room.y});
styleClass = styleClass + ' no-wall-left';
}
if (!room.right) {
doors.push({x: room.x + 1, y: room.y});
styleClass = styleClass + ' no-wall-right';
}
if (!room.top) {
doors.push({x: room.x, y: room.y - 1});
styleClass = styleClass + ' no-wall-top';
}
if (!room.bottom) {
doors.push({x: room.x, y: room.y + 1});
styleClass = styleClass + ' no-wall-bottom';
}
if (room.isFinish) {
this.isFinish = true;
styleClass = styleClass + ' finish';
}
if (room.isStart) {
this.isStart = true;
styleClass = styleClass + ' start mouse';
}
this.styleId = 'roomX'+room.x+'Y'+room.y;
this.styleClass = styleClass;
this.doors = doors;
this.numberOfDoors = doors.length;
}
Room.prototype.getDoors = function () {
return this.doors;
}
module.exports.getRoom = function (mazeRoom) {
return new Room(mazeRoom);
};