Skip to content

Commit

Permalink
seems like i can't test private matchmaking without front
Browse files Browse the repository at this point in the history
  • Loading branch information
a-boring-man committed Mar 30, 2023
1 parent 6a3063b commit cfc261b
Showing 1 changed file with 14 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,18 @@ import { GameEngineService } from 'src/game_engine/game_engine.service';
import { PongEngineService } from 'src/pong_engine/pong_engine.service';
import { OnGatewayInit } from '@nestjs/websockets';

/**
* struct use to share the ball position
*/
interface ballpos {
x: number,
y: number,
}

/**
* struct use to share the game state
*/
interface gameState {
ballPosition: ballpos[],
paddleOne: {x: number, y: number },
paddleTwo: {x: number, y:number },
interface Private_order {
target: string,
type: string,
}

/**
* use in the waiting room for private matchmaking store
*/
export class Waiting_socket {
socket: Socket;
target;
game;
target: string;
game: string;
}

/**
Expand Down Expand Up @@ -113,6 +101,7 @@ export class GameUpdateCenterGateway implements OnGatewayInit, OnGatewayConnecti
players.l1 = this.socket_login.get(player1.id);
players.l2 = this.socket_login.get(player2.id);
this.server.to(player1.id).emit('players', players);
this.logger.debug("a game room has been created");
}

/**
Expand Down Expand Up @@ -281,15 +270,22 @@ export class GameUpdateCenterGateway implements OnGatewayInit, OnGatewayConnecti
}

@SubscribeMessage('private matchmaking')
handlePrivateMatchmaking(@MessageBody() body: any, @ConnectedSocket() client: Socket) {
handlePrivateMatchmaking(@MessageBody() body: Private_order, @ConnectedSocket() client: Socket) {
for (let i = 0; i < this.private_space.length; i++) {
const element = this.private_space[i];
if (element.socket === client) {
this.logger.debug("already waiting");
console.log(element);
return;
}
console.log(body);
if (element.target === this.socket_login.get(client.id)) {
this.StartGameRoom(element.socket, client, body.type);
this.private_space.splice(i, 1);
return;
}
}
this.logger.debug("not waiting so create a new wait order");
let private_room = new Waiting_socket();
private_room.socket = client;
private_room.target = body.target;
Expand Down

0 comments on commit cfc261b

Please sign in to comment.