/** * ============================================================================================== * Modul: DVL17 — DAS VERRÜCKTE LABYRINTH (SOLO-AI & OPEN-ROOM MULTIPLAYER EDITION) * Datei: dvl17.pde * Framework: DTIM-ZEC MODULAR PHYSICS FRAMEWORK (DAMTP ACADEMIC STANDARD) * Version: 17.3.0 (Tactical AI Pirates + Live AI-Slot Takeover via dvl17_lobby.php) * Author: Jan Buehring & Adaptive Intelligence Synthesis Network (Google AI) * License: MIT License * Copyright: (c) 2026 Jan Bühring & Adaptive Intelligence Synthesis Network (Google AI) * Plattform: Processing 4.5.6 (Linux x64) & Processing.js (processing.min.js) * * Steuerung: * [Einzelspieler / KI] : Pirat 2-4 spielen automatisch als KI (auf [KI]/[MENSCH] klicken zum Wechseln). * [Offenes Spiel] : Besucht ein 2. Spieler die Seite, erscheint oben das Banner zum Ersetzen * einer KI per Klick ([Pirat 2 übernehmen] usw.). * [1. Karte schieben] : Reservekarte drehen [R], dann Randpfeil klicken. Gegner rausgeschoben * (-1 Energie) -> Gegner landet als Geisel auf eigenem Kartenplatz! * [2. Geisel halten] : [G] überspringt den Zug, hält den Gegner gefangen und gibt +1 Energie. * [3. Pirat laufen] : [W/A/S/D] / [Pfeile] oder Nachbarfeld anklicken. [Y] Ordentlich beenden. * [4. Siegpunkte] : Genau 4 Punkte = +1 SP | Rundenende mit != 4 Punkten = +3 SP. * [H] : Sehhilfe (DTIM Standard / Farbenblind / Max-Kontrast). * ============================================================================================== */ // ============================================================================================== // MODUL 1: GLOBALE SYSTEMKONSTANTEN & SPIELZUSTAND (100% PROCESSING.JS-SICHER) // ============================================================================================== int MAX_GRID = 9; int gridN = 7; // Standard 7x7, umschaltbar 5 / 7 / 9 int MAX_ENERGY = 7; // Lebensenergie 0 .. 7 int SERIES_GOAL_VP = 5; // Gesamtsieg der Serie ab 5 Siegpunkten float BOARD_X = 255.0; float BOARD_Y = 112.0; float BOARD_SIZE = 536.0; MazeTile[][] board = new MazeTile[9][9]; MazeTile spareTile; PirateAgent[] pirates = new PirateAgent[4]; int activePirate = 0; // 0..3 (Pirat 1 bis Pirat 4) int turnPhase = 0; // 0 = Karte einschieben / Geisel, 1 = Laufen, 2 = Rundenende boolean editorMode = false; int roundNumber = 1; int roundWinner = -1; int awardedVP = 0; String roundEndReason = ""; int a11yTheme = 0; // 0: DTIM Standard, 1: Farbenblind, 2: Max-Kontrast // Sperre gegen direktes Zurückschieben desselben Pfeils int blockedArrowSide = -1; int blockedArrowIndex = -1; // Flüssige Schiebe-Animation int animAxis = -1; int animLineIndex = 0; float animOffsetPx = 0.0; // KI-Steuerung (für Einzelspieler & offene Räume) boolean[] isAiSeat = { false, true, true, true }; int aiThinkTimer = 0; int aiSubStep = 0; // 0 = Karte drehen/schieben, 1 = Schritt laufen/beenden // Offene Online-Lobby (+1 / -1 Besucher-Sync über dvl17_lobby.php) String myClientId = ""; boolean lobbyConnected = false; boolean lobbyEnabled = true; int lobbyHumans = 1; int mySeatIndex = 0; // -1 = Zuschauer (kann KI ersetzen!), 0..3 = eigener Pirat int roomRevision = 0; int lobbyPollCooldown = 0; String lobbyBannerMsg = ""; boolean[][] reachable = new boolean[9][9]; String statusLine = "Pirat 1 beginnt: Karte drehen [R] & einschieben (4 Pkt = 1 SP | !=4 Pkt = 3 SP)"; // ============================================================================================== // MODUL 2: DATENSTRUKTUREN // ============================================================================================== class MazeTile { boolean n; boolean e; boolean s; boolean w; int lootType; // 0 = leer, 1 = Silber (+1 Punkt), 2 = Gold (+2 Punkte) MazeTile(boolean north, boolean east, boolean south, boolean west) { n = north; e = east; s = south; w = west; lootType = 0; } void rotateClockwise() { boolean oldN = n; n = w; w = s; s = e; e = oldN; } } class PirateAgent { int id; String name; int gx; int gy; float vx; float vy; int energy; int roundPoints; int victoryPoints; int stepsTaken; int maxStepsTurn; int captiveOf; // -1 = frei, 0..3 = Geisel auf Kartenplatz von Pirat X PirateAgent(int idx, String label, int startX, int startY) { id = idx; name = label; gx = startX; gy = startY; vx = float(startX); vy = float(startY); energy = MAX_ENERGY; roundPoints = 0; victoryPoints = 0; stepsTaken = 0; maxStepsTurn = 4; captiveOf = -1; } } // ============================================================================================== // MODUL 3: FARB-PALETTEN (SCHWARZ / BLUTROT / NACHTBLAU / SILBERGRAU + SEHHILFE) // ============================================================================================== int getUiColor(int theme, int role) { if (theme == 1) { if (role == 0) return color(5, 9, 17); if (role == 1) return color(11, 17, 29); if (role == 2) return color(180, 120, 10); if (role == 3) return color(10, 75, 130); if (role == 4) return color(251, 191, 36); if (role == 5) return color(15, 23, 42); return color(226, 238, 255); } if (theme == 2) { if (role == 0) return color(0, 0, 0); if (role == 1) return color(0, 0, 0); if (role == 2) return color(0, 0, 0); if (role == 3) return color(0, 0, 0); if (role == 4) return color(255, 255, 0); if (role == 5) return color(0, 0, 0); return color(255, 255, 255); } if (role == 0) return color(6, 8, 14); if (role == 1) return color(13, 16, 26); if (role == 2) return color(122, 16, 38); if (role == 3) return color(18, 46, 98); if (role == 4) return color(225, 55, 85); if (role == 5) return color(14, 18, 28); return color(232, 238, 248); } int getPirateColor(int theme, int pIdx) { if (theme == 1) { if (pIdx == 0) return color(56, 189, 248); if (pIdx == 1) return color(251, 191, 36); if (pIdx == 2) return color(52, 211, 153); return color(244, 114, 182); } if (theme == 2) { if (pIdx == 0) return color(0, 255, 255); if (pIdx == 1) return color(255, 255, 0); if (pIdx == 2) return color(0, 255, 120); return color(255, 120, 255); } if (pIdx == 0) return color(58, 135, 255); if (pIdx == 1) return color(35, 210, 115); if (pIdx == 2) return color(0, 225, 245); return color(235, 55, 80); } // ============================================================================================== // MODUL 4: INITIALISIERUNG & RUNDEN-AUFBAU // ============================================================================================== void setup() { size(1060, 770); noSmooth(); frameRate(60); myClientId = "P" + int(random(100000, 999999)) + "_" + millis(); for (int i = 0; i < 4; i++) { pirates[i] = new PirateAgent(i, "Pirat " + (i + 1), 0, 0); } startNewRound(true, false); // Prüfe einmalig beim Start, ob dvl17_lobby.php auf dem Webspace aktiv ist syncWithLobby("poll", -1, false); if (lobbyConnected) { if (lobbyHumans == 0) { // Erster Besucher (+1): Übernimmt sofort Pirat 1 und teilt das laufende Spiel! syncWithLobby("claim", 0, false); syncWithLobby("push", mySeatIndex, true); } else { // Es läuft bereits ein offenes Spiel! Besucher startet als Zuschauer und kann eine KI ersetzen mySeatIndex = -1; } } } void startNewRound(boolean resetSeriesVP, boolean pushOnline) { if (resetSeriesVP) { roundNumber = 1; for (int i = 0; i < 4; i++) { pirates[i].victoryPoints = 0; } } activePirate = 0; turnPhase = 0; editorMode = false; roundWinner = -1; awardedVP = 0; roundEndReason = ""; blockedArrowSide = -1; blockedArrowIndex = -1; animAxis = -1; animOffsetPx = 0.0; aiThinkTimer = 24; aiSubStep = 0; for (int y = 0; y < gridN; y++) { for (int x = 0; x < gridN; x++) { board[x][y] = createRandomTile(); } } board[0][0] = new MazeTile(false, true, true, false); board[gridN - 1][0] = new MazeTile(false, false, true, true); board[0][gridN - 1] = new MazeTile(true, true, false, false); board[gridN - 1][gridN - 1] = new MazeTile(true, false, false, true); spareTile = createRandomTile(); int[] sx = { 0, gridN - 1, 0, gridN - 1 }; int[] sy = { 0, 0, gridN - 1, gridN - 1 }; for (int i = 0; i < 4; i++) { pirates[i].gx = sx[i]; pirates[i].gy = sy[i]; pirates[i].vx = float(sx[i]); pirates[i].vy = float(sy[i]); pirates[i].energy = MAX_ENERGY; pirates[i].roundPoints = 0; pirates[i].stepsTaken = 0; pirates[i].maxStepsTurn = 4; pirates[i].captiveOf = -1; } for (int s = 0; s < 7; s++) spawnLootTile(1); for (int g = 0; g < 3; g++) spawnLootTile(2); computeReachableTiles(); statusLine = "Runde " + roundNumber + " · Pirat 1: Karte drehen [R] & einschieben (4 Pkt = 1 SP | !=4 Pkt = 3 SP)"; if (pushOnline && lobbyConnected && mySeatIndex >= 0) { syncWithLobby("push", mySeatIndex, true); } } MazeTile createRandomTile() { int kind = int(random(0, 3)); MazeTile t; if (kind == 0) t = new MazeTile(true, false, true, false); else if (kind == 1) t = new MazeTile(true, true, false, false); else t = new MazeTile(true, true, false, true); int rots = int(random(0, 4)); for (int r = 0; r < rots; r++) { t.rotateClockwise(); } return t; } void spawnLootTile(int lootKind) { for (int attempt = 0; attempt < 150; attempt++) { int rx = int(random(0, gridN)); int ry = int(random(0, gridN)); if (board[rx][ry].lootType != 0) continue; boolean onStart = (rx == 0 && ry == 0) || (rx == gridN - 1 && ry == 0) || (rx == 0 && ry == gridN - 1) || (rx == gridN - 1 && ry == gridN - 1); if (!onStart) { board[rx][ry].lootType = lootKind; return; } } } // ============================================================================================== // MODUL 5: HAUPTSCHLEIFE & KI-AUTOPILOT // ============================================================================================== void draw() { background(getUiColor(a11yTheme, 0)); // Periodischer Herzschlag & Raum-Sync (ca. alle 2.2 Sekunden, wenn Online-Lobby aktiv) if (lobbyConnected && lobbyEnabled) { lobbyPollCooldown++; if (lobbyPollCooldown >= 135) { lobbyPollCooldown = 0; syncWithLobby("poll", -1, false); } } // Flüssige Schiebe- & Bewegungs-Interpolation if (abs(animOffsetPx) > 0.4) { animOffsetPx = lerp(animOffsetPx, 0.0, 0.28); } else { animOffsetPx = 0.0; animAxis = -1; } for (int i = 0; i < 4; i++) { if (pirates[i].captiveOf == -1) { pirates[i].vx = lerp(pirates[i].vx, float(pirates[i].gx), 0.28); pirates[i].vy = lerp(pirates[i].vy, float(pirates[i].gy), 0.28); } } // KI-Zug ausführen (im Solo-Modus immer lokal; im Online-Modus steuert der niedrigste Menschen-Slot die KIs) if (turnPhase != 2 && isAiSeat[activePirate] && canLocalClientRunAi()) { aiThinkTimer--; if (aiThinkTimer <= 0) { executeAiStep(); } } // 1. Obere Steuer-Leiste & Offenes-Spiel-Banner (falls ein zweiter Besucher beitritt) drawTopBar(); drawOpenRoomBanner(); // 2. Vier Piraten-Terminals links & rechts drawPirateCard(0, 14, 84); drawPirateCard(2, 14, 426); drawPirateCard(1, 834, 84); drawPirateCard(3, 834, 426); // 3. Zentrales Spielfeld & Einschub-Pfeile drawInsertionArrows(); drawLabyrinthBoard(); // 4. Untere Statusleiste drawBottomStatusBar(); // 5. Runden-Sieg-Dialog if (turnPhase == 2 && roundWinner >= 0) { drawRoundVictoryModal(); } } boolean canLocalClientRunAi() { if (!lobbyConnected || !lobbyEnabled) return true; if (mySeatIndex < 0) return false; for (int i = 0; i < mySeatIndex; i++) { if (!isAiSeat[i]) return false; // Ein Mitspieler mit niedrigerer Piraten-ID übernimmt die KI-Berechnung } return true; } boolean canLocalControlPirate(int pIdx) { if (isAiSeat[pIdx]) return false; if (!lobbyConnected || !lobbyEnabled) return true; return (mySeatIndex == pIdx); } // Taktische KI für Pirat 2-4 (nutzt Geisel-Regel, Schatzsuche, 4-Punkte-Taktik & Erholung) void executeAiStep() { PirateAgent ai = pirates[activePirate]; if (turnPhase == 0) { // Prüfe zuerst: Sitzt eine Geisel auf dem Kartenplatz und braucht die KI Lebensenergie? int hostage = getHostageOfPirate(activePirate); if (hostage != -1 && ai.energy <= 4) { holdHostageAndSkipTurn(); aiThinkTimer = 26; return; } // Besten Einschub (Pfeil & Rotation) suchen int bestSide = 0; int bestIdx = 1; int bestRot = 0; int bestScore = -9999; for (int side = 0; side < 4; side++) { for (int idx = 1; idx < gridN; idx += 2) { if (side == blockedArrowSide && idx == blockedArrowIndex) continue; int evalScore = int(random(0, 18)); // Bevorzuge Reihen/Spalten, in denen Schätze liegen oder der eigene Pirat steht for (int k = 0; k < gridN; k++) { int cx = (side == 0 || side == 2) ? idx : k; int cy = (side == 0 || side == 2) ? k : idx; if (board[cx][cy].lootType > 0) evalScore += 24 * board[cx][cy].lootType; if (ai.gx == cx && ai.gy == cy) evalScore += 14; } // Prüfe, ob ein Gegner am Rand rausgeschoben werden kann (Geiselnahme!) int victim = previewPushedOffPirate(side, idx); if (victim != -1 && victim != activePirate && ai.energy >= 4) { evalScore += 45; } else if (victim == activePirate) { evalScore -= 25; } if (evalScore > bestScore) { bestScore = evalScore; bestSide = side; bestIdx = idx; bestRot = int(random(0, 4)); } } } for (int r = 0; r < bestRot; r++) { spareTile.rotateClockwise(); } insertSpareTileAt(bestSide, bestIdx); aiSubStep = 1; aiThinkTimer = 24; return; } if (turnPhase == 1) { if (ai.stepsTaken >= ai.maxStepsTurn || ai.energy <= 1) { finishTurnOrderly(); aiThinkTimer = 26; return; } // Nächsten erreichbaren Schritt in Richtung Schatz wählen int bestDx = 0; int bestDy = 0; float bestDist = 9999.0; int[] dxs = { 0, 1, 0, -1 }; int[] dys = { -1, 0, 1, 0 }; for (int d = 0; d < 4; d++) { int nx = ai.gx + dxs[d]; int ny = ai.gy + dys[d]; if (!canPassBetween(ai.gx, ai.gy, nx, ny)) continue; float distToLoot = findNearestLootDistance(nx, ny); if (board[nx][ny].lootType > 0) distToLoot = -10.0; if (distToLoot < bestDist) { bestDist = distToLoot; bestDx = dxs[d]; bestDy = dys[d]; } } if (bestDx == 0 && bestDy == 0) { finishTurnOrderly(); aiThinkTimer = 26; } else { tryStepPirate(bestDx, bestDy); aiThinkTimer = 20; } } } int previewPushedOffPirate(int side, int idx) { for (int p = 0; p < 4; p++) { if (pirates[p].captiveOf != -1) continue; if (side == 0 && pirates[p].gx == idx && pirates[p].gy == gridN - 1) return p; if (side == 2 && pirates[p].gx == idx && pirates[p].gy == 0) return p; if (side == 3 && pirates[p].gy == idx && pirates[p].gx == gridN - 1) return p; if (side == 1 && pirates[p].gy == idx && pirates[p].gx == 0) return p; } return -1; } float findNearestLootDistance(int sx, int sy) { float best = 999.0; for (int y = 0; y < gridN; y++) { for (int x = 0; x < gridN; x++) { if (board[x][y].lootType > 0) { float d = abs(x - sx) + abs(y - sy); if (d < best) best = d; } } } return best; } // ============================================================================================== // MODUL 6: UI-RENDERER (TOP-LEISTE, OFFENES-SPIEL-BANNER & PIRATEN-KARTEN) // ============================================================================================== void drawTopBar() { fill(getUiColor(a11yTheme, 1)); noStroke(); rect(0, 0, width, 46); stroke(getUiColor(a11yTheme, 4)); line(0, 46, width, 46); fill(255); textSize(14); textAlign(LEFT, CENTER); text("DVL17 — PIRATEN-LABYRINTH (RUNDE " + roundNumber + ")", 16, 15); fill(210, 225, 245); textSize(11); text("4 Pkt = +1 SP | !=4 Pkt = +3 SP | Schieben vom Feld = Geisel (-1 E)", 16, 33); drawUiButton(535, 7, 108, 32, "Neu Würfeln", getUiColor(a11yTheme, 3)); drawUiButton(651, 7, 96, 32, "Feld: " + gridN + "x" + gridN, getUiColor(a11yTheme, 3)); int edBg = editorMode ? getUiColor(a11yTheme, 2) : color(24, 30, 44); drawUiButton(755, 7, 148, 32, editorMode ? "Editor: AN (-1 E)" : "Editor: AUS", edBg); String a11yLbl = "Sehhilfe [H]"; if (a11yTheme == 1) a11yLbl = "Farbenblind"; if (a11yTheme == 2) a11yLbl = "Max-Kontrast"; drawUiButton(911, 7, 134, 32, a11yLbl, getUiColor(a11yTheme, 3)); } // Kleine Message & 1-Klick-Buttons, um eine KI durch einen echten Mitspieler zu ersetzen! void drawOpenRoomBanner() { fill(a11yTheme == 2 ? color(0) : color(11, 16, 28)); stroke(59, 110, 194); rect(14, 52, width - 28, 26, 5); fill(230, 238, 250); textSize(11); textAlign(LEFT, CENTER); if (!lobbyConnected) { text("Modus: Einzelspieler gegen KI (Klicke auf [KI-BOT] bei einem Piraten zum Umschalten)", 24, 65); return; } if (mySeatIndex == -1) { // Zweiter Besucher ist dazugekommen -> kleine Message, dass man eine KI ersetzen kann! fill(255, 225, 95); text("OFFENES SPIEL AKTIV (" + lobbyHumans + " Spieler): Du kannst eine KI ersetzen ->", 24, 65); int bx = 435; for (int i = 0; i < 4; i++) { if (isAiSeat[i]) { drawUiButton(bx, 55, 132, 20, "Pirat " + (i + 1) + " übernehmen", getUiColor(a11yTheme, 2)); bx += 138; } } } else { text("Offener Raum aktiv (" + lobbyHumans + " Mensch(en) online) · Du spielst Pirat " + (mySeatIndex + 1) + " · " + lobbyBannerMsg, 24, 65); drawUiButton(width - 175, 55, 150, 20, "An KI abgeben (-1)", color(35, 44, 66)); } } void drawPirateCard(int pIdx, float px, float py) { float pw = 212.0; float ph = 326.0; PirateAgent p = pirates[pIdx]; boolean isTurn = (activePirate == pIdx && turnPhase != 2); int pCol = getPirateColor(a11yTheme, pIdx); fill(getUiColor(a11yTheme, 1)); if (isTurn) { stroke(pCol); strokeWeight(2.5); } else { stroke(48, 58, 82); strokeWeight(1.0); } rect(px, py, pw, ph, 8); strokeWeight(1.0); // Kopfbalken mit Piratenname & Siegpunkten fill(pCol); noStroke(); rect(px + 10, py + 8, pw - 20, 26, 5); fill(a11yTheme == 2 ? color(0) : color(8, 10, 16)); textSize(13); textAlign(LEFT, CENTER); text(p.name, px + 16, py + 21); textAlign(RIGHT, CENTER); text(p.victoryPoints + " SP", px + pw - 16, py + 21); // KI / MENSCH Umschalter-Badge (ermöglicht schnelles Wechseln im Solo & Open-Room) String roleLabel = isAiSeat[pIdx] ? "KI-BOT (Klick = Mensch)" : ((mySeatIndex == pIdx) ? "DU (MENSCH)" : "MITSPIELER"); int roleBg = isAiSeat[pIdx] ? color(24, 46, 86) : getUiColor(a11yTheme, 2); drawUiButton(px + 10, py + 38, pw - 20, 20, roleLabel, roleBg); // Status-Badge (Aktiv / Wartet / ALS GEISEL GEFANGEN) if (p.captiveOf != -1) { fill(145, 22, 42); stroke(255, 120, 140); } else if (isTurn) { fill(getUiColor(a11yTheme, 2)); stroke(getUiColor(a11yTheme, 4)); } else { fill(20, 25, 38); stroke(55, 68, 95); } rect(px + 10, py + 62, pw - 20, 22, 4); fill(255); textSize(10); textAlign(CENTER, CENTER); String badgeTxt = "Wartet"; if (p.captiveOf != -1) { badgeTxt = "GEISEL BEI PIRAT " + (p.captiveOf + 1); } else if (isTurn) { if (isAiSeat[pIdx]) badgeTxt = "KI denkt & zieht..."; else badgeTxt = (turnPhase == 0) ? "1. Karte schieben / Geisel" : "2. Laufen (" + (p.maxStepsTurn - p.stepsTaken) + " Schr.)"; } text(badgeTxt, px + pw * 0.5, py + 73); // Punkte & Lebensenergie-Balken (0..7) fill(240, 245, 255); textSize(11); textAlign(LEFT, TOP); String ptHint = (p.roundPoints == 4) ? " [ZIEL 4!]" : ""; text("Punkte: " + p.roundPoints + " / 4" + ptHint, px + 12, py + 90); text("Lebensenergie: " + p.energy + " / " + MAX_ENERGY, px + 12, py + 108); fill(28, 35, 52); noStroke(); rect(px + 12, py + 124, pw - 24, 9, 3); int eCol = color(35, 210, 115); if (p.energy <= 2) eCol = color(235, 55, 80); else if (p.energy <= 4) eCol = color(251, 191, 36); fill(eCol); rect(px + 12, py + 124, map(p.energy, 0, MAX_ENERGY, 0, pw - 24), 9, 3); // Reserve-Kartenplatz float miniSize = 80.0; float miniX = px + (pw - miniSize) * 0.5; float miniY = py + 150.0; int hostageIdx = getHostageOfPirate(pIdx); if (isTurn) { fill(210, 225, 245); textSize(10); textAlign(CENTER, BOTTOM); text("Kartenplatz (Klick = Drehen):", px + pw * 0.5, miniY - 3); drawTileGraphic(spareTile, miniX, miniY, miniSize, false, pIdx, hostageIdx); if (canLocalControlPirate(pIdx)) { drawUiButton(px + 12, miniY + miniSize + 6, pw - 24, 24, "Karte drehen [R]", getUiColor(a11yTheme, 3)); if (hostageIdx != -1 && turnPhase == 0) { drawUiButton(px + 12, miniY + miniSize + 34, pw - 24, 26, "Geisel halten [G] (+1 E)", getUiColor(a11yTheme, 2)); } else if (turnPhase == 1) { drawUiButton(px + 12, miniY + miniSize + 34, pw - 24, 26, "Ordentlich beenden [Y]", getUiColor(a11yTheme, 2)); } else { drawUiButton(px + 12, miniY + miniSize + 34, pw - 24, 26, "Ohne Schub laufen [S]", color(30, 38, 56)); } drawUiButton(px + 12, miniY + miniSize + 64, pw - 24, 22, "Runde werten [V]", color(42, 50, 72)); } } else { fill(18, 22, 34); stroke(45, 55, 78); rect(miniX, miniY, miniSize, miniSize, 5); if (hostageIdx != -1) { drawPirateTokenOnCard(hostageIdx, miniX + miniSize * 0.5, miniY + miniSize * 0.5, 26.0); } else { fill(145, 160, 185); textSize(10); textAlign(CENTER, CENTER); text("Kartenplatz\nfrei", px + pw * 0.5, miniY + miniSize * 0.5); } } } int getHostageOfPirate(int captorIdx) { for (int i = 0; i < 4; i++) { if (pirates[i].captiveOf == captorIdx) return i; } return -1; } void drawInsertionArrows() { float tileSz = BOARD_SIZE / float(gridN); boolean canArrow = (turnPhase == 0 && canLocalControlPirate(activePirate)); int arrowCol = canArrow ? getUiColor(a11yTheme, 4) : color(55, 68, 95); for (int idx = 1; idx < gridN; idx += 2) { float mid = idx * tileSz + tileSz * 0.5; if (!(blockedArrowSide == 0 && blockedArrowIndex == idx)) drawArrowBadge(BOARD_X + mid, BOARD_Y - 15, 0, arrowCol, canArrow); if (!(blockedArrowSide == 2 && blockedArrowIndex == idx)) drawArrowBadge(BOARD_X + mid, BOARD_Y + BOARD_SIZE + 15, 2, arrowCol, canArrow); if (!(blockedArrowSide == 3 && blockedArrowIndex == idx)) drawArrowBadge(BOARD_X - 15, BOARD_Y + mid, 3, arrowCol, canArrow); if (!(blockedArrowSide == 1 && blockedArrowIndex == idx)) drawArrowBadge(BOARD_X + BOARD_SIZE + 15, BOARD_Y + mid, 1, arrowCol, canArrow); } } void drawArrowBadge(float cx, float cy, int dir, int col, boolean active) { fill(getUiColor(a11yTheme, 1)); stroke(col); strokeWeight(active ? 1.8 : 1.0); ellipse(cx, cy, 22, 22); fill(active ? color(255) : color(130)); noStroke(); if (dir == 0) triangle(cx - 5, cy - 3, cx + 5, cy - 3, cx, cy + 5); if (dir == 2) triangle(cx - 5, cy + 3, cx + 5, cy + 3, cx, cy - 5); if (dir == 3) triangle(cx - 3, cy - 5, cx - 3, cy + 5, cx + 5, cy); if (dir == 1) triangle(cx + 3, cy - 5, cx + 3, cy + 5, cx - 5, cy); strokeWeight(1.0); } void drawLabyrinthBoard() { fill(getUiColor(a11yTheme, 5)); stroke(getUiColor(a11yTheme, 4)); strokeWeight(2.0); rect(BOARD_X - 2, BOARD_Y - 2, BOARD_SIZE + 4, BOARD_SIZE + 4, 4); strokeWeight(1.0); float tileSz = BOARD_SIZE / float(gridN); for (int y = 0; y < gridN; y++) { for (int x = 0; x < gridN; x++) { float dx = BOARD_X + x * tileSz; float dy = BOARD_Y + y * tileSz; if (animAxis == 0 && y == animLineIndex) dx += animOffsetPx; if (animAxis == 1 && x == animLineIndex) dy += animOffsetPx; boolean isReach = (turnPhase == 1 && reachable[x][y]); drawTileGraphic(board[x][y], dx, dy, tileSz, isReach, activePirate, -1); } } for (int p = 0; p < 4; p++) { if (pirates[p].captiveOf != -1) continue; float px = BOARD_X + pirates[p].vx * tileSz + tileSz * 0.5; float py = BOARD_Y + pirates[p].vy * tileSz + tileSz * 0.5; int pCol = getPirateColor(a11yTheme, p); if (p == activePirate) { noFill(); stroke(255); strokeWeight(2.0); ellipse(px, py, tileSz * 0.52, tileSz * 0.52); } fill(pCol); stroke(0); strokeWeight(1.5); ellipse(px, py, tileSz * 0.36, tileSz * 0.36); fill(a11yTheme == 2 ? color(0) : color(255)); textSize(11); textAlign(CENTER, CENTER); text(str(p + 1), px, py - 1); } strokeWeight(1.0); } void drawTileGraphic(MazeTile t, float tx, float ty, float sz, boolean highlightReach, int currentP, int captiveOnTile) { float third = sz / 3.0; int wallCol = getUiColor(a11yTheme, 5); int pathCol = getUiColor(a11yTheme, 6); fill(wallCol); stroke(38, 48, 72); rect(tx, ty, sz, sz); noStroke(); fill(pathCol); rect(tx + third, ty + third, third, third); if (t.n) rect(tx + third, ty, third, third); if (t.s) rect(tx + third, ty + third * 2.0, third, third); if (t.w) rect(tx, ty + third, third, third); if (t.e) rect(tx + third * 2.0, ty + third, third, third); if (highlightReach) { int pCol = getPirateColor(a11yTheme, currentP); fill(red(pCol), green(pCol), blue(pCol), 72); rect(tx + 2, ty + 2, sz - 4, sz - 4); } if (t.lootType > 0) { float cx = tx + sz * 0.5; float cy = ty + sz * 0.5; if (t.lootType == 2) fill(255, 205, 45); else fill(140, 175, 235); stroke(0); strokeWeight(1.4); ellipse(cx, cy, third * 0.72, third * 0.72); fill(0); textSize(10); textAlign(CENTER, CENTER); text(t.lootType == 2 ? "+2" : "+1", cx, cy - 1); strokeWeight(1.0); } if (captiveOnTile >= 0) { drawPirateTokenOnCard(captiveOnTile, tx + sz * 0.5, ty + sz * 0.5, sz * 0.34); } } void drawPirateTokenOnCard(int pIdx, float cx, float cy, float diam) { int pCol = getPirateColor(a11yTheme, pIdx); fill(pCol); stroke(255); strokeWeight(2.0); ellipse(cx, cy, diam, diam); fill(0); textSize(11); textAlign(CENTER, CENTER); text("G" + (pIdx + 1), cx, cy - 1); strokeWeight(1.0); } void drawBottomStatusBar() { fill(getUiColor(a11yTheme, 1)); stroke(59, 110, 194); rect(236, 686, 588, 68, 8); fill(255); textSize(12); textAlign(LEFT, TOP); text(statusLine, 250, 696); fill(195, 210, 235); textSize(11); text("[R] Drehen | [G] Geisel halten | [W/A/S/D] Laufen | [Y] Ordentlich beenden | [H] Sehhilfe", 250, 724); } void drawRoundVictoryModal() { fill(4, 5, 12, 228); noStroke(); rect(0, 46, width, height - 46); fill(getUiColor(a11yTheme, 1)); stroke(getPirateColor(a11yTheme, roundWinner)); strokeWeight(2.5); rect(250, 200, 560, 290, 10); strokeWeight(1.0); fill(getPirateColor(a11yTheme, roundWinner)); noStroke(); rect(251, 201, 558, 42, 9); fill(a11yTheme == 2 ? color(0) : color(8, 10, 16)); textSize(16); textAlign(CENTER, CENTER); text("RUNDENSIEG: " + pirates[roundWinner].name.toUpperCase() + " (+" + awardedVP + " SIEGPUNKTE!)", width * 0.5, 222); fill(242, 246, 255); textSize(13); textAlign(CENTER, TOP); text(roundEndReason + "\n\nAktueller Serienstand (Ziel: " + SERIES_GOAL_VP + " Siegpunkte):\n" + "Pirat 1: " + pirates[0].victoryPoints + " SP | Pirat 2: " + pirates[1].victoryPoints + " SP | " + "Pirat 3: " + pirates[2].victoryPoints + " SP | Pirat 4: " + pirates[3].victoryPoints + " SP", 275, 262, 510, 145); boolean seriesFinished = (pirates[roundWinner].victoryPoints >= SERIES_GOAL_VP); String btnTxt = seriesFinished ? "NEUE SERIE STARTEN" : "NÄCHSTE RUNDE STARTEN >>"; drawUiButton(390, 425, 280, 42, btnTxt, getUiColor(a11yTheme, 2)); } void drawUiButton(float bx, float by, float bw, float bh, String label, int bgCol) { if (a11yTheme == 2) { fill(0); stroke(255, 255, 0); } else { fill(bgCol); stroke(125, 160, 220); } rect(bx, by, bw, bh, 5); fill(a11yTheme == 2 ? color(255, 255, 0) : color(255)); textSize(11); textAlign(CENTER, CENTER); text(label, bx + bw * 0.5, by + bh * 0.5); } // ============================================================================================== // MODUL 7: SCHIEBE-MECHANIK, GEISELNAHME, ERSCHÖPFUNG & SIEGPUNKTE-LOGIK // ============================================================================================== void insertSpareTileAt(int side, int idx) { if (turnPhase != 0) return; if (side == blockedArrowSide && idx == blockedArrowIndex) { statusLine = "Direktes Zurückschieben ist gesperrt — wähle einen anderen Pfeil!"; return; } PirateAgent mover = pirates[activePirate]; float tileSz = BOARD_SIZE / float(gridN); int releasedHostage = getHostageOfPirate(activePirate); int entryX = idx; int entryY = 0; if (side == 0) { entryX = idx; entryY = 0; } if (side == 2) { entryX = idx; entryY = gridN - 1; } if (side == 3) { entryX = 0; entryY = idx; } if (side == 1) { entryX = gridN - 1; entryY = idx; } MazeTile pushedOut; int pushedOffVictim = -1; if (side == 0) { pushedOut = board[idx][gridN - 1]; for (int y = gridN - 1; y > 0; y--) board[idx][y] = board[idx][y - 1]; board[idx][0] = spareTile; spareTile = pushedOut; for (int p = 0; p < 4; p++) { if (pirates[p].captiveOf == -1 && pirates[p].gx == idx) { if (pirates[p].gy == gridN - 1) pushedOffVictim = p; else pirates[p].gy++; } } animAxis = 1; animLineIndex = idx; animOffsetPx = -tileSz; blockedArrowSide = 2; blockedArrowIndex = idx; } else if (side == 2) { pushedOut = board[idx][0]; for (int y = 0; y < gridN - 1; y++) board[idx][y] = board[idx][y + 1]; board[idx][gridN - 1] = spareTile; spareTile = pushedOut; for (int p = 0; p < 4; p++) { if (pirates[p].captiveOf == -1 && pirates[p].gx == idx) { if (pirates[p].gy == 0) pushedOffVictim = p; else pirates[p].gy--; } } animAxis = 1; animLineIndex = idx; animOffsetPx = tileSz; blockedArrowSide = 0; blockedArrowIndex = idx; } else if (side == 3) { pushedOut = board[gridN - 1][idx]; for (int x = gridN - 1; x > 0; x--) board[x][idx] = board[x - 1][idx]; board[0][idx] = spareTile; spareTile = pushedOut; for (int p = 0; p < 4; p++) { if (pirates[p].captiveOf == -1 && pirates[p].gy == idx) { if (pirates[p].gx == gridN - 1) pushedOffVictim = p; else pirates[p].gx++; } } animAxis = 0; animLineIndex = idx; animOffsetPx = -tileSz; blockedArrowSide = 1; blockedArrowIndex = idx; } else { pushedOut = board[0][idx]; for (int x = 0; x < gridN - 1; x++) board[x][idx] = board[x + 1][idx]; board[gridN - 1][idx] = spareTile; spareTile = pushedOut; for (int p = 0; p < 4; p++) { if (pirates[p].captiveOf == -1 && pirates[p].gy == idx) { if (pirates[p].gx == 0) pushedOffVictim = p; else pirates[p].gx--; } } animAxis = 0; animLineIndex = idx; animOffsetPx = tileSz; blockedArrowSide = 3; blockedArrowIndex = idx; } if (releasedHostage != -1) { pirates[releasedHostage].captiveOf = -1; pirates[releasedHostage].gx = entryX; pirates[releasedHostage].gy = entryY; pirates[releasedHostage].vx = float(entryX); pirates[releasedHostage].vy = float(entryY); } if (pushedOffVictim != -1) { if (pushedOffVictim == activePirate) { mover.gx = entryX; mover.gy = entryY; mover.vx = float(entryX); mover.vy = float(entryY); } else { pirates[pushedOffVictim].captiveOf = activePirate; mover.energy = max(0, mover.energy - 1); statusLine = mover.name + " schiebt " + pirates[pushedOffVictim].name + " vom Feld auf seinen Kartenplatz (-1 Energie)!"; if (checkAllRivalsCaptured(activePirate)) { finishRoundWithWinner(activePirate, "Alle Mitspieler wurden als Geiseln festgesetzt!"); pushOnlineStateIfNeeded(); return; } } } prepareMovementPhase(); pushOnlineStateIfNeeded(); } void holdHostageAndSkipTurn() { int hostage = getHostageOfPirate(activePirate); if (turnPhase != 0 || hostage == -1) return; PirateAgent mover = pirates[activePirate]; mover.energy = min(MAX_ENERGY, mover.energy + 1); statusLine = mover.name + " überspringt den Zug, hält " + pirates[hostage].name + " als Geisel und gewinnt +1 Energie!"; advanceToNextPirate(); pushOnlineStateIfNeeded(); } void prepareMovementPhase() { turnPhase = 1; PirateAgent p = pirates[activePirate]; p.stepsTaken = 0; if (p.energy >= 6) p.maxStepsTurn = 4; else if (p.energy >= 4) p.maxStepsTurn = 3; else if (p.energy >= 2) p.maxStepsTurn = 2; else if (p.energy == 1) p.maxStepsTurn = 1; else p.maxStepsTurn = 0; computeReachableTiles(); checkLootPickup(activePirate); if (turnPhase != 2 && !statusLine.contains("Kartenplatz (-1 Energie)")) { if (p.maxStepsTurn == 0) { statusLine = p.name + " hat 0 Lebensenergie und kann nicht laufen — [Y] für Erholung!"; } else { statusLine = p.name + ": Bis zu " + p.maxStepsTurn + " Schritte (Energie " + p.energy + "/7) | [Y] Ordentlich beenden"; } } } boolean canPassBetween(int cx, int cy, int nx, int ny) { if (nx < 0 || nx >= gridN || ny < 0 || ny >= gridN) return false; MazeTile cur = board[cx][cy]; MazeTile next = board[nx][ny]; int dx = nx - cx; int dy = ny - cy; if (dy == -1 && cur.n && next.s) return true; if (dy == 1 && cur.s && next.n) return true; if (dx == -1 && cur.w && next.e) return true; if (dx == 1 && cur.e && next.w) return true; return false; } void tryStepPirate(int dx, int dy) { if (turnPhase != 1) return; PirateAgent p = pirates[activePirate]; if (p.stepsTaken >= p.maxStepsTurn) { statusLine = p.name + " hat sein Schrittlimit erreicht — beende den Zug ordentlich mit [Y]!"; return; } int nx = p.gx + dx; int ny = p.gy + dy; if (!canPassBetween(p.gx, p.gy, nx, ny)) return; int staminaRoll = int(random(0, p.energy + 1)); if (p.energy <= 2 && staminaRoll == 0) { p.stepsTaken++; statusLine = p.name + " stolpert vor Erschöpfung (Energie " + p.energy + "/7)! [Y] für Erholung."; pushOnlineStateIfNeeded(); return; } p.gx = nx; p.gy = ny; p.stepsTaken++; if (p.stepsTaken % 2 == 0 && p.energy > 0) { p.energy--; } checkLootPickup(activePirate); if (turnPhase != 2) { int rem = max(0, p.maxStepsTurn - p.stepsTaken); statusLine = p.name + " zieht nach (" + nx + "," + ny + ") · Restschritte: " + rem + " · Energie: " + p.energy + "/7"; } pushOnlineStateIfNeeded(); } void finishTurnOrderly() { if (turnPhase == 2) return; PirateAgent p = pirates[activePirate]; int roll = int(random(0, MAX_ENERGY)); if (p.energy > 0 && roll < p.energy) { int gain = (p.energy >= 5) ? 2 : 1; p.energy = min(MAX_ENERGY, p.energy + gain); statusLine = p.name + " beendet ordentlich und erholt sich (+" + gain + " Lebensenergie -> " + p.energy + "/7)!"; } else if (p.energy == 0) { p.energy = 1; statusLine = p.name + " schöpft nach totaler Erschöpfung wieder +1 Lebensenergie."; } else { statusLine = p.name + " beendet den Zug ordentlich."; } advanceToNextPirate(); pushOnlineStateIfNeeded(); } void advanceToNextPirate() { if (turnPhase == 2) return; for (int step = 1; step <= 4; step++) { int candidate = (activePirate + step) % 4; if (pirates[candidate].captiveOf == -1) { activePirate = candidate; turnPhase = 0; aiThinkTimer = 26; aiSubStep = 0; computeReachableTiles(); return; } } } void checkLootPickup(int pIdx) { PirateAgent p = pirates[pIdx]; MazeTile tile = board[p.gx][p.gy]; if (tile.lootType > 0) { int ptsGain = tile.lootType; tile.lootType = 0; p.roundPoints += ptsGain; spawnLootTile(ptsGain); if (p.roundPoints == 4) { finishRoundWithWinner(pIdx, p.name + " hat genau 4 Punkte eingesammelt!"); } else if (p.roundPoints > 4) { finishRoundWithWinner(pIdx, p.name + " beendet mit " + p.roundPoints + " Punkten (ungleich 4)!"); } else { statusLine = p.name + " sammelt +" + ptsGain + " Punkt(e) -> Stand: " + p.roundPoints + " Punkte!"; } } } boolean checkAllRivalsCaptured(int captorIdx) { int freeRivals = 0; for (int i = 0; i < 4; i++) { if (i != captorIdx && pirates[i].captiveOf == -1) freeRivals++; } return (freeRivals == 0); } void evaluateRoundEndNow() { int bestIdx = 0; for (int i = 1; i < 4; i++) { if (pirates[i].roundPoints > pirates[bestIdx].roundPoints) bestIdx = i; } finishRoundWithWinner(bestIdx, "Vorzeitige Rundenwertung: " + pirates[bestIdx].name + " führt mit " + pirates[bestIdx].roundPoints + " Punkten!"); pushOnlineStateIfNeeded(); } void finishRoundWithWinner(int wIdx, String reason) { roundWinner = wIdx; turnPhase = 2; if (pirates[wIdx].roundPoints == 4) { awardedVP = 1; roundEndReason = reason + "\nGenau 4 Punkte erreicht -> +1 Siegpunkt!"; } else { awardedVP = 3; roundEndReason = reason + "\nRundenende mit " + pirates[wIdx].roundPoints + " Punkten (ungleich 4) -> +3 Siegpunkte!"; } pirates[wIdx].victoryPoints += awardedVP; } void computeReachableTiles() { for (int y = 0; y < MAX_GRID; y++) { for (int x = 0; x < MAX_GRID; x++) { reachable[x][y] = false; } } PirateAgent p = pirates[activePirate]; if (p.captiveOf != -1) return; reachable[p.gx][p.gy] = true; int[] qx = new int[81]; int[] qy = new int[81]; int[] qd = new int[81]; int head = 0; int tail = 0; qx[tail] = p.gx; qy[tail] = p.gy; qd[tail] = 0; tail++; int remSteps = max(0, p.maxStepsTurn - p.stepsTaken); while (head < tail) { int cx = qx[head]; int cy = qy[head]; int cd = qd[head]; head++; if (cd >= remSteps) continue; if (canPassBetween(cx, cy, cx, cy - 1) && !reachable[cx][cy - 1]) { reachable[cx][cy - 1] = true; qx[tail] = cx; qy[tail] = cy - 1; qd[tail] = cd + 1; tail++; } if (canPassBetween(cx, cy, cx, cy + 1) && !reachable[cx][cy + 1]) { reachable[cx][cy + 1] = true; qx[tail] = cx; qy[tail] = cy + 1; qd[tail] = cd + 1; tail++; } if (canPassBetween(cx, cy, cx - 1, cy) && !reachable[cx - 1][cy]) { reachable[cx - 1][cy] = true; qx[tail] = cx - 1; qy[tail] = cy; qd[tail] = cd + 1; tail++; } if (canPassBetween(cx, cy, cx + 1, cy) && !reachable[cx + 1][cy]) { reachable[cx + 1][cy] = true; qx[tail] = cx + 1; qy[tail] = cy; qd[tail] = cd + 1; tail++; } } } void handleEditorWallClick(int gx, int gy, float localX, float localY, float tileSz) { PirateAgent p = pirates[activePirate]; if (p.energy <= 0) { statusLine = p.name + " hat 0 Lebensenergie für den Editor!"; return; } MazeTile t = board[gx][gy]; float dTop = localY; float dBottom = tileSz - localY; float dLeft = localX; float dRight = tileSz - localX; float minD = min(min(dTop, dBottom), min(dLeft, dRight)); if (minD == dTop) t.n = !t.n; else if (minD == dBottom) t.s = !t.s; else if (minD == dLeft) t.w = !t.w; else t.e = !t.e; p.energy--; computeReachableTiles(); statusLine = "Editor: Durchgang auf (" + gx + "," + gy + ") geändert (-1 Lebensenergie -> " + p.energy + "/7)"; pushOnlineStateIfNeeded(); } // ============================================================================================== // MODUL 8: OFFENE LOBBY-SYNCHRONISATION (dvl17_lobby.php -> +1 / -1 & KI-ÜBERNAHME) // ============================================================================================== void pushOnlineStateIfNeeded() { if (!lobbyConnected || !lobbyEnabled) return; if (mySeatIndex < 0) return; syncWithLobby("push", mySeatIndex, true); } void syncWithLobby(String action, int reqSeat, boolean sendState) { try { String url = "dvl17_lobby.php?action=" + action + "&cid=" + myClientId + "&seat=" + reqSeat; if (sendState) { url = url + "&st=" + encodeBoardState() + "&ev=" + cleanUrlText(statusLine); } String[] lines = loadStrings(url); if (lines == null || lines.length == 0) return; boolean okFound = false; int remoteRev = roomRevision; String remoteState = ""; for (int i = 0; i < lines.length; i++) { String line = trim(lines[i]); int eq = line.indexOf('='); if (eq <= 0) continue; String k = line.substring(0, eq); String v = line.substring(eq + 1); if (k.equals("STATUS") && v.equals("OK")) okFound = true; else if (k.equals("HUMANS")) lobbyHumans = int(v); else if (k.equals("MY_SEAT")) mySeatIndex = int(v); else if (k.equals("REVISION")) remoteRev = int(v); else if (k.equals("SEAT_0")) isAiSeat[0] = v.equals("AI"); else if (k.equals("SEAT_1")) isAiSeat[1] = v.equals("AI"); else if (k.equals("SEAT_2")) isAiSeat[2] = v.equals("AI"); else if (k.equals("SEAT_3")) isAiSeat[3] = v.equals("AI"); else if (k.equals("EVENT")) lobbyBannerMsg = v; else if (k.equals("STATE")) remoteState = v; } if (okFound) { lobbyConnected = true; if (remoteRev > roomRevision && remoteState.length() > 10) { roomRevision = remoteRev; decodeBoardState(remoteState); } else if (sendState && remoteRev > roomRevision) { roomRevision = remoteRev; } } } catch (Exception e) { // Offline-Fallback (z. B. lokal in Processing 4.5.6 ohne PHP-Server) } } String cleanUrlText(String s) { String out = ""; for (int i = 0; i < min(s.length(), 90); i++) { char ch = s.charAt(i); if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9') || ch == '-' || ch == '.') { out = out + ch; } else if (ch == ' ') { out = out + "_"; } } return out; } String encodeTile(MazeTile t) { int mask = 0; if (t.n) mask += 1; if (t.e) mask += 2; if (t.s) mask += 4; if (t.w) mask += 8; String hexChars = "0123456789abcdef"; return str(hexChars.charAt(mask)) + str(t.lootType); } MazeTile decodeTile(String pair) { String hexChars = "0123456789abcdef"; int mask = hexChars.indexOf(pair.charAt(0)); if (mask < 0) mask = 5; int loot = int(str(pair.charAt(1))); MazeTile t = new MazeTile((mask & 1) != 0, (mask & 2) != 0, (mask & 4) != 0, (mask & 8) != 0); t.lootType = loot; return t; } String encodeBoardState() { String hdr = gridN + "," + roundNumber + "," + activePirate + "," + turnPhase + "," + blockedArrowSide + "," + blockedArrowIndex + "," + roundWinner + "," + awardedVP; String sp = encodeTile(spareTile); String cells = ""; for (int y = 0; y < gridN; y++) { for (int x = 0; x < gridN; x++) { cells = cells + encodeTile(board[x][y]); } } String pStr = ""; for (int i = 0; i < 4; i++) { PirateAgent p = pirates[i]; if (i > 0) pStr = pStr + ";"; pStr = pStr + p.gx + "," + p.gy + "," + p.energy + "," + p.roundPoints + "," + p.victoryPoints + "," + p.captiveOf; } return hdr + "|" + sp + "|" + cells + "|" + pStr; } void decodeBoardState(String raw) { String[] parts = split(raw, '|'); if (parts == null || parts.length < 4) return; String[] hdr = split(parts[0], ','); if (hdr == null || hdr.length < 8) return; int nVal = constrain(int(hdr[0]), 5, 9); gridN = nVal; roundNumber = int(hdr[1]); activePirate = constrain(int(hdr[2]), 0, 3); turnPhase = constrain(int(hdr[3]), 0, 2); blockedArrowSide = int(hdr[4]); blockedArrowIndex = int(hdr[5]); roundWinner = int(hdr[6]); awardedVP = int(hdr[7]); if (parts[1].length() >= 2) { spareTile = decodeTile(parts[1]); } String cellStream = parts[2]; if (cellStream.length() >= gridN * gridN * 2) { int pos = 0; for (int y = 0; y < gridN; y++) { for (int x = 0; x < gridN; x++) { board[x][y] = decodeTile(cellStream.substring(pos, pos + 2)); pos += 2; } } } String[] pList = split(parts[3], ';'); if (pList != null && pList.length >= 4) { for (int i = 0; i < 4; i++) { String[] pv = split(pList[i], ','); if (pv != null && pv.length >= 6) { pirates[i].gx = int(pv[0]); pirates[i].gy = int(pv[1]); pirates[i].energy = int(pv[2]); pirates[i].roundPoints = int(pv[3]); pirates[i].victoryPoints = int(pv[4]); pirates[i].captiveOf = int(pv[5]); } } } computeReachableTiles(); } // ============================================================================================== // MODUL 9: MAUS- & TASTATUR-STEUERUNG // ============================================================================================== void mousePressed() { if (turnPhase == 2) { if (mouseX >= 390 && mouseX <= 670 && mouseY >= 425 && mouseY <= 467) { boolean resetAll = (pirates[roundWinner].victoryPoints >= SERIES_GOAL_VP); if (!resetAll) roundNumber++; startNewRound(resetAll, true); } return; } // 1. Top-Leiste Buttons (y: 0..46) if (mouseY <= 46) { if (mouseX >= 535 && mouseX <= 643) { startNewRound(false, true); return; } if (mouseX >= 651 && mouseX <= 747) { gridN = (gridN == 5) ? 7 : ((gridN == 7) ? 9 : 5); startNewRound(false, true); return; } if (mouseX >= 755 && mouseX <= 903) { editorMode = !editorMode; statusLine = editorMode ? "Editor AKTIV: Klick auf eine Wandkante ändert den Durchgang (-1 Energie)." : "Editor deaktiviert."; return; } if (mouseX >= 911 && mouseX <= 1045) { a11yTheme = (a11yTheme + 1) % 3; return; } return; } // 2. Offenes-Spiel-Leiste (y: 52..78 -> KI ersetzen oder eigenen Platz abgeben) if (lobbyConnected && mouseY >= 52 && mouseY <= 78) { if (mySeatIndex == -1) { int bx = 435; for (int i = 0; i < 4; i++) { if (isAiSeat[i]) { if (mouseX >= bx && mouseX <= bx + 132) { syncWithLobby("claim", i, false); return; } bx += 138; } } } else if (mouseX >= width - 175 && mouseX <= width - 25) { syncWithLobby("release", mySeatIndex, false); return; } return; } // 3. Klicks in den 4 Piraten-Karten (KI/Mensch-Toggle + Aktionsbuttons) int[] cardOrder = { 0, 1, 2, 3 }; float[] cardXs = { 14.0, 834.0, 14.0, 834.0 }; float[] cardYs = { 84.0, 84.0, 426.0, 426.0 }; for (int c = 0; c < 4; c++) { int pIdx = cardOrder[c]; float cx = cardXs[c]; float cy = cardYs[c]; if (mouseX >= cx && mouseX <= cx + 212.0 && mouseY >= cy && mouseY <= cy + 326.0) { // Klick auf KI / MENSCH Umschalter (y: cy+38 .. cy+58) if (mouseY >= cy + 38.0 && mouseY <= cy + 58.0) { if (!lobbyConnected) { isAiSeat[pIdx] = !isAiSeat[pIdx]; aiThinkTimer = 20; } else if (mySeatIndex == -1 && isAiSeat[pIdx]) { syncWithLobby("claim", pIdx, false); } else if (mySeatIndex == pIdx) { syncWithLobby("release", pIdx, false); } return; } if (pIdx == activePirate && canLocalControlPirate(pIdx)) { float miniY = cy + 150.0; float miniSize = 80.0; if (mouseY >= miniY && mouseY <= miniY + miniSize + 32.0) { spareTile.rotateClockwise(); return; } if (mouseY >= miniY + miniSize + 34.0 && mouseY <= miniY + miniSize + 60.0) { int hostageIdx = getHostageOfPirate(activePirate); if (hostageIdx != -1 && turnPhase == 0) holdHostageAndSkipTurn(); else if (turnPhase == 1) finishTurnOrderly(); else prepareMovementPhase(); return; } if (mouseY >= miniY + miniSize + 64.0 && mouseY <= miniY + miniSize + 86.0) { evaluateRoundEndNow(); return; } } return; } } if (!canLocalControlPirate(activePirate)) return; float tileSz = BOARD_SIZE / float(gridN); // 4. Randpfeile zum Einschieben der Karte (Phase 0) if (turnPhase == 0) { for (int idx = 1; idx < gridN; idx += 2) { float mid = idx * tileSz + tileSz * 0.5; if (dist(mouseX, mouseY, BOARD_X + mid, BOARD_Y - 15) < 16.0) { insertSpareTileAt(0, idx); return; } if (dist(mouseX, mouseY, BOARD_X + mid, BOARD_Y + BOARD_SIZE + 15) < 16.0) { insertSpareTileAt(2, idx); return; } if (dist(mouseX, mouseY, BOARD_X - 15, BOARD_Y + mid) < 16.0) { insertSpareTileAt(3, idx); return; } if (dist(mouseX, mouseY, BOARD_X + BOARD_SIZE + 15, BOARD_Y + mid) < 16.0) { insertSpareTileAt(1, idx); return; } } } // 5. Klick direkt aufs Spielfeld if (mouseX >= BOARD_X && mouseX < BOARD_X + BOARD_SIZE && mouseY >= BOARD_Y && mouseY < BOARD_Y + BOARD_SIZE) { int gx = constrain(floor((mouseX - BOARD_X) / tileSz), 0, gridN - 1); int gy = constrain(floor((mouseY - BOARD_Y) / tileSz), 0, gridN - 1); if (editorMode) { float localX = (mouseX - BOARD_X) - gx * tileSz; float localY = (mouseY - BOARD_Y) - gy * tileSz; handleEditorWallClick(gx, gy, localX, localY, tileSz); return; } if (turnPhase == 1) { PirateAgent p = pirates[activePirate]; int dx = gx - p.gx; int dy = gy - p.gy; if (abs(dx) + abs(dy) == 1) { tryStepPirate(dx, dy); } } } } void keyPressed() { if (key == 'h' || key == 'H') { a11yTheme = (a11yTheme + 1) % 3; return; } if (turnPhase == 2 || !canLocalControlPirate(activePirate)) return; if (key == 'r' || key == 'R') { spareTile.rotateClockwise(); return; } if (key == 'g' || key == 'G') { holdHostageAndSkipTurn(); return; } if (key == 'v' || key == 'V') { evaluateRoundEndNow(); return; } if (key == 'y' || key == 'Y' || key == ENTER || key == RETURN) { if (turnPhase == 1) finishTurnOrderly(); return; } if (key == 's' || key == 'S') { if (turnPhase == 0) { prepareMovementPhase(); return; } } if (turnPhase == 1) { if (key == 'w' || key == 'W') tryStepPirate(0, -1); if (key == 's' || key == 'S') tryStepPirate(0, 1); if (key == 'a' || key == 'A') tryStepPirate(-1, 0); if (key == 'd' || key == 'D') tryStepPirate(1, 0); if (key == CODED) { if (keyCode == UP) tryStepPirate(0, -1); if (keyCode == DOWN) tryStepPirate(0, 1); if (keyCode == LEFT) tryStepPirate(-1, 0); if (keyCode == RIGHT) tryStepPirate(1, 0); } } }