/// <summary> /// Allow the user to create a room with a table inside it for Texas Hold’em Poker game that other user can join & play. /// </summary> /// <remarks>UC003: Create a New Room</remarks> /// <see cref="https://docs.google.com/document/d/1OTee6BGDWK2usL53jdoeBOI-1Jh8wyNejbQ0ZroUhcA/edit#heading=h.eqjp0wvvpmjg"/> /// <param name="level">user level</param> /// <returns>the new created room</returns> public Room CreateNewRoom(int level, GamePreferences config, out Player creator) { creator = new Player(); // creating the room and adding the creator as a passive player to it. var room = new Room(creator, config); BindPlayerToRoom(creator, room); League league = FindLeagueToFill(GetAllLeaguesAtLevel(level)); if (league == null) { throw new LevelNotFoundException("Requested level: " + level); } league.Rooms.Add(room); BindRoomToLeague(room, league); RoomsByID.Add(room.GetHashCode(), room); creator.Lock = room; return(room); }
private bool RemoveRoom(Room room) { // Note: aggressive approach - all the players kicked out /* TODO: try/catch for gentle approach? * example - if there are players at the room, this removal will fail. * */ if (room.Players.Count > 0) { foreach (var player in room.Players) { RemovePlayer(player); } room.ClearAll(); } RoomsByID.Remove(room.GetHashCode()); // remove the room from the league roomsManager[room].RemoveRoom(room); // remove the room from the room's dictionary. return(roomsManager.Remove(room)); }