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

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

Loading…
Cancel
Save