-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
146 lines (123 loc) · 3.45 KB
/
index.html
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>Maze Creator</h1>
<script>
class MapSite {
constructor() {
if (this.constructor === MapSite) {
throw 'this is an Abstrct Class';
}
}
enter() {
throw 'this method need to be implemented on each subClass';
}
}
class Room extends MapSite {
constructor() {
super();
this.name = `room${Room.prototype.conteo}`;
this.roomNumber = Room.prototype.conteo;
this.structure = {};
console.log(`creating room number ${this.roomNumber}`);
Room.prototype.conteo++;
}
enter() {
console.log(`your are now on room number ${this.roomNumber}`);
}
setSide(direction, MapSiteComponent) {
if (
!(
direction === 'N' ||
direction === 'S' ||
direction === 'E' ||
direction === 'W'
)
) {
throw 'you have to set a real direction N, S, E, or W';
} else {
this.structure[direction] = MapSiteComponent;
}
}
getSide(direction) {
if (
!(
direction === 'N' ||
direction === 'S' ||
direction === 'E' ||
direction === 'W'
)
) {
throw 'you have to set a real direction N, S, E, or W';
} else if (this[direction]) {
console.log(this[direction].name);
} else {
console.log('nothing There');
}
}
}
Room.prototype.conteo = 1;
class Wall extends MapSite {
constructor() {
super();
this.name = `Wall${Wall.prototype.conteo}`;
this.wallNumber = Wall.prototype.conteo;
console.log(`creating wall number ${this.wallNumber}`);
Wall.prototype.conteo++;
}
}
Wall.prototype.conteo = 1;
class Door extends MapSite {
constructor(roomA, roomB) {
super();
if (!(roomA && roomB)) {
throw 'need two rooms';
}
this.name = `Door${Door.prototype.conteo}`;
this.doorNumber = Door.prototype.conteo;
this.between = [roomA.name, roomB.name];
console.log(
`creating door # ${this.doorNumber} between ${this.between[0]} and ${this.between[1]} `
);
Door.prototype.conteo++;
}
}
Door.prototype.conteo = 1;
class Maze {
constructor() {
console.log(`creating a new Maze`);
this.rooms = [];
}
addRoom(room) {
this.rooms.push(room);
}
/* TODO: create search RoomNo. method */
}
class MazeGame {
constructor() {
console.log(`creating a new MazeGame`);
}
createMaze() {
const firstMaze = new Maze();
const r1 = new Room();
const r2 = new Room();
const theDoor = new Door(r1, r2);
firstMaze.addRoom(r1);
firstMaze.addRoom(r2);
r1.setSide('N', new Wall());
r1.setSide('E', theDoor);
r1.setSide('S', new Wall());
r1.setSide('W', new Wall());
r2.setSide('N', new Wall());
r2.setSide('E', new Wall());
r2.setSide('S', new Wall());
r2.setSide('W', theDoor);
return firstMaze;
}
}
myMaze = new MazeGame().createMaze();
</script>
</body>
</html>