From 27c1340dbbf18638f680be8557a531180abfd53a Mon Sep 17 00:00:00 2001 From: lonkaars Date: Wed, 17 Feb 2021 22:35:41 +0100 Subject: supposed-to-work thingy --- pages/game.tsx | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'pages') diff --git a/pages/game.tsx b/pages/game.tsx index a206d7a..1c66f92 100644 --- a/pages/game.tsx +++ b/pages/game.tsx @@ -6,6 +6,13 @@ import * as cookies from 'react-cookies'; var socket = io("http://localhost:2080/api/game/socket/"); +socket.on("connect", () => { + console.log("connect") +}) +socket.on("disconnect", () => { + console.log("disconnect") +}) + import { NavBar } from '../components/navbar'; import { CenteredPage } from '../components/page'; import { VoerBord } from '../components/voerBord'; @@ -52,12 +59,21 @@ class VoerGame extends Component { super(props); } - board = [...Array(7 * 6)].map(() => 0); + width = 7; + height = 6; + + state: { + userID: string; + } = { + userID: "" + } + + board = [...Array(this.width * this.height)].map(() => 0); userID = ""; move(column: number) { console.log(column) - if(this.userID == "") { + if(this.state.userID == "") { axios.request({ method: "get", url: `/api/user/info`, @@ -66,6 +82,11 @@ class VoerGame extends Component { .then(request => this.setState({ userID: request.data.id })) .catch(() => {}); } + console.log("emitted this", { + move: column, + token: cookies.load("token"), + gameID: "fortnite" + }) socket.emit("new_move", { move: column, token: cookies.load("token"), @@ -81,7 +102,7 @@ class VoerGame extends Component { maxWidth: "100vh", margin: "0 auto" }}> - this.move(Number(m))}/> + this.move(m % this.width + 1)}/> } -- cgit v1.2.3