mirror of
https://github.com/giongto35/cloud-game.git
synced 2026-07-21 00:59:22 +00:00
ADd room logics
This commit is contained in:
parent
8bd521b7ed
commit
1835f9be9d
2 changed files with 10 additions and 4 deletions
|
|
@ -81,6 +81,11 @@
|
|||
<div style="position:absolute; top:30%; left: 5%;">
|
||||
<h3>Instruction</h3>
|
||||
<div>
|
||||
Menu:
|
||||
Left, Right to browse the game list <br />
|
||||
V to select the game <br />
|
||||
<br />
|
||||
Game: <br />
|
||||
Use Up, Down, Left, Right to Move <br />
|
||||
Z to jump (A) <br />
|
||||
X to sprint (B) <br />
|
||||
|
|
@ -90,7 +95,7 @@
|
|||
S to save <br />
|
||||
L to load <br />
|
||||
<br />
|
||||
Your current room: <b><label id="currentRoomID"></b> <br />
|
||||
Your current room: <b><label id="currentRoomID" style="color:white"></b> <br />
|
||||
You can join a remote game by roomID.<br />
|
||||
Remote room ID: <input type="text" id="roomID"><br />
|
||||
Play as player(1,2): <select id="playerIndex">
|
||||
|
|
|
|||
|
|
@ -12,10 +12,10 @@ function startGame() {
|
|||
|
||||
conn = new WebSocket(`ws://${location.host}/ws`);
|
||||
|
||||
// Clear old roomID
|
||||
conn.onopen = () => {
|
||||
log("WebSocket is opened. Send ping");
|
||||
roomID = roomID.value
|
||||
conn.send(JSON.stringify({"id": "ping", "data": GAME_LIST[gameIdx].nes, "room_id": roomID, "player_index": parseInt(playerIndex.value, 10)}));
|
||||
conn.send(JSON.stringify({"id": "ping", "data": GAME_LIST[gameIdx].nes, "room_id": roomID.value, "player_index": parseInt(playerIndex.value, 10)}));
|
||||
}
|
||||
|
||||
conn.onerror = error => {
|
||||
|
|
@ -39,7 +39,8 @@ function startGame() {
|
|||
break;
|
||||
case "start":
|
||||
log("Got start");
|
||||
currentRoomID.value = d["room_id"]
|
||||
roomID.value = ""
|
||||
currentRoomID.innerText = d["room_id"]
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue