route-planner-ip2-public/maze-editor.html
2025-06-14 23:26:42 +02:00

128 lines
3.6 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Maze Editor</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
h1 {
color: #444;
}
.maze-container {
display: flex;
justify-content: center;
}
table {
border-collapse: collapse;
}
td {
border: 1px solid #ccc;
width: 20px;
height: 20px;
text-align: center;
}
input[type="checkbox"] {
width: 20px;
height: 20px;
margin: 0;
}
.cell-0 {
background-color: #fff;
}
.cell-1 {
background-color: #ddd;
}
.button {
margin-top: 20px;
}
#output {
font-family: monospace;
margin-top: 20px;
}
input[disabled] {
cursor: not-allowed;
}
</style>
</head>
<body>
<h1>Maze Editor</h1>
<div id="maze-container" class="maze-container"></div>
<button class="button" onclick="printArray()">Show Array</button>
<div id="output"></div>
<script>
const MAZE_SIZE = 11;
// Original matrix with -1's
const originalMatrix = [
[ -1, -1, -1, 0, -1, 0, -1, 0, -1, -1, -1 ],
[ -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1 ],
[ -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1 ],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
[ -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1 ],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
[ -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1 ],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
[ -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1 ],
[ -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1 ],
[ -1, -1, -1, 0, -1, 0, -1, 0, -1, -1, -1 ]
];
// Work copy for editing
let mazeData = JSON.parse(JSON.stringify(originalMatrix));
function initMaze() {
const container = document.getElementById("maze-container");
container.innerHTML = "";
const table = document.createElement("table");
for (let i = 0; i < MAZE_SIZE; i++) {
const tr = document.createElement("tr");
for (let j = 0; j < MAZE_SIZE; j++) {
const td = document.createElement("td");
const checkbox = document.createElement("input");
checkbox.type = "checkbox";
checkbox.checked = mazeData[i][j] === -1;
// Disable if original value is -1 OR not at even indices
checkbox.disabled =
originalMatrix[i][j] === -1 ||
!(i % 2 === 0 || j % 2 === 0) ||
checkbox.addEventListener("change", function () {
mazeData[i][j] = this.checked ? -1 : 0;
updateCellClass(td, this.checked);
});
td.appendChild(checkbox);
updateCellClass(td, mazeData[i][j] === -1);
tr.appendChild(td);
}
table.appendChild(tr);
}
container.appendChild(table);
}
function updateCellClass(td, isWall) {
td.className = isWall ? "cell-1" : "cell-0";
}
function printArray() {
let output = "int unexpanded_matrix[MAZE_SIZE][MAZE_SIZE] = {\n";
for (let i = 0; i < MAZE_SIZE; i++) {
output += "\t{";
for (let j = 0; j < MAZE_SIZE; j++) {
output += mazeData[i][j];
if (j < MAZE_SIZE - 1) output += ", ";
}
output += "}";
if (i < MAZE_SIZE - 1) output += ",";
output += "\n";
}
output += "};";
document.getElementById("output").textContent = output;
}
window.onload = initMaze;
</script>
</body>
</html>