コード例 #1
0
ファイル: Program.cs プロジェクト: greenpenguin/XT_Q2
        public static void Main(string[] args)
        {
            WorkWithConsoleClass workWithConsoleClass = new WorkWithConsoleClass();

            RoundClass round = new RoundClass(workWithConsoleClass.Input());

            workWithConsoleClass.Output(round.GetAreaOfRound(), round.GetLengthOfRound());
        }
コード例 #2
0
        protected override Task StartSetUpAsync(bool isBeginning)
        {
            LoadControls();
            PlayerList !.ForEach(thisPlayer => thisPlayer.TotalScore = 0);
            _wasNew        = false;
            WasGuarantee   = false;
            CardForDiscard = null;
            CustomBasicList <RoundClass> tempList = new CustomBasicList <RoundClass>();
            RoundClass thisRound = new RoundClass();

            thisRound.Description = "Round 1:  Same Color";
            thisRound.Category    = EnumCategory.Colors;
            thisRound.Rummy       = EnumRummyType.Regular;
            thisRound.Points      = 1;
            tempList.Add(thisRound);
            thisRound             = new RoundClass();
            thisRound.Description = "Round 2:  Same Shape";
            thisRound.Category    = EnumCategory.Shapes;
            thisRound.Rummy       = EnumRummyType.Regular;
            thisRound.Points      = 2;
            tempList.Add(thisRound);
            thisRound             = new RoundClass();
            thisRound.Description = "Round 3:  Same Shape And Color";
            thisRound.Category    = EnumCategory.Both;
            thisRound.Rummy       = EnumRummyType.Regular;
            thisRound.Points      = 3;
            tempList.Add(thisRound);
            thisRound             = new RoundClass();
            thisRound.Description = "Round 4:  Straight";
            thisRound.Category    = EnumCategory.None;
            thisRound.Rummy       = EnumRummyType.Straight;
            thisRound.Points      = 4;
            tempList.Add(thisRound);
            thisRound             = new RoundClass();
            thisRound.Description = "Round 5:  Straight Same Color";
            thisRound.Category    = EnumCategory.Colors;
            thisRound.Rummy       = EnumRummyType.Straight;
            thisRound.Points      = 5;
            tempList.Add(thisRound);
            thisRound             = new RoundClass();
            thisRound.Description = "Round 6:  Straight Same Shape";
            thisRound.Category    = EnumCategory.Shapes;
            thisRound.Rummy       = EnumRummyType.Straight;
            thisRound.Points      = 6;
            tempList.Add(thisRound);
            thisRound             = new RoundClass();
            thisRound.Description = "Round 7:  Straight Same Shape And Color";
            thisRound.Category    = EnumCategory.Both;
            thisRound.Rummy       = EnumRummyType.Straight;
            thisRound.Points      = 7;
            tempList.Add(thisRound);
            thisRound             = new RoundClass();
            thisRound.Description = "Round 8:  Same Number";
            thisRound.Category    = EnumCategory.None;
            thisRound.Rummy       = EnumRummyType.Kinds;
            thisRound.Points      = 8;
            tempList.Add(thisRound);
            if (Test !.DoubleCheck)
            {
                tempList.KeepConditionalItems(items => items.Points >= 4);
            }
            SaveRoot !.RoundList.ReplaceRange(tempList); //i think.
            return(base.StartSetUpAsync(isBeginning));
        }
コード例 #3
0
        public static bool HasRummy(this IDeckDict <A8RoundRummyCardInformation> cardList, A8RoundRummyMainGameClass mainGame) //you have to send one more argument
        {
            if (cardList.Count != 8)
            {
                throw new BasicBlankException("Must have 8 cards in order to have the rummy");
            }
            mainGame.LastCard       = null;
            mainGame.LastSuccessful = false;
            RoundClass    currentRound = mainGame.SaveRoot !.RoundList.First();
            int           wilds        = cardList.Count(Items => Items.CardType == EnumCardType.Wild);
            int           reverses     = cardList.Count(Items => Items.CardType == EnumCardType.Reverse);
            EnumCardShape shapeUsed;
            EnumColor     colorUsed;

            if (reverses > 1)
            {
                return(false); //can't have more than one reverse in your hand.
            }
            if (currentRound.Category == EnumCategory.Colors && currentRound.Rummy == EnumRummyType.Regular)
            {
                var blueList = cardList.Where(Items => Items.Color == EnumColor.Blue || Items.CardType == EnumCardType.Wild).Take(7).ToRegularDeckDict();
                var redList  = cardList.Where(Items => Items.Color == EnumColor.Red || Items.CardType == EnumCardType.Wild).Take(7).ToRegularDeckDict();
                if (blueList.Count < 7 && redList.Count < 7) //has to be and, not or.
                {
                    return(false);
                }
                mainGame.LastSuccessful = true;
                if (blueList.Count == 7)
                {
                    mainGame.LastCard = cardList.GetLastCard(blueList);
                }
                else
                {
                    mainGame.LastCard = cardList.GetLastCard(redList);
                }
                return(true);
            }
            DeckRegularDict <A8RoundRummyCardInformation> tempList;

            if (currentRound.Category == EnumCategory.Shapes && currentRound.Rummy == EnumRummyType.Regular)
            {
                var firstList = cardList.Where(Items => Items.CardType == EnumCardType.Regular).GroupBy(Items => Items.Shape).ToCustomBasicList();
                if (firstList.Count > 2)
                {
                    return(false);
                }
                if (firstList.Count > 1 && reverses > 0)
                {
                    return(false);
                }
                if (firstList.Count > 1)
                {
                    if (firstList.First().Count() > 1 && firstList.Last().Count() > 1)
                    {
                        return(false);
                    }
                    if (firstList.First().Count() > 1)
                    {
                        shapeUsed = firstList.First().Key;
                    }
                    else
                    {
                        shapeUsed = firstList.Last().Key;
                    }
                }
                else
                {
                    shapeUsed = firstList.First().Key;
                }
                tempList = cardList.Where(Items => Items.Shape == shapeUsed || Items.CardType == EnumCardType.Wild).Take(7).ToRegularDeckDict();
                mainGame.LastSuccessful = true;
                mainGame.LastCard       = cardList.GetLastCard(tempList);
                return(true);
            }
            if (currentRound.Category == EnumCategory.Both && currentRound.Rummy == EnumRummyType.Regular)
            {
                var firstList = cardList.Where(Items => Items.CardType == EnumCardType.Regular).GroupBy(Items => new { Items.Color, Items.Shape }).ToCustomBasicList(); //iffy
                if (firstList.Count > 2)
                {
                    return(false);
                }
                if (firstList.Count > 1 && reverses > 0)
                {
                    return(false);
                }
                if (firstList.Count > 1)
                {
                    if (firstList.First().Count() > 1 && firstList.Last().Count() > 1)
                    {
                        return(false);
                    }
                    if (firstList.First().Count() > 1)
                    {
                        shapeUsed = firstList.First().Key.Shape;
                        colorUsed = firstList.First().Key.Color;
                    }
                    else
                    {
                        shapeUsed = firstList.Last().Key.Shape;
                        colorUsed = firstList.Last().Key.Color;
                    }
                }
                else
                {
                    shapeUsed = firstList.First().Key.Shape;
                    colorUsed = firstList.First().Key.Color;
                }
                tempList = cardList.Where(Items => Items.CardType == EnumCardType.Wild || (Items.Color == colorUsed && Items.Shape == shapeUsed)).Take(7).ToRegularDeckDict();
                mainGame.LastSuccessful = true;
                mainGame.LastCard       = cardList.GetLastCard(tempList);
                return(true);
            }
            if (currentRound.Rummy == EnumRummyType.Kinds)
            {
                var firstList = cardList.Where(Items => Items.CardType == EnumCardType.Regular).GroupBy(Items => Items.Value).ToCustomBasicList();
                int numberUsed;
                if (firstList.Count > 2)
                {
                    return(false);
                }
                if (firstList.Count > 1 && reverses > 0)
                {
                    return(false);
                }
                if (firstList.Count > 1)
                {
                    if (firstList.First().Count() > 1 && firstList.Last().Count() > 1)
                    {
                        return(false);
                    }
                    if (firstList.First().Count() > 1)
                    {
                        numberUsed = firstList.First().Key;
                    }
                    else
                    {
                        numberUsed = firstList.Last().Key;
                    }
                }
                else
                {
                    numberUsed = firstList.First().Key;
                }
                tempList = cardList.Where(Items => Items.Value == numberUsed || Items.CardType == EnumCardType.Wild).Take(7).ToRegularDeckDict();
                mainGame.LastSuccessful = true;
                mainGame.LastCard       = cardList.GetLastCard(tempList);
                return(true);
            }
            if (currentRound.Rummy != EnumRummyType.Straight)
            {
                throw new BasicBlankException("Not Supported");
            }
            var straightList = cardList.Where(Items => Items.CardType == EnumCardType.Regular).OrderBy(Items => Items.Value).ToRegularDeckDict();

            switch (currentRound.Category)
            {
            case EnumCategory.None:
                var nexts   = straightList.GroupBy(Items => Items.Value).ToCustomBasicList();
                var finList = nexts.Where(Items => Items.Count() > 1).ToCustomBasicList();
                if (finList.Count == 0)
                {
                    tempList = cardList.Where(Items => Items.CardType != EnumCardType.Reverse).Take(7).ToRegularDeckDict();
                    mainGame.LastSuccessful = true;
                    mainGame.LastCard       = cardList.GetLastCard(tempList);
                    return(true);
                }
                if (reverses == 1)
                {
                    return(false);
                }
                if (finList.Count > 1)
                {
                    return(false);
                }
                mainGame.LastSuccessful = true;
                mainGame.LastCard       = finList.Single().First(); //hopefully can take the first one.
                return(true);

            case EnumCategory.Colors:
                return(cardList.IsStraightColorOnly(straightList, mainGame, reverses));

            case EnumCategory.Shapes:
                return(cardList.IsStraightShapeOnly(straightList, mainGame, reverses));

            case EnumCategory.Both:
                return(cardList.IsStraightBoth(straightList, mainGame, reverses));

            default:
                throw new BasicBlankException("Not Supported");
            }
        }