Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen der Seite angezeigt.
| Beide Seiten, vorherige Überarbeitung Vorherige Überarbeitung Nächste Überarbeitung | Vorherige Überarbeitung | ||
| talit:web:webapps:client [2025-02-05 06:36] – hof | talit:web:webapps:client [2026-08-10 15:12] (aktuell) – [Darstellung in HTML] hof | ||
|---|---|---|---|
| Zeile 1: | Zeile 1: | ||
| ## Client-Side Vier Gewinnt | ## Client-Side Vier Gewinnt | ||
| - | [[wpde> | + | [[wpde> |
| {{: | {{: | ||
| - | |||
| ### Auftrag A: Struktur & Formatierung | ### Auftrag A: Struktur & Formatierung | ||
| - | Erstelle HTML & CSS, um ein Vier-Gewinnt-Spiel darzustellen: | + | Erstelle |
| * Erstelle einen neuen Ordner, in dem die ganze Web-App enthalten sein wird! | * Erstelle einen neuen Ordner, in dem die ganze Web-App enthalten sein wird! | ||
| Zeile 79: | Zeile 78: | ||
| * ... schaltet die Farbe des Spielers um. | * ... schaltet die Farbe des Spielers um. | ||
| + | Um den Code etwas zu strukturieren, | ||
| + | <code javascript> | ||
| + | /** Drops a piece in the given column and updates the game state accordingly. */ | ||
| + | function dropPiece(grid, | ||
| + | // Check if move is valid. | ||
| + | if (game.state != " | ||
| + | return; | ||
| + | } | ||
| + | // Compute the lowest empty row in the selected column. | ||
| + | let row = computeEmptyRow(game, | ||
| + | let cell = row * 7 + column; | ||
| + | // Update game state. | ||
| + | game.board[cell] = game.next; | ||
| + | // Check for winner / tie, will set game.state if game ended. | ||
| + | checkWinner(game, | ||
| + | // Swap active player | ||
| + | if (game.state == " | ||
| + | togglePlayer(game); | ||
| + | } | ||
| + | // Update the HTML view. | ||
| + | updateHtml(grid, | ||
| + | // Update game status area to reflect active player / winner / tie | ||
| + | updateStatus(status, | ||
| + | } | ||
| + | </ | ||
| #### Darstellung in HTML | #### Darstellung in HTML | ||
| Zeile 86: | Zeile 110: | ||
| Um die Darstellung des Spiels zu ändern, setzen wir den Text des Buttons mit der [[https:// | Um die Darstellung des Spiels zu ändern, setzen wir den Text des Buttons mit der [[https:// | ||
| - | <code javascript | + | <code javascript |
| let color = game.board[cell]; | let color = game.board[cell]; | ||
| button.textContent = color; | button.textContent = color; | ||
| Zeile 94: | Zeile 118: | ||
| In [[gf_informatik: | In [[gf_informatik: | ||
| - | <code css tictactoe.css> | + | <code css connect4.css> |
| button[data-state=" | button[data-state=" | ||
| background-color: | background-color: | ||