"use client" import React, { ReactNode, useEffect, useRef } from "react"; import Maze from "./maze"; import ZMQReceiver from "./zmqreceiver"; import TypewriterText from "./typewritertext"; import { GameState } from "./zmqreceiver"; interface GameStats { points: [number, number]; errors: [number, number]; kills: [number, number, number, number]; deaths: [number, number, number, number]; time: [number, number]; } function Pelita() { const [showPre, setShowPre] = React.useState(true); const [showMain, setShowMain] = React.useState(true); const [getText, setText] = React.useState([]); const [gameUUID, setGameUUID] = React.useState(""); const [shape, setShape] = React.useState<[number, number]>([0, 0]); const [walls, setWalls] = React.useState<[number, number][]>([]); const [food, setFood] = React.useState<[number, number][]>([]); const [bots, setBots] = React.useState<[number, number][]>([[0, 0], [0, 0], [0, 0], [0, 0]]); const [team1, setTeam1] = React.useState(""); const [team2, setTeam2] = React.useState(""); const [stats, setStats] = React.useState(null); const [whoWins, setWhoWins] = React.useState(null); const [gameOver, setGameOver] = React.useState(false); const flip = () => { //setShowMain(!showMain); //setShowPre(!showPre); }; const updateGameState = (gameState: { '__data__': GameState }) => { if (gameState['__data__']) { // if (gameUUID != gameState['__data__']['game_uuid']) { setGameUUID((oldUUID) => { if (oldUUID != gameState['__data__']['game_uuid']) { console.log("UUID changed", gameState['__data__']['game_uuid'], oldUUID); setShape(gameState['__data__']['shape']) setWalls(gameState['__data__']['walls']); } return gameState['__data__']['game_uuid']; }) // } setFood(gameState['__data__']['food']); setBots(gameState['__data__']['bots']); setTeam1(gameState['__data__']['team_names'][0]); setTeam2(gameState['__data__']['team_names'][1]); setStats( { "deaths": gameState['__data__']['deaths'], "kills": gameState['__data__']['kills'], "errors": gameState['__data__']['num_errors'], "points": gameState['__data__']['score'], "time": gameState['__data__']['team_time'], } ); setWhoWins(gameState['__data__']['whowins']); setGameOver(gameState['__data__']['gameover']); } } const updateMessage = (msg: string) => { setText(oldText => [...oldText, msg]); } const clearPage = () => { setText([]); } const a = bots[0]; const b = bots[2]; const x = bots[1]; const y = bots[3]; return (

ᗧ Pelita Tournament 2024

{showPre ? getText.map((t, i) => ()) : null} {showMain ?
{gameUUID ? (<>

{team1} ({stats.points[0]}) {team2} ({stats.points[1]})

Errors: {stats.errors[0]}, Kills: {stats.kills[0] + stats.kills[2]}, Deaths: {stats.deaths[0] + stats.deaths[2]}, Time: {stats.time[0].toFixed(2)}
Errors: {stats.errors[1]}, Kills: {stats.kills[1] + stats.kills[3]}, Deaths: {stats.deaths[1] + stats.deaths[3]}, Time: {stats.time[1].toFixed(2)}
) : null}

{gameUUID}

: null }
); }; export default Pelita;