Example #1
0
        public void Ready(string room)
        {
            if( string.IsNullOrEmpty(room) )
            {
                Clients.Caller.newMessage("Enter a group name!");
            }
            else
            {
                var clients = _groupMappings[room];
                clients.Find(x => x.ConnectionId == Context.ConnectionId).IsReady = true;

                var mathManger = new MathManager.MathManager();

                if(AllGroupMembersReady(room))
                {
                    //Send everyone the first question
                    foreach(var client in clients)
                    {
                        var nextEquation = mathManger.GetMathEquation();
                        Clients.Group(room).newQuestion(client.ConnectionId, nextEquation);
                    }
                }

                Clients.Group(room).setupOpponent(Context.ConnectionId);
            }
        }
Example #2
0
        //-----------------
        public void SubmitAnswer(string room, string questionCode, string questionId, string answer)
        {
            var mathManger = new MathManager.MathManager();
            var isCorrect = mathManger.Verify(questionCode, answer);
            if( isCorrect )
            {
                _groupMappings[room].Find(x => x.ConnectionId == Context.ConnectionId).Points += int.Parse(answer);
            }

            var nextEquation = mathManger.GetMathEquation();
            var points = _groupMappings[room].Find(x => x.ConnectionId == Context.ConnectionId).Points;
            Clients.Group(room).setAnswer(Context.ConnectionId, questionId, answer);
            Clients.Group(room).setResult(Context.ConnectionId, questionId, isCorrect, points);

            string winner;
            //Detect game conclusion
            if( GameConcluded(room, out winner) )
            {
                Clients.Group(room).setWinner(winner);
            }
            else
            {
                Clients.Group(room).newQuestion(Context.ConnectionId, nextEquation);
            }
        }