Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
 into main
  • Loading branch information
ethinot committed Apr 23, 2023
2 parents 83224ac + 8bb753f commit ec0793c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion client/src/phaser/gameObjects/Board.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default class Board {
handleSocketEvents() {
this.socket.on("map", (data: [[null | [string, string] | [string]]]) => {
const packetSize = Buffer.byteLength(JSON.stringify(data));
console.log(`[map] Packet size: ${packetSize} bytes`);
// console.log(`[map] Packet size: ${packetSize} bytes`);
for (let i = 0; i < data.length; i++) {
for (let j = 0; j < data[i].length; j++) {
const cell = data[i][j];
Expand Down
3 changes: 2 additions & 1 deletion client/src/phaser/gameObjects/Player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ export default class Player extends Phaser.GameObjects.Sprite {
_socket: Socket | null = null
) {
super(scene, 0, 0, "playerHeads");

// On mute tout les sons
this.setIsAudioMuted(true);
this.board = board;

this.color = color;
Expand Down
8 changes: 5 additions & 3 deletions client/src/phaser/scenes/GameScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export default class GameScene extends Phaser.Scene {
data: { playerID: string; x: number; y: number; direction: number }[]
) {
const packetSize = Buffer.byteLength(JSON.stringify(data));
console.log(`[playersPositions] Packet size: ${packetSize} bytes`);
// console.log(`[playersPositions] Packet size: ${packetSize} bytes`);
if (this.player?.id) {
const dataThisPlayer = data.find(
(p: { playerID: string }) => p.playerID === this.player?.id
Expand Down Expand Up @@ -120,7 +120,7 @@ export default class GameScene extends Phaser.Scene {
// Met a jour la liste des joueurs
updatePlayerList(data: { id: string; pseudo: string; color: number }[]) {
const packetSize = Buffer.byteLength(JSON.stringify(data));
console.log(`[playersList] Packet size: ${packetSize} bytes`);
// console.log(`[playersList] Packet size: ${packetSize} bytes`);

data.forEach((p) => {
const playerFound = this.players.find(
Expand Down Expand Up @@ -190,6 +190,8 @@ export default class GameScene extends Phaser.Scene {
this.socket?.on("gameUpdated", this.tickGame.bind(this));
this.socket?.on("leaderBoard", this.updateLeaderBoard.bind(this));
this.socket?.on("wrongPassword", () => {
// On clear le local storage
localStorage.removeItem("gamePassword");
localStorage.removeItem("gameId");
alert("Wrong password");
// Reload
Expand Down Expand Up @@ -232,7 +234,7 @@ export default class GameScene extends Phaser.Scene {
const soundState = isMuted ? false : true;
//wait for the player to be created
if (!this.player)
setTimeout(() => this.player?.setIsAudioMuted(soundState), 100);
setTimeout(() => this.player?.setIsAudioMuted(soundState), 1000);
else this.player?.setIsAudioMuted(soundState);
return isMuted;
}
Expand Down
3 changes: 3 additions & 0 deletions server/src/game/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Cell from "./cell";
import { playerPosition, Settings, CreateGameSettings } from "./interfaces";
import { getUserPseudo, saveUserStats } from "../database";
import { Stats } from "../enums/Stats";
import { promises } from "dns";

const skinsCount = 33;

Expand Down Expand Up @@ -90,6 +91,8 @@ export default class Game {

async join(playerSocket: Socket, password?: string): Promise<void> {
if (this.isPrivate && this.password !== password) {
// On attend une seconde pour éviter le message parte dans le néant
await new Promise((r) => setTimeout(r, 1000));
playerSocket.emit("wrongPassword");
return;
}
Expand Down
2 changes: 1 addition & 1 deletion server/src/game/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default class Player {
position = { x: 0, y: 0 } as playerPosition;
gameStats: PlayerGameStats;
color = 0;
score = 0;
score = 25;
territoryScore = 0;
isAlive = false;
socket: Socket;
Expand Down

0 comments on commit ec0793c

Please sign in to comment.