public ActionResult DbTest()
        {
            var db = new CardsReposiitory();

            var questions = db.GetQuestionCards();

            return null;
        }
Exemplo n.º 2
0
        public void StartGame(string lobbyCode)
        {
            var lobby = LobbyHub.Lobbies.SingleOrDefault(x => x.Code == lobbyCode.ToUpper());

            if (lobby == null)
                return;

            var db = new CardsReposiitory();

            lobby.ActiveGame = true;
            lobby.QuestionCards = db.GetQuestionCards();
            lobby.AnswerCards = db.GetAnswerCards();

            lobby.CurrentLeader = lobby.Users.First();
            lobby.CurrentQuestion = lobby.QuestionCards.Where(x => x.NumAnswers == 1).PickRandom(); // TODO: ALLOW MULTIPLE ANSWERS
            lobby.CurrentAwnsers = new List<Card>();

            foreach (var user in lobby.Users)
            {
                var cards = lobby.AnswerCards.Where(x => x.CardUsed == CardUsedEnum.Free).PickRandom(10).ToList();
                cards.ForEach(x => x.CardUsed = CardUsedEnum.InUse);

                user.CurrentCardsOnHand = cards;
            }

            foreach (var user in lobby.Users)
            {
                Clients.Client(user.ConnectionId).gameRecievedScores(lobby.Users.Select(x => new { x.Name, x.NumberOfPoints }));
            }

            foreach (var user in lobby.Users)
            {
                if (user == lobby.CurrentLeader)
                    continue;

                Clients.Client(user.ConnectionId).gameShowCurrentCards(user.CurrentCardsOnHand.Select(x => new { x.Id, x.Text }), lobby.CurrentQuestion.NumAnswers);
            }

            Clients.Client(lobby.CurrentLeader.ConnectionId).gameShowCurrentQuestion(lobby.CurrentQuestion.Text);
        }