예제 #1
0
        public IO_Answer AddAnswer(long SenderId, long RecipientId)
        {
            Gamer Sender    = Gamer(SenderId);
            Gamer Recipient = Gamer(RecipientId);

            if (Sender != null && Recipient != null && Task != null)
            {
                IO_Answer answer =
                    Task.Answers.FirstOrDefault(x => x.SenderId == SenderId);

                if (answer == null)
                {
                    answer = new IO_Answer()
                    {
                        Sender      = Sender,
                        SenderId    = SenderId,
                        Recipient   = Recipient,
                        RecipientId = RecipientId,
                        Task        = Task,
                        TaskId      = Task.Id,
                        GameSession = Game
                    };

                    Sender.Answers.Add(answer);
                    Recipient.Answers.Add(answer);
                    Task.Answers.Add(answer);
                    Game.Answers.Add(answer);
                }
                else
                {
                    answer.Recipient   = Recipient;
                    answer.RecipientId = RecipientId;
                }

                return(answer);
            }

            return(null);
        }
예제 #2
0
        private void SetAnswer(long SenderId, long RecipientId, ConnectGamer gamer = null)
        {
            gamer = gamer ?? GamerById(SenderId);
            GameMechanic game = gamer.Game.Game;

            IO_Answer answer = game.AddAnswer(SenderId, RecipientId);

            if (answer != null)
            {
                bool All = game.IsAllAnswer;

                if (!All)
                {
                    Clients.Caller.SetAnswers(new List <JsonAnswer>()
                    {
                        new JsonAnswer(answer)
                    });
                }
                else
                {
                    game.CalculatorCoints();
                    foreach (Gamer g in game.Gamers)
                    {
                        g.Ready = false;
                    }

                    Clients.Clients(GamersId(gamer))
                    .SetAnswers(game.Answers.Select(x => new JsonAnswer(x)).ToList());

                    Clients.Clients(GamersId(gamer))
                    .SetGamers(gamer.Game.Gamers.Select(x => new JsonGamer(x)).ToList());
                }
            }
            else
            {
                Clients.Caller.Reload();
            }
        }
예제 #3
0
 public JsonAnswer(IO_Answer answer)
 {
     SenderId = answer.SenderId ?? 0;
     RecipientId = answer.RecipientId;
     Coins = answer.Coins;
 }