Add functionality to the kill/leave game buttons

This commit is contained in:
Oliver-Akins 2020-10-21 21:13:22 -06:00
parent 956c28ed39
commit aebbdf877e

View file

@ -38,10 +38,10 @@
<div v-if="is_host" class="controls">
<button v-if="is_host">Start Game</button>
<br>
<button>Kill Game</button>
<button @click.stop="handle_exit_button()">Kill Game</button>
</div>
<div v-else class="controls">
<button>Leave Game</button>
<button @click.stop="handle_exit_button()">Leave Game</button>
</div>
</div>
</template>
@ -86,11 +86,17 @@ export default {
if (this.is_host) {
let cont = confirm(`Are you sure you want to exit`);
if (cont) {
alert(`exiting game`)
this.$socket.emit(`KillGame`, {
game_code: this.game_code,
user: this.username,
});
};
} else {
this.$socket.emit(`LeaveGame`, {
username: this.username
this.$socket.emit(`KickPlayer`, {
game_code: this.game_code,
target: this.username,
user: this.username,
ban: false,
});
};
},
@ -120,7 +126,7 @@ export default {
PlayerKicked(data) {
if (data.player === this.username) {
this.$emit(`alert`, {
message: `You have been kicked from the game by the host.`,
message: `You have been removed from the game.`,
classes: [`error`],
});
setTimeout(() => {
@ -130,7 +136,7 @@ export default {
});
this.$emit(`go-to`, `game-type`);
}, 2000);
}
};
this.players = this.players.filter(x => x !== data.player);
}
},