uloha:had_class

Rozdíly

Zde můžete vidět rozdíly mezi vybranou verzí a aktuální verzí dané stránky.

Odkaz na výstup diff

Následující verze
Předchozí verze
uloha:had_class [2023/02/08 17:10] – vytvořeno adminuloha:had_class [2023/11/15 20:54] (aktuální) – upraveno mimo DokuWiki 127.0.0.1
Řádek 70: Řádek 70:
     }     }
 } }
 +</code>
 +
 +<code javascript>
 +class Game {
 +    width = 0
 +    height = 0
 +    htmlParent = null
 +    gameObjects = []
 +
 +
 +    constructor(width, height, htmlParent) {
 +        this.width = width
 +        this.height = height
 +        this.htmlParent = htmlParent
 +
 +        for (let y = 0; y < this.height; y++) {
 +            let row = document.createElement('tr')
 +            for (let x = 0; x < this.height; x++) {
 +                let cell = document.createElement('td')
 +                cell.id = `cell-${x}-${y}`
 +                cell.class = 'cell'
 +                row.appendChild(cell)
 +            }
 +            this.htmlParent.appendChild(row)
 +        }
 +
 +        // todo: setInterval na gameTick
 +    }
 +
 +    /*
 +     Funkce kterou podstrcime hadovi, aby se mohl vykreslit
 +     */
 +    drawElement(x, y, color) {
 +        const cell = document.getElementById(`cell-${x}-${y}`)
 +        cell.style.background = color
 +    }
 +
 +    gameTick() {
 +        // Smaz vsechno
 +        for (let y = 0; y < this.height; y++) {
 +            for (let x = 0; x < this.height; x++) {
 +                this.drawElement(x, y, 'white')
 +            }
 +        }
 +        // Vykresli vsechny objekty znovu
 +        for (const object of this.gameObjects) {
 +            object.draw(this.drawElement)
 +        }
 +    }
 +}
 +
 </code> </code>
  • uloha/had_class.1675876241.txt.gz
  • Poslední úprava: 2023/11/15 20:54
  • (upraveno mimo DokuWiki)