Skip to content

Commit 723ca7a

Browse files
committed
Añade creación del laberinto en ASCII para MMSIM
1 parent 194c0d2 commit 723ca7a

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

utils/maze-wall-placer.html

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,12 @@ <h4 class="title">Maze Array</h4>
131131
<textarea name="maze-array" id="maze-array" rows="4" class="form-control bg-light p-4"></textarea>
132132
</div>
133133
</div>
134+
<div class="row mb-5">
135+
<div class="col">
136+
<h4 class="title">Maze ASCII</h4>
137+
<textarea name="maze-ascii" id="maze-ascii" rows="4" class="form-control bg-light p-4 text-center" style="font-family: monospace;"></textarea>
138+
</div>
139+
</div>
134140

135141
</div>
136142

@@ -436,6 +442,7 @@ <h4 class="title">Maze Array</h4>
436442
}
437443
clearFades(td_snap);
438444
buildMazeArray();
445+
buildMazeAscii();
439446
}
440447

441448
let table = document.createElement("table");
@@ -514,6 +521,7 @@ <h4 class="title">Maze Array</h4>
514521
}
515522

516523
buildMazeArray();
524+
buildMazeAscii();
517525
};
518526

519527
let buildMazeArray = function () {
@@ -557,6 +565,47 @@ <h4 class="title">Maze Array</h4>
557565
document.getElementById("maze-array").value = JSON.stringify(maze_array);
558566
};
559567

568+
let buildMazeAscii = function () {
569+
let maze_ascii = "";
570+
let maze_table = document.getElementById("maze-table");
571+
let rows = maze_table.rows.length;
572+
let cols = maze_table.rows[0].cells.length;
573+
574+
for (let row = 0; row < rows; row++) {
575+
for (let col = 0; col < cols; col++) {
576+
let cell = maze_table.rows[row].cells[col];
577+
// First row of the ASCII cell
578+
maze_ascii += "+";
579+
if (cell.classList.contains("border-top")) {
580+
maze_ascii += "---";
581+
} else {
582+
maze_ascii += " ";
583+
}
584+
}
585+
maze_ascii += "+\n"; // End of the row
586+
for (let col = 0; col < cols; col++) {
587+
let cell = maze_table.rows[row].cells[col];
588+
// Second row of the ASCII cell
589+
if (cell.classList.contains("border-left")) {
590+
maze_ascii += "|";
591+
} else {
592+
maze_ascii += " ";
593+
}
594+
maze_ascii += " ";
595+
}
596+
maze_ascii += "|\n"; // End of the row
597+
}
598+
for (let col = 0; col < cols; col++) {
599+
maze_ascii += "+";
600+
maze_ascii += "---";
601+
}
602+
maze_ascii += "+"; // End of the last row
603+
604+
console.log(maze_ascii);
605+
document.getElementById("maze-ascii").value = maze_ascii;
606+
document.getElementById("maze-ascii").rows = Math.max(4, rows * 2 + 1); // Adjust rows based on the number of rows in the maze
607+
}
608+
560609
let updateBordersFromArray = function (maze_array) {
561610
let maze_table = document.getElementById("maze-table");
562611
let rows = maze_table.rows.length;
@@ -605,6 +654,7 @@ <h4 class="title">Maze Array</h4>
605654
}
606655

607656

657+
buildMazeAscii();
608658
};
609659

610660

0 commit comments

Comments
 (0)