-
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.
2 folder added, 1 file mooved, 2 file added, 1 file renamed, 1 file e…
…dited
- Loading branch information
1 parent
0e2bc45
commit bfc0339
Showing
5 changed files
with
47 additions
and
4 deletions.
There are no files selected for viewing
File renamed without changes.
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,14 @@ | ||
// Funzione per gestire la creazione di una nuova stanza | ||
function createNewRoom() { | ||
// Fai una richiesta al server per creare una nuova stanza | ||
fetch('http://localhost:2567/createRoom') | ||
.then(response => response.json()) | ||
.then(data => { | ||
// Aggiorna l'interfaccia utente con RoomId e SessionId ottenuti dal server | ||
document.getElementById('roomId').textContent = data.roomId; | ||
document.getElementById('sessionId').textContent = data.sessionId; | ||
}) | ||
.catch(error => { | ||
console.error('Error creating room:', error); | ||
}); | ||
} |
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,30 @@ | ||
// Importa Colyseus | ||
const { Server } = require("colyseus"); | ||
|
||
// Crea una nuova istanza del server Colyseus | ||
const server = new Server(); | ||
|
||
// Definisci una classe per la tua stanza di gioco | ||
class MyRoom extends Room { | ||
// Implementa la logica per la creazione della stanza | ||
onCreate(options) { | ||
// Genera un RoomId univoco | ||
const roomId = generateUniqueId(); | ||
|
||
// Crea la stanza con il RoomId generato | ||
this.setState({ roomId }); | ||
|
||
// Assegna un SessionId al giocatore | ||
const sessionId = generateUniqueId(); | ||
this.assignSessionId(this.connectedClients[0], sessionId); | ||
|
||
// Invia RoomId e SessionId al giocatore | ||
this.sendToClient(this.connectedClients[0], { roomId, sessionId }); | ||
} | ||
} | ||
|
||
// Registra la tua stanza con il server Colyseus | ||
server.define("my_room", MyRoom); | ||
|
||
// Avvia il server sulla porta desiderata | ||
server.listen(2567); |
File renamed without changes.
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