fixed a bug with handling changing board sizes when size is decreased more by 1 row / column

main
Inga 🏳‍🌈 3 days ago
parent a42ecfe0ce
commit dba3c7f55c
  1. 16
      src/frontend/components/board-game.ts

@ -49,11 +49,11 @@ export class BoardGameComponent extends HTMLElement {
for (const tbodyUntyped of this.querySelectorAll("tbody.game-board")) {
const tbody = tbodyUntyped as HTMLTableSectionElement;
for (let rowNumberToRemove = gameState.rows; rowNumberToRemove < tbody.rows.length; rowNumberToRemove++) {
tbody.rows[rowNumberToRemove]?.remove();
while (gameState.rows < tbody.rows.length) {
tbody.rows[0]?.remove();
}
for (let rowNumberToAdd = tbody.rows.length; rowNumberToAdd < gameState.rows; rowNumberToAdd++) {
while (gameState.rows > tbody.rows.length) {
tbody.insertRow();
}
@ -63,15 +63,11 @@ export class BoardGameComponent extends HTMLElement {
continue;
}
for (
let columnNumberToRemove = gameState.columns;
columnNumberToRemove < row.cells.length;
columnNumberToRemove++
) {
row.cells[columnNumberToRemove]?.remove();
while (gameState.columns < row.cells.length) {
row.cells[0]?.remove();
}
for (let columnNumberToAdd = row.cells.length; columnNumberToAdd < gameState.columns; columnNumberToAdd++) {
while (gameState.columns > row.cells.length) {
row.insertCell();
}

Loading…
Cancel
Save