91 lines
2.2 KiB
C#
91 lines
2.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Newtonsoft.Json;
|
|
|
|
[Serializable]
|
|
[JsonObject]
|
|
public class Room
|
|
{
|
|
public string code;
|
|
public Dictionary<string, Question> questions;
|
|
public Dictionary<string, Player> players;
|
|
public int currentQuestion;
|
|
public double creationDate;
|
|
public int currentState;
|
|
|
|
public Room(string _code)
|
|
{
|
|
code = _code;
|
|
creationDate = DateTime.Now.ToOADate();
|
|
players = new Dictionary<string, Player>();
|
|
questions = new Dictionary<string, Question>();
|
|
currentQuestion = 0;
|
|
currentState = 1; //default by PC
|
|
}
|
|
|
|
public List<Player> GetPlayerList()
|
|
{
|
|
return new List<Player>(players.Values);
|
|
}
|
|
|
|
/// <summary>
|
|
/// return the list of player ordered by who joined first
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<Player> GetOrderedPlayerList()
|
|
{
|
|
return players.Values.OrderBy(x => x.creationDate).ToList();
|
|
}
|
|
|
|
public List<Question> GetQuestionList()
|
|
{
|
|
return new List<Question>(questions.Values);
|
|
}
|
|
|
|
public List<Question> GetQuestionsByPlayer(Player player)
|
|
{
|
|
List<Question> questions = new();
|
|
|
|
foreach (Question question in GetQuestionList())
|
|
{
|
|
foreach (Proposition proposition in new List<Proposition>(question.propositions.Values))
|
|
{
|
|
if (proposition.owner.id == player.id)
|
|
{
|
|
questions.Add(question);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
return questions;
|
|
}
|
|
|
|
|
|
public void SetPlayersAreReady(int _state)
|
|
{
|
|
currentState = _state;
|
|
}
|
|
|
|
public List<Proposition> GetPropositionsByPlayer(Player player)
|
|
{
|
|
List<Proposition> propositions = new();
|
|
|
|
foreach (Question question in GetQuestionList())
|
|
{
|
|
foreach (Proposition proposition in new List<Proposition>(question.propositions.Values))
|
|
{
|
|
if (proposition.owner.id == player.id)
|
|
{
|
|
propositions.Add(proposition);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
return propositions;
|
|
}
|
|
}
|
|
|