Ejemplo n.º 1
0
        async void EndGame()
        {
            StopQuestionTimer();

            SendToAll.SendText(GamePlayers, "Game has ended. Final Score:");

            var playersByScore = (from i in GamePlayers
                                  where i.Score > 0
                                  orderby i.Score descending
                                  select i).ToArray();


            for (int i = 0; i < playersByScore.Length; i++)
            {
                playersByScore[i].Player.ChangeRating(playersByScore.Length - i);
            }

            var playersApplyNegScore = (from i in GamePlayers
                                        where i.Score == 0
                                        select i).ToList();

            foreach (var player in playersApplyNegScore)
            {
                player.Player.ChangeRating(-1);
            }

            await SendScore(true);

            Program.Server.Games.Remove(this);
        }
Ejemplo n.º 2
0
        async void Start()
        {
            SendToAll.SendText(GamePlayers, "Game is starting \n Your opponents:");

            await SendScore();
            await ChangeQuestion();
        }
Ejemplo n.º 3
0
        async Task SendScore(bool last = false)
        {
            await Task.Delay(500);

            var scoretext = "";

            foreach (var gamePlayer in GamePlayers)
            {
                if (last)
                {
                    scoretext += string.Format("{0} - {1} ({2}).\n",
                                               gamePlayer.Player.Name,
                                               gamePlayer.Score,
                                               gamePlayer.Player.Rating);
                }
                else
                {
                    scoretext += string.Format("{0} - {1}.\n",
                                               gamePlayer.Player.Name,
                                               gamePlayer.Score);
                }
            }

            SendToAll.SendText(GamePlayers, scoretext);
        }
Ejemplo n.º 4
0
 private Akka.Cluster.PubSub.Serializers.Proto.SendToAll SendToAllToProto(SendToAll sendToAll)
 {
     return(Akka.Cluster.PubSub.Serializers.Proto.SendToAll.CreateBuilder()
            .SetPath(sendToAll.Path)
            .SetAllButSelf(sendToAll.ExcludeSelf)
            .SetPayload(PayloadToProto(sendToAll.Message))
            .Build());
 }
 private SendToAll SendToAllToProto(Distributed.SendToAll sendToAll)
 {
     return(SendToAll.CreateBuilder()
            .SetPath(sendToAll.Path)
            .SetAllButSelf(sendToAll.ExcludeSelf)
            .SetPayload(PayloadToProto(sendToAll.Message))
            .Build());
 }
Ejemplo n.º 6
0
        private byte[] SendToAllToProto(SendToAll sendToAll)
        {
            var protoMessage = new Proto.Msg.SendToAll();

            protoMessage.Path       = sendToAll.Path;
            protoMessage.AllButSelf = sendToAll.ExcludeSelf;
            protoMessage.Payload    = _payloadSupport.PayloadToProto(sendToAll.Message);
            return(protoMessage.ToByteArray());
        }
Ejemplo n.º 7
0
        async Task ChangeQuestion()
        {
            AcceptMessages = false;
            StopQuestionTimer();

            foreach (var gameplayer in GamePlayers)
            {
                await Program.Server.Client.SendChatActionAsync(gameplayer.Player.ChatId, ChatAction.Typing);

                gameplayer.Answered = false;
            }


            if (QuestionNum == 0)
            {
                SendToAll.SendText(GamePlayers, "First question:");
            }
            else if (QuestionNum == GameConfig.QuestionsPerGame)
            {
                SendToAll.SendText(GamePlayers, "Last question:");
            }
            else if (QuestionNum > GameConfig.QuestionsPerGame)
            {
                SendToAll.SendText(GamePlayers, "Playing untill getting winner:");
            }
            else
            {
                SendToAll.SendText(GamePlayers, "Question " + QuestionNum + ":");
            }

            Question = QuestionSelector.SelectQuestion();
            QuestionNum++;

            await Task.Delay(250);

            var outtext = Question.QuestionText;
            int i       = 0;

            foreach (var answer in Question.Answers)
            {
                i++;
                outtext += "\n" + i + ") " + answer;
            }
            SendToAll.SendText(GamePlayers, outtext);

            AcceptMessages = true;

            TillNewQuestionDelayer = DelayedTask.DelayTask(new List <DelayedTask>()
            {
                new DelayedTask(() => ChangeQuestion(), 60),
                new DelayedTask(() => SendToAll.SendText(GamePlayers, "30 seconds remaining"), 30),
                new DelayedTask(() => SendToAll.SendText(GamePlayers, "15 seconds remaining"), 45),
                new DelayedTask(() => SendToAll.SendText(GamePlayers, "5 seconds remaining"), 55)
            });
        }
Ejemplo n.º 8
0
 void StartDelay()
 {
     Delayer = DelayedTask.DelayTask(new List <DelayedTask>()
     {
         new DelayedTask(() => StartGame(), 60),
         new DelayedTask(() => SendToAll.SendText(Players.ToArray(), "Game will start in 60 seconds."), 0),
         new DelayedTask(() => SendToAll.SendText(Players.ToArray(), "Game will start in 30 seconds."), 30),
         new DelayedTask(() => SendToAll.SendText(Players.ToArray(), "Game will start in 15 seconds."), 45),
         new DelayedTask(() => SendToAll.SendText(Players.ToArray(), "Game will start in 5 seconds."), 55)
     });
 }
Ejemplo n.º 9
0
        public void Can_serialize_SendToAll()
        {
            var message = new SendToAll("/user/u3", "hello", true);

            AssertEqual(message);
        }
 private Akka.Cluster.PubSub.Serializers.Proto.SendToAll SendToAllToProto(SendToAll sendToAll)
 {
     return Akka.Cluster.PubSub.Serializers.Proto.SendToAll.CreateBuilder()
         .SetPath(sendToAll.Path)
         .SetAllButSelf(sendToAll.ExcludeSelf)
         .SetPayload(PayloadToProto(sendToAll.Message))
         .Build();
 }
 private Distributed.SendToAll SendToAllFromProto(SendToAll send)
 {
     return(new Distributed.SendToAll(send.Path, PayloadFromProto(send.Payload), send.AllButSelf));
 }
 private Distributed.SendToAll SendToAllFromBinary(byte[] binary)
 {
     return(SendToAllFromProto(SendToAll.ParseFrom(binary)));
 }