Пример #1
0
        public bool Play(bool print)
        {
            // Take the first card on the top left
            Hand          = Side.First();
            Hand.FacingUp = true;
            Side.RemoveAt(0);

            while (!Finished)
            {
                // If we find the same value
                for (var i = 0; i < Columns; i++)
                {
                    if (Table[i, 0].Value == Hand.Value && Table[i, 0].FacingUp)
                    {
                        for (var j = 0; j < 4; j++)
                        {
                            if (!Table[i, j].FacingUp)
                            {
                                var temp = Table[i, j];
                                Table[i, j]   = Hand;
                                Hand          = temp;
                                Hand.FacingUp = true;
                                goto PRINT;
                            }
                        }
                    }
                }

                // If we find a card facing down in the top place of the column
                for (var i = 0; i < Columns; i++)
                {
                    if (!Table[i, 0].FacingUp)
                    {
                        var temp = Table[i, 0];
                        Table[i, 0]   = Hand;
                        Hand          = temp;
                        Hand.FacingUp = true;
                        goto PRINT;
                    }
                }

                foreach (Card card in Side)
                {
                    if (!card.FacingUp)
                    {
                        var temp = card;
                        Side.Remove(card);
                        Side.Add(Hand);
                        Hand          = temp;
                        Hand.FacingUp = true;
                        goto PRINT;
                    }
                }

                // We reach here if it's the end of the game and we have to put our hand card in the Side column
                Side.Add(Hand);
                Hand = null;

PRINT:
                if (print)
                {
                    PrintTable();
                    Thread.Sleep(500);
                }
            }

            for (var i = 0; i < Columns; i++)
            {
                for (var j = 0; j < 4; j++)
                {
                    if (!Table[i, j].FacingUp)
                    {
                        Table[i, j].FacingUp = true;
                    }
                }
            }

            if (print)
            {
                PrintTable();
            }

            return(Won);
        }