Merge branch 'luke'
This commit is contained in:
@@ -274,7 +274,7 @@ export class GameSession {
|
|||||||
gc.scoreRight = 3;
|
gc.scoreRight = 3;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ // TODO: match draw, verifier la getion coté Nest
|
{
|
||||||
gc.scoreLeft = 0;
|
gc.scoreLeft = 0;
|
||||||
gc.scoreRight = 0;
|
gc.scoreRight = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,10 +87,12 @@ export class GameService {
|
|||||||
if (user.status === STATUS.IN_POOL || user.status === STATUS.IN_GAME)
|
if (user.status === STATUS.IN_POOL || user.status === STATUS.IN_GAME)
|
||||||
{
|
{
|
||||||
await this.deleteToken(user);
|
await this.deleteToken(user);
|
||||||
user.status = STATUS.CONNECTED;
|
if (user.status === STATUS.IN_POOL) {
|
||||||
|
user.status = STATUS.CONNECTED;
|
||||||
|
}
|
||||||
this.userRepository.save(user);
|
this.userRepository.save(user);
|
||||||
}
|
}
|
||||||
if (grantTicketDto.isGameIsWithInvitation === true)
|
if (grantTicketDto.isGameIsWithInvitation === true && user.status !== STATUS.IN_GAME)
|
||||||
{
|
{
|
||||||
const secondUser : Partial<User> = await this.userService.findOne(grantTicketDto.playerTwoUsername)
|
const secondUser : Partial<User> = await this.userService.findOne(grantTicketDto.playerTwoUsername)
|
||||||
if (!secondUser || secondUser.username === user.username)
|
if (!secondUser || secondUser.username === user.username)
|
||||||
@@ -105,7 +107,7 @@ export class GameService {
|
|||||||
this.userService.updateStatus(user.id, "In Pool")
|
this.userService.updateStatus(user.id, "In Pool")
|
||||||
return res.status(HttpStatus.OK).json({ token : encryptedTextToReturn });
|
return res.status(HttpStatus.OK).json({ token : encryptedTextToReturn });
|
||||||
}
|
}
|
||||||
else if (grantTicketDto.isGameIsWithInvitation === false) {
|
else if (grantTicketDto.isGameIsWithInvitation === false && user.status !== STATUS.IN_GAME) {
|
||||||
const encryptedTextToReturn = await this.encryptToken(user.username + '_'
|
const encryptedTextToReturn = await this.encryptToken(user.username + '_'
|
||||||
+ grantTicketDto.gameOptions + '_' + grantTicketDto.isGameIsWithInvitation + '_' + new Date())
|
+ grantTicketDto.gameOptions + '_' + grantTicketDto.isGameIsWithInvitation + '_' + new Date())
|
||||||
const tok = this.tokenGameRepository.create(grantTicketDto);
|
const tok = this.tokenGameRepository.create(grantTicketDto);
|
||||||
@@ -280,6 +282,7 @@ export class GameService {
|
|||||||
{
|
{
|
||||||
this.userService.incrementDraws(playerOne.id)
|
this.userService.incrementDraws(playerOne.id)
|
||||||
this.userService.incrementDraws(playerTwo.id)
|
this.userService.incrementDraws(playerTwo.id)
|
||||||
|
console.log("DRAW NEST");
|
||||||
}
|
}
|
||||||
else if (game.playerOneUsernameResult < game.playerTwoUsernameResult)
|
else if (game.playerOneUsernameResult < game.playerTwoUsernameResult)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -193,7 +193,7 @@ export class UsersService {
|
|||||||
.getOne();
|
.getOne();
|
||||||
if (!user.stats || !user)
|
if (!user.stats || !user)
|
||||||
throw new HttpException(`The user's stats could not be found.`,HttpStatus.NOT_FOUND);
|
throw new HttpException(`The user's stats could not be found.`,HttpStatus.NOT_FOUND);
|
||||||
user.stats.winGame++;
|
user.stats.drawGame++;
|
||||||
user.stats.totalGame++;
|
user.stats.totalGame++;
|
||||||
this.userRepository.save(user);
|
this.userRepository.save(user);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,43 +59,43 @@
|
|||||||
optionsAreNotSet = false;
|
optionsAreNotSet = false;
|
||||||
showWaitPage = true;
|
showWaitPage = true;
|
||||||
const matchOptions = pong.computeMatchOptions(options);
|
const matchOptions = pong.computeMatchOptions(options);
|
||||||
|
try {
|
||||||
const responseWhenGrantToken = fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/game/ticket`, {
|
const response = await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/game/ticket`, {
|
||||||
method : "POST",
|
method : "POST",
|
||||||
headers : {'Content-Type': 'application/json'},
|
headers : {'Content-Type': 'application/json'},
|
||||||
body : JSON.stringify({
|
body : JSON.stringify({
|
||||||
playerOneUsername : options.playerOneUsername,
|
playerOneUsername : options.playerOneUsername,
|
||||||
playerTwoUsername : options.playerTwoUsername,
|
playerTwoUsername : options.playerTwoUsername,
|
||||||
gameOptions : matchOptions,
|
gameOptions : matchOptions,
|
||||||
isGameIsWithInvitation : options.isSomeoneIsInvited
|
isGameIsWithInvitation : options.isSomeoneIsInvited
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
const responseFromServer = await responseWhenGrantToken;
|
console.log("status : " + response.status);
|
||||||
const responseInjson = await responseFromServer.json();
|
const responseBody = await response.json();
|
||||||
const token : string = responseInjson.token;
|
const token : string = responseBody.token;
|
||||||
showWaitPage = false;
|
showWaitPage = false;
|
||||||
console.log("status : " + responseFromServer.status);
|
if (response.ok && token)
|
||||||
if (responseFromServer.status != 200)
|
{
|
||||||
{
|
watchGameStateInterval = setInterval(watchGameState, watchGameStateIntervalRate);
|
||||||
console.log(responseInjson);
|
pong.init(matchOptions, options, gameAreaId, token);
|
||||||
console.log("On refuse le ticket");
|
hiddenGame = false;
|
||||||
errorMessage = responseInjson.message;
|
}
|
||||||
showError = true;
|
else
|
||||||
options.reset(user.username);
|
{
|
||||||
setTimeout(() => {
|
console.log(responseBody);
|
||||||
optionsAreNotSet = true;
|
console.log("On refuse le ticket");
|
||||||
showError = false;
|
errorMessage = responseBody.message;
|
||||||
errorMessage = "";
|
showError = true;
|
||||||
}, 5000);
|
options.reset(user.username);
|
||||||
|
setTimeout(() => {
|
||||||
|
optionsAreNotSet = true;
|
||||||
|
showError = false;
|
||||||
|
errorMessage = "";
|
||||||
|
}, 5000);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e);
|
||||||
}
|
}
|
||||||
else if (token)
|
|
||||||
{
|
|
||||||
watchGameStateInterval = setInterval(watchGameState, watchGameStateIntervalRate);
|
|
||||||
pong.init(matchOptions, options, gameAreaId, token);
|
|
||||||
hiddenGame = false;
|
|
||||||
}
|
|
||||||
// TODO: Un "else" peut-être ? Si pas de token on fait un truc ?
|
|
||||||
// Si on ne rentre pas dans le else if, du coup il ne se passe rien.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const initGameForInvitedPlayer = async(invitation : any) =>
|
const initGameForInvitedPlayer = async(invitation : any) =>
|
||||||
|
|||||||
@@ -2,20 +2,29 @@
|
|||||||
import * as c from "./constants.js"
|
import * as c from "./constants.js"
|
||||||
|
|
||||||
// export const soundPongArr: HTMLAudioElement[] = [];
|
// export const soundPongArr: HTMLAudioElement[] = [];
|
||||||
|
export let muteFlag: boolean;
|
||||||
export const soundPongArr: HTMLAudioElement[] = [];
|
export const soundPongArr: HTMLAudioElement[] = [];
|
||||||
export let soundRoblox: HTMLAudioElement;
|
export let soundRoblox: HTMLAudioElement;
|
||||||
|
|
||||||
export function initAudio(sound: string)
|
export function initAudio(sound: string)
|
||||||
{
|
{
|
||||||
let muteFlag: boolean;
|
soundPongArr.length = 0;
|
||||||
|
soundRoblox = null;
|
||||||
|
|
||||||
if (sound === "on") {
|
if (sound === "on") {
|
||||||
muteFlag = false;
|
muteFlag = false;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
muteFlag = true;
|
muteFlag = true;
|
||||||
|
return; // Could be changed
|
||||||
|
/*
|
||||||
|
Stop initAudio() here because in the current state of the game
|
||||||
|
there no way to change muteFlag after game start.
|
||||||
|
If it becomes an option,
|
||||||
|
we should continue initAudio() regardless of the muteFlag.
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
soundPongArr.length = 0;
|
|
||||||
soundPongArr.push(new Audio("http://" + process.env.WEBSITE_HOST + ":" + process.env.WEBSITE_PORT + "/sound/pong/"+1+".ogg"));
|
soundPongArr.push(new Audio("http://" + process.env.WEBSITE_HOST + ":" + process.env.WEBSITE_PORT + "/sound/pong/"+1+".ogg"));
|
||||||
soundPongArr.push(new Audio("http://" + process.env.WEBSITE_HOST + ":" + process.env.WEBSITE_PORT + "/sound/pong/"+2+".ogg"));
|
soundPongArr.push(new Audio("http://" + process.env.WEBSITE_HOST + ":" + process.env.WEBSITE_PORT + "/sound/pong/"+2+".ogg"));
|
||||||
soundPongArr.forEach((value) => {
|
soundPongArr.forEach((value) => {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
import { Vector, VectorInteger } from "../../shared_js/class/Vector.js";
|
import { Vector, VectorInteger } from "../../shared_js/class/Vector.js";
|
||||||
import type { GraphicComponent } from "../../shared_js/class/interface.js";
|
import type { GraphicComponent } from "../../shared_js/class/interface.js";
|
||||||
import { Rectangle, MovingRectangle, Racket, Ball } from "../../shared_js/class/Rectangle.js";
|
import { Rectangle, MovingRectangle, Racket, Ball } from "../../shared_js/class/Rectangle.js";
|
||||||
import { soundPongArr } from "../audio.js"
|
import { muteFlag, soundPongArr } from "../audio.js"
|
||||||
import { random } from "../utils.js";
|
import { random } from "../utils.js";
|
||||||
|
|
||||||
function updateRectangle(this: RectangleClient) {
|
function updateRectangle(this: RectangleClient) {
|
||||||
@@ -70,6 +70,7 @@ export class BallClient extends Ball implements GraphicComponent {
|
|||||||
color: string;
|
color: string;
|
||||||
update: () => void;
|
update: () => void;
|
||||||
clear: (pos?: VectorInteger) => void;
|
clear: (pos?: VectorInteger) => void;
|
||||||
|
soundSwitch = false;
|
||||||
constructor(pos: VectorInteger, size: number, baseSpeed: number, speedIncrease: number,
|
constructor(pos: VectorInteger, size: number, baseSpeed: number, speedIncrease: number,
|
||||||
ctx: CanvasRenderingContext2D, color: string)
|
ctx: CanvasRenderingContext2D, color: string)
|
||||||
{
|
{
|
||||||
@@ -81,9 +82,14 @@ export class BallClient extends Ball implements GraphicComponent {
|
|||||||
}
|
}
|
||||||
bounce(collider?: Rectangle) {
|
bounce(collider?: Rectangle) {
|
||||||
this._bounceAlgo(collider);
|
this._bounceAlgo(collider);
|
||||||
let i = Math.floor(random(0, soundPongArr.length));
|
if (!muteFlag)
|
||||||
soundPongArr[ i ].play();
|
{
|
||||||
console.log(`sound_i=${i}`); // debug log
|
this.soundSwitch = !this.soundSwitch;
|
||||||
|
soundPongArr[this.soundSwitch ? 1 : 0].play();
|
||||||
|
// let i = Math.floor(random(0, soundPongArr.length));
|
||||||
|
// soundPongArr[ i ].play();
|
||||||
|
// console.log(`sound_i=${i}`); // debug log
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import * as en from "../shared_js/enums.js"
|
|||||||
import * as msg from "./message.js";
|
import * as msg from "./message.js";
|
||||||
import type { RacketClient } from "./class/RectangleClient.js";
|
import type { RacketClient } from "./class/RectangleClient.js";
|
||||||
import { repeatInput } from "./handleInput.js";
|
import { repeatInput } from "./handleInput.js";
|
||||||
import { soundRoblox } from "./audio.js"
|
import { muteFlag, soundRoblox } from "./audio.js"
|
||||||
import { sleep } from "./utils.js";
|
import { sleep } from "./utils.js";
|
||||||
import { Vector, VectorInteger } from "../shared_js/class/Vector.js";
|
import { Vector, VectorInteger } from "../shared_js/class/Vector.js";
|
||||||
|
|
||||||
@@ -198,11 +198,14 @@ function gameUpdate(data: ev.EventGameUpdate)
|
|||||||
function scoreUpdate(data: ev.EventScoreUpdate)
|
function scoreUpdate(data: ev.EventScoreUpdate)
|
||||||
{
|
{
|
||||||
// console.log("scoreUpdate");
|
// console.log("scoreUpdate");
|
||||||
if (clientInfo.side === en.PlayerSide.left && data.scoreRight > gc.scoreRight.value) {
|
if (!muteFlag)
|
||||||
soundRoblox.play();
|
{
|
||||||
}
|
if (clientInfo.side === en.PlayerSide.left && data.scoreRight > gc.scoreRight.value) {
|
||||||
else if (clientInfo.side === en.PlayerSide.right && data.scoreLeft > gc.scoreLeft.value) {
|
soundRoblox.play();
|
||||||
soundRoblox.play();
|
}
|
||||||
|
else if (clientInfo.side === en.PlayerSide.right && data.scoreLeft > gc.scoreLeft.value) {
|
||||||
|
soundRoblox.play();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
gc.scoreLeft.value = data.scoreLeft;
|
gc.scoreLeft.value = data.scoreLeft;
|
||||||
gc.scoreRight.value = data.scoreRight;
|
gc.scoreRight.value = data.scoreRight;
|
||||||
|
|||||||
Reference in New Issue
Block a user