@@ -14,20 +14,39 @@ class Maze {
1414 constructor ( mazeSettings ) {
1515 this . prng = mazeSettings . prng ?? Math ;
1616 this . width = mazeSettings . width ||
17- mazeSettings . xSize || mazeSettings . size || mazeSettings . height || mazeSettings . ySize || 30 ;
17+ mazeSettings . xSize || mazeSettings . size || mazeSettings . height ||
18+ mazeSettings . ySize || 30 ;
1819 this . height = mazeSettings . height ||
1920 mazeSettings . ySize || mazeSettings . size || this . width ;
2021 this . finishedGenerating = false ;
2122 this . seed = mazeSettings . seed ?? Math . floor ( Math . random ( ) * 10e8 ) ;
2223 this . algorithm = mazeSettings . algorithm ;
2324 this . algorithmId = mazeSettings . algorithmId ;
24-
25+
2526 this . entrance = this . getXYPosition ( mazeSettings . entrance ?? "top left" ) ;
2627
2728 this . exit = this . getXYPosition ( mazeSettings . exit ?? "bottom right" ) ;
2829
29- this . entrance . direction = this . entrance . direction ?? ( this . entrance . x <= 0 ? "W" : this . entrance . x >= this . width - 1 ? "E" : this . entrance . y <= 0 ? "N" : this . entrance . y >= this . width - 1 ? "S" : " " ) ;
30- this . exit . direction = this . exit . direction ?? ( this . exit . x <= 0 ? "W" : this . exit . x >= this . width - 1 ? "E" : this . exit . y <= 0 ? "N" : this . exit . y >= this . width - 1 ? "S" : " " ) ;
30+ this . entrance . direction = this . entrance . direction ??
31+ ( this . entrance . x <= 0
32+ ? "W"
33+ : this . entrance . x >= this . width - 1
34+ ? "E"
35+ : this . entrance . y <= 0
36+ ? "N"
37+ : this . entrance . y >= this . width - 1
38+ ? "S"
39+ : " " ) ;
40+ this . exit . direction = this . exit . direction ??
41+ ( this . exit . x <= 0
42+ ? "W"
43+ : this . exit . x >= this . width - 1
44+ ? "E"
45+ : this . exit . y <= 0
46+ ? "N"
47+ : this . exit . y >= this . width - 1
48+ ? "S"
49+ : " " ) ;
3150
3251 if (
3352 this . algorithmId === "sidewinder" ||
@@ -106,7 +125,7 @@ class Maze {
106125 }
107126
108127 step ( ) {
109- if ( this . finishedGenerating ) return false ;
128+ if ( this . finishedGenerating ) return false ;
110129 this . takeStep ( ) ;
111130 return ! this . finishedGenerating ;
112131 }
0 commit comments