Beispiel #1
0
        public UnoCard(UnoCardColor color, int rank)
            : this(color)
        {
            Rank = rank;

            if (rank > -1)
            {
                Weight = rank;
            }
        }
Beispiel #2
0
        public UnoCard(UnoCardColor color, UnoCardAction action)
            : this(color, -1)
        {
            Action = action;

            switch (action)
            {
            case UnoCardAction.DrawTwo:
            case UnoCardAction.Reverse:
            case UnoCardAction.Skip:
                Weight = 20;
                break;

            case UnoCardAction.Wild:
            case UnoCardAction.WildDraw4:
                Weight = 50;
                break;
            }
        }
Beispiel #3
0
 public UnoCard(UnoCardColor Color, UnoCardType Type)
 {
     this.Color = Color;
     this.Type  = Type;
 }
Beispiel #4
0
        public MoveStatus Move(
            List <UnoCard> cards,
            UnoCardColor color,
            IdentityContext context)
        {
            DbMatch       dbMatch = context.Matches.Where(x => x.Id == Id).FirstOrDefault();
            List <DbHand> hands   = context.Hands.Where(x => x.Match.Id == Id).ToList();

            if (dbMatch == null)
            {
                return(MoveStatus.WRONG_MOVE);
            }

            User player;

            if (cards.Count == 0)
            {
                bool hasMove = false;

                foreach (var card in Hands[CurrentPlayer])
                {
                    //hasMove = hasMove || ValidateMove(new List<UnoCard> { card });
                }

                if (hasMove)
                {
                    return(MoveStatus.FAKE_EMPTY_MOVE);
                }
                else
                {
                    TakeCard(CurrentPlayer, dbMatch, hands);
                    CurrentPlayer         = NextPlayer();
                    player                = context.Users.Where(x => x.ExternalId == CurrentPlayer).FirstOrDefault();
                    dbMatch.CurrentPlayer = player;
                    return(MoveStatus.SUCCESS);
                }
            }

            if (!ValidateMove(cards))
            {
                return(MoveStatus.WRONG_MOVE);
            }

            UnoMatchMove move = new UnoMatchMove
            {
                DeckCard     = GetCurrentCard(),
                PlayerId     = CurrentPlayer,
                Move         = cards,
                SelecteColor = color
            };

            Backlog.Add(move);
            dbMatch.Backlog.Add(move);

            DbHand currentPlayerHand = hands.Where(x => x.User.ExternalId == CurrentPlayer).FirstOrDefault();

            if (currentPlayerHand == null)
            {
                return(MoveStatus.WRONG_MOVE);
            }

            cards.ForEach(card => {
                Hands[CurrentPlayer].Remove(card);
                var dbCard = currentPlayerHand
                             .Hand
                             .Where(x => x.Color == card.Color && x.NumberValue == card.NumberValue && x.Type == card.Type)
                             .FirstOrDefault();
                currentPlayerHand.Hand.Remove(dbCard);
            });

            if (Hands[CurrentPlayer].Count == 0)
            {
                return(MoveStatus.ENDGAME);
            }

            cards.ForEach(card => {
                Discharge.Add(card);
                dbMatch.Discharge.Add(card);
            });

            switch (GetCurrentCard().Type)
            {
            case UnoCardType.Numeric:
                CurrentPlayer = NextPlayer();
                break;

            case UnoCardType.Reverse:
            case UnoCardType.Skip:
                break;

            case UnoCardType.TakeTwo:
                TakeCard(NextPlayer(), dbMatch, hands);
                TakeCard(NextPlayer(), dbMatch, hands);
                break;

            case UnoCardType.TakeFourChooseColor:
                for (var i = 0; i < 4; i++)
                {
                    TakeCard(NextPlayer(), dbMatch, hands);
                }
                CurrentColor = color;
                break;

            case UnoCardType.ChooseColor:
                CurrentColor  = color;
                CurrentPlayer = NextPlayer();
                break;
            }


            player = context.Users.Where(x => x.ExternalId == CurrentPlayer).FirstOrDefault();
            dbMatch.CurrentPlayer = player;
            dbMatch.CurrentColor  = color;

            return(MoveStatus.SUCCESS);
        }
Beispiel #5
0
 private UnoCard(UnoCardColor color)
 {
     Color = color;
 }