Commit ec203d1c authored by 范雪寒's avatar 范雪寒

feat: 开始游戏的判断逻辑

parent 409da6cc
...@@ -36,23 +36,21 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -36,23 +36,21 @@ export default class SceneComponent extends MyCocosSceneComponent {
await this.networkHelper.initRoom(); await this.networkHelper.initRoom();
this.playerId = await this.networkHelper.joinRoom('op_16', 2); this.playerId = await this.networkHelper.joinRoom('op_16', 2);
const roomInfo = this.networkHelper.getRoomInfo(); // const roomInfo = this.networkHelper.getRoomInfo();
if (roomInfo.playerList.length == roomInfo.maxPlayers) { // if (roomInfo.playerList.length == roomInfo.maxPlayers) {
if (this.playerId == roomInfo.playerList[0].id) { // if (this.playerId == roomInfo.playerList[0].id) {
this.networkHelper.startGame(); // this.networkHelper.startGame();
} // }
} // }
roomInfo.playerList.forEach(player => { // roomInfo.playerList.forEach(player => {
// const startPos = JSON.parse(player.customProfile); // // const startPos = JSON.parse(player.customProfile);
// this.createTank(player.id, startPos); // // this.createTank(player.id, startPos);
}); // });
this.networkHelper.on('playerJoin', (event) => { this.networkHelper.on('playerJoin', (event) => {
const roomInfo = this.networkHelper.getRoomInfo(); const roomInfo = this.networkHelper.getRoomInfo();
if (roomInfo.playerList.length == roomInfo.maxPlayers) { if (roomInfo.playerList.length == roomInfo.maxPlayers) {
if (this.playerId == roomInfo.playerList[0].id) { this.networkHelper.startGame();
this.networkHelper.startGame();
}
} }
console.log("playerJoin", event); console.log("playerJoin", event);
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment