From bc0bfbea0fc5dc2e73c4ee927b81f542bb133031 Mon Sep 17 00:00:00 2001 From: Martin Berg Alstad <600878@stud.hvl.no> Date: Thu, 20 Jul 2023 15:00:03 +0200 Subject: [PATCH] Created method to remove a player from a game --- pac-man-board-game/Services/Game.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pac-man-board-game/Services/Game.cs b/pac-man-board-game/Services/Game.cs index 0fbfb3d..a9f681d 100644 --- a/pac-man-board-game/Services/Game.cs +++ b/pac-man-board-game/Services/Game.cs @@ -62,6 +62,15 @@ public class Game // TODO handle disconnects and reconnects return true; } + public IPlayer? RemovePlayer(string username) + { + var index = Players.FindIndex(p => p.Username == username); + if (index == -1) return null; + var removedPlayer = Players[index]; + Players.RemoveAt(index); + return removedPlayer; + } + private void SetSpawn(IPlayer player) { if (player.PacMan.SpawnPosition is not null) return;