join game in js
This commit is contained in:
parent
1addd381a3
commit
6059172c95
@ -24,7 +24,7 @@ def legal():
|
|||||||
@routes_ui.route("/lobby/<game_id>")
|
@routes_ui.route("/lobby/<game_id>")
|
||||||
def lobby(game_id):
|
def lobby(game_id):
|
||||||
# rendered by the javascript client-side
|
# rendered by the javascript client-side
|
||||||
return flask.render_template("lobby.html")
|
return flask.render_template("lobby.html",gameid=game_id)
|
||||||
|
|
||||||
@routes_ui.route("/solo")
|
@routes_ui.route("/solo")
|
||||||
def solo():
|
def solo():
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
// Display functions
|
// Display functions
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display the invalid rounds count message element, by removing the hidden CSS class.
|
* Display the invalid rounds count message element, by removing the hidden CSS class.
|
||||||
*
|
*
|
||||||
@ -296,8 +295,8 @@ function getChallengeModeRoundsCount() {
|
|||||||
* @returns the code of the room
|
* @returns the code of the room
|
||||||
*/
|
*/
|
||||||
function getRoomCode() {
|
function getRoomCode() {
|
||||||
//FIXME get the real room code
|
gameid = document.getElementById("gameid")
|
||||||
return "ABCDEF";
|
return gameid;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lobby initialization
|
// Lobby initialization
|
||||||
@ -317,6 +316,21 @@ function getRoomCode() {
|
|||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
function initLobby() {
|
function initLobby() {
|
||||||
|
|
||||||
|
gameid = getRoomCode();
|
||||||
|
socket = io({
|
||||||
|
auth:{
|
||||||
|
game_id: gameid
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
socket.on("connect", () => {
|
||||||
|
console.log("Connected !")
|
||||||
|
})
|
||||||
|
|
||||||
|
socket.on("playersjoin", (err) => {
|
||||||
|
console.log(`Failed to connect to socket: ${err.message}`);
|
||||||
|
});
|
||||||
if (hasJoinedRoom()) {
|
if (hasJoinedRoom()) {
|
||||||
displayRoomView();
|
displayRoomView();
|
||||||
if (isRoomOwner()) {
|
if (isRoomOwner()) {
|
||||||
|
@ -125,7 +125,7 @@ function createMultiPlayerRoom() {
|
|||||||
|
|
||||||
hideInvalidInputErrorMessage();
|
hideInvalidInputErrorMessage();
|
||||||
|
|
||||||
startGame()
|
startGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
function joinMultiPlayerRoom() {
|
function joinMultiPlayerRoom() {
|
||||||
@ -135,7 +135,7 @@ function joinMultiPlayerRoom() {
|
|||||||
|
|
||||||
hideInvalidInputErrorMessage();
|
hideInvalidInputErrorMessage();
|
||||||
|
|
||||||
//TODO: code to join multi player game
|
joinGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -211,12 +211,36 @@ function changeTheme() {
|
|||||||
async function startGame(){
|
async function startGame(){
|
||||||
username = document.getElementById("game_username").value;
|
username = document.getElementById("game_username").value;
|
||||||
let data = {}
|
let data = {}
|
||||||
data["username"] = username
|
data["username"] = username;
|
||||||
await makeAPIRequest("createGame",data);
|
response = makeAPIRequest("createGame",data);
|
||||||
|
response.then((value) => {
|
||||||
|
if (value["error"] != 0){
|
||||||
|
alert(value["msg"]);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
gameid = value["game_id"]
|
||||||
|
window.location.href = "/lobby/" + gameid;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
async function joinGame(){
|
async function joinGame(){
|
||||||
username = document.getElementById("game_username").value();
|
username = document.getElementById("game_username").value;
|
||||||
gameid = document.getElementById("game_room_code").value();
|
gameid = document.getElementById("game_room_code").value;
|
||||||
|
console.log(username);
|
||||||
|
data = {}
|
||||||
|
data["username"] = username;
|
||||||
|
data["game_id"] = gameid;
|
||||||
|
response = makeAPIRequest("joinGame",data);
|
||||||
|
response.then((value)=>{
|
||||||
|
console.log(value);
|
||||||
|
if (value["error"] != 0){
|
||||||
|
//alert(value["msg"]);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
//window.location.href = "/lobby/" + gameid;
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
// Set event listeners
|
// Set event listeners
|
||||||
|
|
||||||
|
@ -72,8 +72,8 @@
|
|||||||
<a href="/legal" class="footer_link link" target="_blank" title="Consulter les mentions légales de Truth Inquiry (ouverture dans un nouvel onglet)">Mentions légales</a>
|
<a href="/legal" class="footer_link link" target="_blank" title="Consulter les mentions légales de Truth Inquiry (ouverture dans un nouvel onglet)">Mentions légales</a>
|
||||||
</div>
|
</div>
|
||||||
</footer>
|
</footer>
|
||||||
<script src="/static/js/api.js"></script>
|
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.4.1/socket.io.min.js"></script>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.4.1/socket.io.min.js"></script>
|
||||||
|
<script src="/static/js/api.js"></script>
|
||||||
<script src="/static/js/game_common.js"></script>
|
<script src="/static/js/game_common.js"></script>
|
||||||
<script src="/static/js/game_start_page.js"></script>
|
<script src="/static/js/game_start_page.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
@ -61,10 +61,10 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</noscript>
|
</noscript>
|
||||||
<script src="/static/js/api.js"></script>
|
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.4.1/socket.io.min.js"></script>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.4.1/socket.io.min.js"></script>
|
||||||
|
<script src="/static/js/api.js"></script>
|
||||||
<script src="/static/js/game_common.js"></script>
|
<script src="/static/js/game_common.js"></script>
|
||||||
<script src="/static/js/game_lobby.js"></script>
|
<script src="/static/js/game_lobby.js"></script>
|
||||||
|
<input type="hidden" id="game_id" name="game_id" value={{gameid}} />
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
Loading…
Reference in New Issue
Block a user