added victory by forfeit
This commit is contained in:
4
memo.txt
4
memo.txt
@@ -1,6 +1,4 @@
|
|||||||
TODO:
|
TODO:
|
||||||
- lors d'un newRound() verifier si tout les joueurs sont encore en ligne et stopper le match sinon
|
|
||||||
(victoire si encore un joueur en ligne, annulation du match si aucun joueur en ligne)
|
|
||||||
- mode spectateur
|
- mode spectateur
|
||||||
- certaines utilisations de Math.floor() superflu ? Vérifier les appels.
|
- certaines utilisations de Math.floor() superflu ? Vérifier les appels.
|
||||||
(éventuellement Math.round() ?)
|
(éventuellement Math.round() ?)
|
||||||
@@ -26,6 +24,8 @@ Done:
|
|||||||
- Selection des modes de jeu via HTML
|
- Selection des modes de jeu via HTML
|
||||||
- Selection audio on/off via HTML
|
- Selection audio on/off via HTML
|
||||||
- Match Abort si tout les joueurs n'ont pas répondus assez vite (5 secondes)
|
- Match Abort si tout les joueurs n'ont pas répondus assez vite (5 secondes)
|
||||||
|
- lors d'un newRound() verifier si tout les joueurs sont encore en ligne et stopper le match sinon
|
||||||
|
(victoire si encore un joueur en ligne, annulation du match si aucun joueur en ligne)
|
||||||
|
|
||||||
-----------
|
-----------
|
||||||
BUG:
|
BUG:
|
||||||
|
|||||||
@@ -68,6 +68,8 @@ class GameComponentsClient extends GameComponentsExtensionForClient {
|
|||||||
scoreLeft: TextNumericValue;
|
scoreLeft: TextNumericValue;
|
||||||
scoreRight: TextNumericValue;
|
scoreRight: TextNumericValue;
|
||||||
text1: TextElem;
|
text1: TextElem;
|
||||||
|
text2: TextElem;
|
||||||
|
text3: TextElem;
|
||||||
|
|
||||||
w_grid_mid: RectangleClient;
|
w_grid_mid: RectangleClient;
|
||||||
w_grid_u1: RectangleClient;
|
w_grid_u1: RectangleClient;
|
||||||
@@ -90,6 +92,8 @@ class GameComponentsClient extends GameComponentsExtensionForClient {
|
|||||||
// Text
|
// Text
|
||||||
pos.assign(0, c.h_mid);
|
pos.assign(0, c.h_mid);
|
||||||
this.text1 = new TextElem(pos, Math.floor(c.w/8), ctx, "white");
|
this.text1 = new TextElem(pos, Math.floor(c.w/8), ctx, "white");
|
||||||
|
this.text2 = new TextElem(pos, Math.floor(c.w/24), ctx, "white");
|
||||||
|
this.text3 = new TextElem(pos, Math.floor(c.w/24), ctx, "white");
|
||||||
|
|
||||||
// Dotted Midline
|
// Dotted Midline
|
||||||
pos.assign(c.w_mid-c.midLineSize/2, 0+c.wallSize);
|
pos.assign(c.w_mid-c.midLineSize/2, 0+c.wallSize);
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ function drawLoop()
|
|||||||
drawStatic();
|
drawStatic();
|
||||||
|
|
||||||
gc.text1.update();
|
gc.text1.update();
|
||||||
|
gc.text2.update();
|
||||||
|
gc.text3.update();
|
||||||
|
|
||||||
drawDynamic();
|
drawDynamic();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ body {
|
|||||||
background-color: #222425;
|
background-color: #222425;
|
||||||
}
|
}
|
||||||
#canvas_container {
|
#canvas_container {
|
||||||
|
margin-top: 20px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
/* border: dashed rgb(245, 245, 245) 5px; */
|
/* border: dashed rgb(245, 245, 245) 5px; */
|
||||||
/* max-height: 80vh; */
|
/* max-height: 80vh; */
|
||||||
|
|||||||
@@ -78,12 +78,14 @@ function matchAbort()
|
|||||||
gc.text1.text = text;
|
gc.text1.text = text;
|
||||||
gc.text1.update();
|
gc.text1.update();
|
||||||
|
|
||||||
gc.text1.pos.assign(c.w*0.44, c.h*0.6);
|
setTimeout(() => {
|
||||||
gc.text1.text = "sorry =(";
|
gc.text2.pos.assign(c.w*0.44, c.h*0.6);
|
||||||
const oriSize = gc.text1.size;
|
gc.text2.text = "pardon =(";
|
||||||
gc.text1.size = gc.text1.size*0.2;
|
const oriSize = gc.text2.size;
|
||||||
gc.text1.update();
|
gc.text2.size = c.w*0.025;
|
||||||
gc.text1.size = oriSize;
|
gc.text2.update();
|
||||||
|
gc.text2.size = oriSize;
|
||||||
|
}, 3000);
|
||||||
}
|
}
|
||||||
|
|
||||||
function matchStart()
|
function matchStart()
|
||||||
|
|||||||
@@ -173,14 +173,30 @@ function scoreUpdate(data: ev.EventScoreUpdate)
|
|||||||
function matchEnd(data: ev.EventMatchEnd)
|
function matchEnd(data: ev.EventMatchEnd)
|
||||||
{
|
{
|
||||||
if (data.winner === clientInfo.side) {
|
if (data.winner === clientInfo.side) {
|
||||||
gc.text1.pos.assign(c.w*0.415, c.h_mid);
|
gc.text1.pos.assign(c.w*0.415, c.h*0.5);
|
||||||
gc.text1.text = "WIN";
|
gc.text1.text = "WIN";
|
||||||
|
if (data.forfeit) {
|
||||||
|
if (clientInfo.side === en.PlayerSide.left) {
|
||||||
|
gc.text2.pos.assign(c.w*0.65, c.h*0.42);
|
||||||
|
gc.text3.pos.assign(c.w*0.65, c.h*0.52);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
gc.text1.pos.assign(c.w*0.383, c.h_mid);
|
gc.text2.pos.assign(c.w*0.09, c.h*0.42);
|
||||||
|
gc.text3.pos.assign(c.w*0.09, c.h*0.52);
|
||||||
|
}
|
||||||
|
setTimeout(() => {
|
||||||
|
gc.text2.text = "par forfait";
|
||||||
|
}, 2500);
|
||||||
|
setTimeout(() => {
|
||||||
|
gc.text3.text = "calme ta joie";
|
||||||
|
}, 5000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
gc.text1.pos.assign(c.w*0.383, c.h*0.5);
|
||||||
gc.text1.text = "LOSE";
|
gc.text1.text = "LOSE";
|
||||||
}
|
}
|
||||||
// matchEnded = true;
|
// matchEnded = true; // unused
|
||||||
}
|
}
|
||||||
|
|
||||||
// export let matchEnded = false;
|
// export let matchEnded = false; // unused
|
||||||
|
|||||||
@@ -149,10 +149,13 @@ class GameSession {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
private _newRound(s: GameSession, ball: Ball) {
|
private _newRound(s: GameSession, ball: Ball) {
|
||||||
const gc = s.components;
|
if (s._checkDisconnexions()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
// https://fr.wikipedia.org/wiki/Tennis_de_table#Nombre_de_manches
|
// https://fr.wikipedia.org/wiki/Tennis_de_table#Nombre_de_manches
|
||||||
if (gc.scoreLeft >= 11 || gc.scoreRight >= 11)
|
const gc = s.components;
|
||||||
// if (gc.scoreLeft >= 2 || gc.scoreRight >= 2) // WIP: for testing
|
const minScore = 11;// can be changed for testing
|
||||||
|
if (gc.scoreLeft >= minScore || gc.scoreRight >= minScore)
|
||||||
{
|
{
|
||||||
if (Math.abs(gc.scoreLeft - gc.scoreRight) >= 2)
|
if (Math.abs(gc.scoreLeft - gc.scoreRight) >= 2)
|
||||||
{
|
{
|
||||||
@@ -165,6 +168,29 @@ class GameSession {
|
|||||||
ball.speed = ball.baseSpeed;
|
ball.speed = ball.baseSpeed;
|
||||||
ball.ballInPlay = true;
|
ball.ballInPlay = true;
|
||||||
}
|
}
|
||||||
|
private _checkDisconnexions() {
|
||||||
|
if (this.playersMap.size !== 2)
|
||||||
|
{
|
||||||
|
this.matchEnded = true;
|
||||||
|
if (this.playersMap.size != 0)
|
||||||
|
{
|
||||||
|
const gc = this.components;
|
||||||
|
const luckyWinner: ClientPlayer = this.playersMap.values().next().value;
|
||||||
|
let eventEnd: ev.EventMatchEnd;
|
||||||
|
if (luckyWinner.racket === gc.playerLeft) {
|
||||||
|
eventEnd = new ev.EventMatchEnd(en.PlayerSide.left, true);
|
||||||
|
console.log("Player Left WIN (by forfeit)");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
eventEnd = new ev.EventMatchEnd(en.PlayerSide.right, true);
|
||||||
|
console.log("Player Right WIN (by forfeit)");
|
||||||
|
}
|
||||||
|
luckyWinner.socket.send(JSON.stringify(eventEnd));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
private _matchEnd(s: GameSession) {
|
private _matchEnd(s: GameSession) {
|
||||||
s.matchEnded = true;
|
s.matchEnded = true;
|
||||||
const gc = s.components;
|
const gc = s.components;
|
||||||
|
|||||||
@@ -63,9 +63,11 @@ class EventScoreUpdate extends ServerEvent {
|
|||||||
|
|
||||||
class EventMatchEnd extends ServerEvent {
|
class EventMatchEnd extends ServerEvent {
|
||||||
winner: en.PlayerSide;
|
winner: en.PlayerSide;
|
||||||
constructor(winner: en.PlayerSide) {
|
forfeit: boolean;
|
||||||
|
constructor(winner: en.PlayerSide, forfeit = false) {
|
||||||
super(en.EventTypes.matchEnd);
|
super(en.EventTypes.matchEnd);
|
||||||
this.winner = winner;
|
this.winner = winner;
|
||||||
|
this.forfeit = forfeit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user