Beispiel #1
0
        public void SubmitClaim(ClaimsPrincipal user, List <GameCard> claims, List <GameCard> actual)
        {
            lock (gameLogicLock)
            {
                if (!IsCurrentTurn(user))
                {
                    throw new Exception("Somebody may be cheating");
                }
                if (claims.Count != actual.Count)
                {
                    throw new Exception("Somebody may be cheating");
                }
                if (TurnTimer != null)
                {
                    TurnTimer.Stop();
                    TurnTimer.Dispose();
                }

                var referenceCard = claims[0];
                foreach (var card in claims)
                {
                    if (card.Rank != referenceCard.Rank)
                    {
                        throw new Exception("Somebody may be cheating");
                    }
                }

                if (CurrentClaims.Count > 0)
                {
                    if (CurrentClaims.Last().ClaimUser.UserPrincipal.GetUserLoginID() == user.GetUserLoginID())
                    {
                        throw new Exception("Somebody may be cheating");
                    }
                }

                if (CurrentClaims.Count > 0)
                {
                    var recentClaimIndex = GameCard
                                           .Ranks
                                           .FindIndex((item) =>
                    {
                        return(item == CurrentClaims.Last().Claims[0].Rank);
                    });

                    var lowerBoundRank  = GetLowerBoundRank(recentClaimIndex);
                    var upperBoundRank  = GetUpperBoundRank(recentClaimIndex);
                    var middleBoundRank = GetMiddleBoundRank(recentClaimIndex);

                    if (
                        referenceCard.Rank != lowerBoundRank &&
                        referenceCard.Rank != middleBoundRank &&
                        referenceCard.Rank != upperBoundRank)
                    {
                        throw new Exception("Somebody may be cheating");
                    }
                }

                var gameUser = GetPlayer(user);
                CurrentClaims.Add(new GameClaim(claims, actual, gameUser));

                foreach (var card in actual)
                {
                    gameUser.Hand.Remove(card);
                }
                ActionHistory.Add($"{user.GetUserName()} has submitted {claims.Count} cards, with claim {referenceCard.Rank}");
            }
        }