-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/ItzyBitzySpider/pawnpawnpwn
- Loading branch information
Showing
11 changed files
with
338 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,11 @@ | ||
// Generate a random 6-letter room code | ||
export function generateRoomCode() { | ||
return Math.random().toString(36).substring(2, 8).toUpperCase(); | ||
const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | ||
let roomCode = ""; | ||
for (let i = 0; i < 6; i++) { | ||
roomCode += characters.charAt( | ||
Math.floor(Math.random() * characters.length) | ||
); | ||
} | ||
return roomCode; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { io } from "socket.io-client"; | ||
|
||
const socket = io("http://localhost:8000"); | ||
|
||
socket.on("connect", () => console.log("Connected to socket.io server")); | ||
|
||
export async function createRoom() { | ||
const response = await socket.emitWithAck("create"); | ||
console.log(response); | ||
return response as string; | ||
} | ||
|
||
export async function joinRoom(roomId: string) { | ||
const response = await socket.emitWithAck("join", roomId); | ||
console.log(roomId, response); | ||
return response as boolean; | ||
} | ||
|
||
export function move(move: string) { | ||
socket.emit("move", move); | ||
} | ||
|
||
export function onGameStart(callback: (fen: string, isWhite: boolean) => void) { | ||
socket.on("start", (fen, whiteSocketId) => | ||
callback(fen, socket.id === whiteSocketId) | ||
); | ||
} | ||
|
||
export function onUpdate(callback: (fen: string, lastMove: string) => void) { | ||
socket.on("update", callback); | ||
} |
Oops, something went wrong.