import { CSSProperties, Component } from 'react'; import { io as socket, Socket } from 'socket.io-client'; import axios from 'axios'; import * as cookies from 'react-cookies'; import { NavBar } from '../components/navbar'; import { CenteredPage } from '../components/page'; import { VoerBord } from '../components/voerBord'; import { DialogBox } from '../components/dialogBox'; import { CurrentGameSettings } from '../components/gameSettings'; import { Button, SearchBar, IconLabelButton } from '../components/ui'; import { GameBar } from '../components/gameBar'; import WifiTetheringRoundedIcon from '@material-ui/icons/WifiTetheringRounded'; import LinkRoundedIcon from '@material-ui/icons/LinkRounded'; import RefreshIcon from '@material-ui/icons/Refresh'; interface VoerGameProps { gameID: string; token: string; active: boolean; player1: boolean; } class VoerGame extends Component { constructor(props: VoerGameProps) { super(props); if (typeof document === "undefined") return; this.io = socket(); this.io.on("connect", () => console.log("connect")); this.io.on("disconnect", () => console.log("disconnect")); this.io.on("fieldUpdate", (data: { field: string }) => { this.setState({ board: data.field.split("").map(i => Number(i)) }); for(let i = 0; i < data.field.length; i++) document.getElementById(`pos-${i}`).parentNode.children.item(1).classList.add(`state-${data.field[i]}`); }); this.io.on("turnUpdate", (data: { player1: boolean }) => this.setState({ turn: data.player1 })); this.io.on("finish", (data: { winPositions: Array> boardFull: boolean }) => { this.setState({ winPositions: data.winPositions }); var outcome = -1; if (data.winPositions.length > 0) outcome = this.state.board[data.winPositions[0][0]]; if (data.boardFull) outcome = 0; this.setState({ outcome }); }); } io: Socket; width = 7; height = 6; state: { userID: string; turn: boolean; winPositions: Array>; outcome: number; board: Array; } = { userID: "", turn: true, winPositions: [], outcome: -1, board: [], }; board = [...Array(this.width * this.height)].map(() => 0); move(column: number) { this.io.emit("newMove", { move: column, token: this.props.token, game_id: this.props.gameID }); } render() { return
this.move(m % this.width + 1)} active={this.props.active == true && this.state.outcome == -1}/>
} } function GameOutcomeDialog(props: { outcome: number; player: number; visible: boolean; }) { return

{ props.outcome == 0 ? "Gelijkspel" : props.outcome == props.player ? "Verloren" : props.outcome != props.player ? "Gewonnen" : "???" }

{ false &&

0 Gemiste winstzetten
6 Optimale zetten
0 Blunders

} { false && } style={{ float: "none", marginTop: 24, padding: "12px 32px" }}/> }
} var InviteButtonStyle: CSSProperties = { backgroundColor: "var(--page-background)", height: 160, padding: 12 } var InviteButtonIconStyle: CSSProperties = { fontSize: 100, position: "absolute", top: 12, left: "50%", transform: "translateX(-50%)" } var InviteButtonLabelStyle: CSSProperties = { position: "absolute", bottom: 12, left: "50%", transform: "translateX(-50%)", textAlign: "center", color: "var(--text-alt)", width: 136, fontSize: 20, userSelect: "none" } export default class GamePage extends Component { constructor(props: {}) { super(props); } state: { gameID: string; token: string; player1: boolean; } = { gameID: "", token: "", player1: true } render() { return
} }