- add variable for disable bot movement
Site
    - fix bug with message in end screen game
    - fix dispose for list user in tournament page
This commit is contained in:
Kum1ta
2024-10-16 01:33:13 +02:00
parent adae90904b
commit 18eed2de28
5 changed files with 34 additions and 38 deletions

View File

@ -3,10 +3,10 @@
# ::: :::::::: # # ::: :::::::: #
# Bot.py :+: :+: :+: # # Bot.py :+: :+: :+: #
# +:+ +:+ +:+ # # +:+ +:+ +:+ #
# By: tomoron <tomoron@student.42.fr> +#+ +:+ +#+ # # By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2024/10/05 03:54:20 by tomoron #+# #+# # # Created: 2024/10/05 03:54:20 by tomoron #+# #+# #
# Updated: 2024/10/14 20:18:58 by tomoron ### ########.fr # # Updated: 2024/10/16 01:25:20 by edbernar ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
@ -18,6 +18,8 @@ import random
import asyncio import asyncio
import time import time
DISABLE_BOT_MOVEMENT = False
class Bot(Player): class Bot(Player):
def __init__(self, game=None, tournament=None): def __init__(self, game=None, tournament=None):
self.socket = DummySocket(game) self.socket = DummySocket(game)
@ -84,18 +86,19 @@ class Bot(Player):
async def goToObjectiveLoop(self): async def goToObjectiveLoop(self):
lastUpdate = time.time() lastUpdate = time.time()
while not self.isEnd(): while not self.isEnd():
if(self.pos["pos"] != self.objective["pos"] or self.pos["up"] != self.objective["up"]): if (not DISABLE_BOT_MOVEMENT):
self.pos["up"] = self.objective["up"] if(self.pos["pos"] != self.objective["pos"] or self.pos["up"] != self.objective["up"]):
self.pos["up"] = self.objective["up"]
maxDistance = GameSettings.maxPlayerSpeed * (time.time() - lastUpdate) maxDistance = GameSettings.maxPlayerSpeed * (time.time() - lastUpdate)
print("maxDistance :", maxDistance) print("maxDistance :", maxDistance)
travel = self.objective["pos"] - self.pos["pos"] travel = self.objective["pos"] - self.pos["pos"]
if(travel >= 0): if(travel >= 0):
travel = min(self.objective["pos"] - self.pos["pos"], maxDistance) travel = min(self.objective["pos"] - self.pos["pos"], maxDistance)
else: else:
travel = max(self.objective["pos"] - self.pos["pos"], -maxDistance) travel = max(self.objective["pos"] - self.pos["pos"], -maxDistance)
print("travel :", travel) print("travel :", travel)
self.game.move(self.socket, self.pos["pos"] + travel, self.pos["up"]) self.game.move(self.socket, self.pos["pos"] + travel, self.pos["up"])
lastUpdate = time.time() lastUpdate = time.time()
await asyncio.sleep(1 / 20) await asyncio.sleep(1 / 20)

View File

@ -3,10 +3,10 @@
# ::: :::::::: # # ::: :::::::: #
# GameSettings.py :+: :+: :+: # # GameSettings.py :+: :+: :+: #
# +:+ +:+ +:+ # # +:+ +:+ +:+ #
# By: tomoron <tomoron@student.42.fr> +#+ +:+ +#+ # # By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2024/10/06 16:33:56 by tomoron #+# #+# # # Created: 2024/10/06 16:33:56 by tomoron #+# #+# #
# Updated: 2024/10/12 23:31:00 by tomoron ### ########.fr # # Updated: 2024/10/16 01:24:44 by edbernar ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #

View File

@ -6,7 +6,7 @@
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */ /* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/18 00:53:53 by edbernar #+# #+# */ /* Created: 2024/08/18 00:53:53 by edbernar #+# #+# */
/* Updated: 2024/10/15 20:47:20 by edbernar ### ########.fr */ /* Updated: 2024/10/16 00:55:59 by edbernar ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -262,9 +262,9 @@ class MultiOnlineGamePage
endGameDiv.style.display = 'flex'; endGameDiv.style.display = 'flex';
intervalEnd = setInterval(() => { intervalEnd = setInterval(() => {
if (content.opponentLeft) if (content.opponentLeft)
simpleText.innerText = `Your opponent has given up...\nYou will be redirected to the ` + content.tournamentCode ? "tournamenet" : "lobby" + ` in ${time} seconds` simpleText.innerText = `Your opponent has given up...\nYou will be redirected to the ` + (content.tournamentCode ? "tournament" : "lobby") + ` in ${time} seconds`
else else
simpleText.innerText = `You will be redirected to the ` + content.tournamentCode ? "tournamenet" : "lobby" + ` in ${time} seconds` simpleText.innerText = `You will be redirected to the ` + (content.tournamentCode ? "tournament" : "lobby") + ` in ${time} seconds`
time--; time--;
if (time == -1) if (time == -1)
{ {

View File

@ -6,7 +6,7 @@
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */ /* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/01 13:42:29 by edbernar #+# #+# */ /* Created: 2024/10/01 13:42:29 by edbernar #+# #+# */
/* Updated: 2024/10/14 21:49:04 by edbernar ### ########.fr */ /* Updated: 2024/10/16 01:10:29 by edbernar ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -15,14 +15,14 @@ import { pageRenderer } from '/static/javascript/main.js';
const playerNb = [1, 2, 4, 5, 13, 14, 15, 16]; const playerNb = [1, 2, 4, 5, 13, 14, 15, 16];
const playerList = { const playerList = {
player1: {id: 0, username: null, pfp: null}, player1: {id: -1, username: null, pfp: null},
player2: {id: 0, username: null, pfp: null}, player2: {id: -1, username: null, pfp: null},
player4: {id: 0, username: null, pfp: null}, player4: {id: -1, username: null, pfp: null},
player5: {id: 0, username: null, pfp: null}, player5: {id: -1, username: null, pfp: null},
player13: {id: 0, username: null, pfp: null}, player13: {id: -1, username: null, pfp: null},
player14: {id: 0, username: null, pfp: null}, player14: {id: -1, username: null, pfp: null},
player15: {id: 0, username: null, pfp: null}, player15: {id: -1, username: null, pfp: null},
player16: {id: 0, username: null, pfp: null}, player16: {id: -1, username: null, pfp: null},
}; };
let divTopInfo = null; let divTopInfo = null;
let divInfo = null; let divInfo = null;
@ -62,7 +62,7 @@ class TournamentPage
divInfo = null; divInfo = null;
divChat = null; divChat = null;
Object.values(playerList).forEach((info) => { Object.values(playerList).forEach((info) => {
info.id = 0; info.id = -1;
info.username = null; info.username = null;
info.pfp = null; info.pfp = null;
}); });
@ -75,11 +75,8 @@ class TournamentPage
let i = 0; let i = 0;
Object.values(playerList).forEach((info) => { Object.values(playerList).forEach((info) => {
if (!found && info.id == 0 || info.id == content.id) if (!found && info.id == -1 || (info.id == content.id && info.id != 0))
{
found = true; found = true;
alreadyConnected = info.id == content.id;
}
if (!found) if (!found)
i++; i++;
}); });
@ -88,11 +85,6 @@ class TournamentPage
console.warn("Tournament is full."); console.warn("Tournament is full.");
return ; return ;
} }
// if (alreadyConnected)
// {
// console.warn("Player is already in game.");
// return ;
// }
newInfo(`${content.username} joined the tournament.`); newInfo(`${content.username} joined the tournament.`);
document.getElementById('user-' + playerNb[i]).innerText = content.username; document.getElementById('user-' + playerNb[i]).innerText = content.username;
document.getElementById('pfp-' + playerNb[i]).style.backgroundImage = `url(${content.pfp})`; document.getElementById('pfp-' + playerNb[i]).style.backgroundImage = `url(${content.pfp})`;

View File

@ -6,7 +6,7 @@
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */ /* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/01 13:29:50 by edbernar #+# #+# */ /* Created: 2024/10/01 13:29:50 by edbernar #+# #+# */
/* Updated: 2024/10/12 23:16:30 by edbernar ### ########.fr */ /* Updated: 2024/10/16 01:20:33 by edbernar ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -18,6 +18,7 @@ import { pageRenderer } from '/static/javascript/main.js'
function typeTournament(content) function typeTournament(content)
{ {
console.log("New tournament request : ", content);
if (pageRenderer.actualPage == LobbyPage) if (pageRenderer.actualPage == LobbyPage)
{ {
if (content.action == 0) if (content.action == 0)