Rozdíly
Zde můžete vidět rozdíly mezi vybranou verzí a aktuální verzí dané stránky.
Následující verze | Předchozí verze | ||
uloha:had_class [2023/02/08 17:10] – vytvořeno admin | uloha:had_class [2023/11/15 20:54] (aktuální) – upraveno mimo DokuWiki 127.0.0.1 | ||
---|---|---|---|
Řádek 70: | Řádek 70: | ||
} | } | ||
} | } | ||
+ | </ | ||
+ | |||
+ | <code javascript> | ||
+ | class Game { | ||
+ | width = 0 | ||
+ | height = 0 | ||
+ | htmlParent = null | ||
+ | gameObjects = [] | ||
+ | |||
+ | |||
+ | constructor(width, | ||
+ | this.width = width | ||
+ | this.height = height | ||
+ | this.htmlParent = htmlParent | ||
+ | |||
+ | for (let y = 0; y < this.height; | ||
+ | let row = document.createElement(' | ||
+ | for (let x = 0; x < this.height; | ||
+ | let cell = document.createElement(' | ||
+ | cell.id = `cell-${x}-${y}` | ||
+ | cell.class = ' | ||
+ | row.appendChild(cell) | ||
+ | } | ||
+ | this.htmlParent.appendChild(row) | ||
+ | } | ||
+ | |||
+ | // todo: setInterval na gameTick | ||
+ | } | ||
+ | |||
+ | /* | ||
+ | | ||
+ | */ | ||
+ | drawElement(x, | ||
+ | const cell = document.getElementById(`cell-${x}-${y}`) | ||
+ | cell.style.background = color | ||
+ | } | ||
+ | |||
+ | gameTick() { | ||
+ | // Smaz vsechno | ||
+ | for (let y = 0; y < this.height; | ||
+ | for (let x = 0; x < this.height; | ||
+ | this.drawElement(x, | ||
+ | } | ||
+ | } | ||
+ | // Vykresli vsechny objekty znovu | ||
+ | for (const object of this.gameObjects) { | ||
+ | object.draw(this.drawElement) | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
</ | </ |