/// <summary> /// Get the next commander based round winner /// </summary> /// <returns></returns> public Entities.User Winner() { Entities.GameRoundCard card = Answers.Find(x => x.Winner); if (card != null) { return(card.PlayedBy); } return(null); }
/// <summary> /// Constructors /// </summary> /// <param name="key"></param> /// <param name="answers"></param> public GroupedAnswers(Int32 key, List <Entities.GameRoundCard> answers) { this.Key = key; this.Answers = answers.OrderBy(x => x.PlayOrder).ToList(); Entities.GameRoundCard firstCard = Answers.First(); this.PlayedBy = firstCard.PlayedBy; this.Winner = firstCard.Winner; this.AnswerCount = Answers.Count; this.AutoPlayed = firstCard.AutoPlayed; }
private Entities.GameRoundCard CreateQuestion(IEnumerable <Entities.Card> cards, Entities.Game game) { Entities.Card card = cards.FirstOrDefault(); Entities.GameRoundCard question = null; if (card != null) { Entities.GameRound round = game.CurrentRound(); question = new Entities.GameRoundCard(card, round.CardCommander.UserId, round.GameRoundID, game.GameID); } return(question); }
/// <summary> /// Handle dealing cards to players in <paramref name="game"/> /// </summary> /// <param name="game">The game to deal cards for</param> /// <param name="dealQuestion">Is a question card needed</param> public void Execute(Entities.Game game, Boolean dealQuestion) { List<Entities.Card> questions; List<Entities.Card> answers; _shuffleCards.Execute(game, out questions, out answers); IEnumerable<Entities.Card> filteredQuestions = _excludeByCount.Execute(questions, game.QuestionShuffleCount); Entities.GameRoundCard dealtQuestion = null; if(dealQuestion) { dealtQuestion = CreateQuestion(filteredQuestions, game); } else { dealtQuestion = new Entities.GameRoundCard { Card = game.CurrentRound().Question }; } IEnumerable<Entities.Card> filteredAnswers = _excludeCurrentHands.Execute(answers); filteredAnswers = _excludeByCount.Execute(filteredAnswers, game.AnswerShuffleCount); Dictionary<Int32, Int32> drawCount = _calculateDrawCount.Execute(dealtQuestion.Card, game.Players); Boolean needMoreQuestions = dealtQuestion == null && dealQuestion; Boolean needMoreAnswers = drawCount.Values.Sum() > filteredAnswers.Count(); if (needMoreQuestions || needMoreAnswers) { if (needMoreQuestions) { //Update reshuffle counts filteredQuestions = _excludeByCount.Execute(questions, ++game.QuestionShuffleCount); //Reselect question card dealtQuestion = CreateQuestion(filteredQuestions, game); drawCount = _calculateDrawCount.Execute(dealtQuestion.Card, game.Players); needMoreAnswers = drawCount.Values.Sum() > filteredAnswers.Count(); } if (needMoreAnswers) { filteredAnswers = _excludeCurrentHands.Execute(answers); filteredAnswers = _excludeByCount.Execute(filteredAnswers, ++game.AnswerShuffleCount); } _updateGame.Execute(new Entities.Filters.Game.UpdateCounts(game.GameID, game.QuestionShuffleCount, game.AnswerShuffleCount)); } if (dealQuestion) { _insertGameRoundCard.Execute(new List<Entities.GameRoundCard> { dealtQuestion }); game.CurrentRound().Question = dealtQuestion.Card; } _createHand.Execute(filteredAnswers.ToList(), drawCount, game); }
private Entities.GameRoundCard CreateQuestion(IEnumerable<Entities.Card> cards, Entities.Game game) { Entities.Card card = cards.FirstOrDefault(); Entities.GameRoundCard question = null; if (card != null) { Entities.GameRound round = game.CurrentRound(); question = new Entities.GameRoundCard(card, round.CardCommander.UserId, round.GameRoundID, game.GameID); } return question; }
/// <summary> /// Handle dealing cards to players in <paramref name="game"/> /// </summary> /// <param name="game">The game to deal cards for</param> /// <param name="dealQuestion">Is a question card needed</param> public void Execute(Entities.Game game, Boolean dealQuestion) { List <Entities.Card> questions; List <Entities.Card> answers; _shuffleCards.Execute(game, out questions, out answers); IEnumerable <Entities.Card> filteredQuestions = _excludeByCount.Execute(questions, game.QuestionShuffleCount); Entities.GameRoundCard dealtQuestion = null; if (dealQuestion) { dealtQuestion = CreateQuestion(filteredQuestions, game); } else { dealtQuestion = new Entities.GameRoundCard { Card = game.CurrentRound().Question }; } IEnumerable <Entities.Card> filteredAnswers = _excludeCurrentHands.Execute(answers); filteredAnswers = _excludeByCount.Execute(filteredAnswers, game.AnswerShuffleCount); Dictionary <Int32, Int32> drawCount = _calculateDrawCount.Execute(dealtQuestion.Card, game.Players); Boolean needMoreQuestions = dealtQuestion == null && dealQuestion; Boolean needMoreAnswers = drawCount.Values.Sum() > filteredAnswers.Count(); if (needMoreQuestions || needMoreAnswers) { if (needMoreQuestions) { //Update reshuffle counts filteredQuestions = _excludeByCount.Execute(questions, ++game.QuestionShuffleCount); //Reselect question card dealtQuestion = CreateQuestion(filteredQuestions, game); drawCount = _calculateDrawCount.Execute(dealtQuestion.Card, game.Players); needMoreAnswers = drawCount.Values.Sum() > filteredAnswers.Count(); } if (needMoreAnswers) { filteredAnswers = _excludeCurrentHands.Execute(answers); filteredAnswers = _excludeByCount.Execute(filteredAnswers, ++game.AnswerShuffleCount); } _updateGame.Execute(new Entities.Filters.Game.UpdateCounts(game.GameID, game.QuestionShuffleCount, game.AnswerShuffleCount)); } if (dealQuestion) { _insertGameRoundCard.Execute(new List <Entities.GameRoundCard> { dealtQuestion }); game.CurrentRound().Question = dealtQuestion.Card; } _createHand.Execute(filteredAnswers.ToList(), drawCount, game); }