using System; using System.Collections.Generic; using System.Linq; using Newtonsoft.Json; [Serializable] [JsonObject] public class Room { public string code; public Dictionary questions; public Dictionary players; public string currentQuestionId; public double creationDate; public int currentState; public Room(string _code) { code = _code; creationDate = DateTime.Now.ToOADate(); players = new Dictionary(); questions = new Dictionary(); currentQuestionId = ""; currentState = 1; //default by PC } /// /// Return the only player with a specific ID /// /// public Player GetPlayerById(string id) { return players[id]; } public List GetPlayerList() { return new List(players.Values); } /// /// return the list of player ordered by who joined first /// /// public List GetOrderedPlayerList() { return players.Values.OrderBy(x => x.creationDate).ToList(); } public List GetQuestionsByPlayer(Player player) { List playerQuestions = new(); foreach (Question question in new List(questions.Values)) { foreach (Proposition proposition in new List(question.propositions.Values)) { if (proposition.owner.id == player.id) { playerQuestions.Add(question); break; } } } return playerQuestions; } public void SetPlayersAreReady(int _state) { currentState = _state; } public List GetPropositionsByPlayer(Player player) { List playerPropositions = new(); foreach (Question question in new List(questions.Values)) { foreach (Proposition proposition in new List(question.propositions.Values)) { if (proposition.owner.id == player.id) { playerPropositions.Add(proposition); break; } } } return playerPropositions; } }