Esempio n. 1
0
        public bool ValidateMove(string move)
        {
            if (move.Contains("play"))
            {
                string[]   tokens = move.Split(' ');
                int        h      = Int32.Parse(tokens[1]);
                int        n      = Int32.Parse(tokens[2]);
                CaravanRow row    = gameBoard.GetCaravan(n);
                Card       card   = myPlayer.CardAt(h);

                if (tokens.Length == 4)
                {
                    int c = Int32.Parse(tokens[3]);

                    if (card.GetRank() == Rank.Queen)
                    {
                        if (row.GetSize() != c)
                        {
                            Console.WriteLine("Must play queen on last card.");
                            return(false);
                        }
                    }

                    if (row.GetNumFaceCardsAt(c) >= 3)
                    {
                        Console.WriteLine("Cannot attach more than 3 face cards to a number card");
                    }
                    return(row.GetNumFaceCardsAt(c) < 3);
                }

                else if (tokens.Length == 3)
                {
                    if (row.GetSize() == 0)
                    {
                        return(true);
                    }

                    if (card.GetRank() != row.GetEnd().GetRank() && card.GetSuite() == row.GetEnd().GetSuite())
                    {
                        if (row.IsIncreasing() && card.GetValue() < row.GetEnd().GetValue())
                        {
                            row.FlipIncreasing();
                        }

                        else if (!row.IsIncreasing() && card.GetValue() > row.GetEnd().GetValue())
                        {
                            row.FlipIncreasing();
                        }
                        return(true);
                    }

                    if (row.GetEnd().GetRank() == card.GetRank())
                    {
                        Console.WriteLine("Cannot play same card value twice in a row");
                        return(false);
                    }

                    if (row.GetSize() == 1)
                    {
                        if (row.IsIncreasing() && card.GetValue() < row.GetEnd().GetValue())
                        {
                            row.FlipIncreasing();
                        }

                        else if (!row.IsIncreasing() && card.GetValue() > row.GetEnd().GetValue())
                        {
                            row.FlipIncreasing();
                        }
                        return(true);
                    }

                    if (row.IsIncreasing())
                    {
                        if (card.GetValue() > row.GetEnd().GetValue())
                        {
                            return(true);
                        }

                        Console.WriteLine("Cannot play card of lower value");
                        return(false);
                    }

                    else
                    {
                        if (card.GetValue() < row.GetEnd().GetValue())
                        {
                            return(true);
                        }

                        Console.WriteLine("Cannot play card of higher value");
                        return(false);
                    }
                }
            }

            return(move.Contains("discard") || move.Contains("reset") || move == "give up");
        }
Esempio n. 2
0
        public string GetMove()
        {
            string move = "";
            string temp = "";
            bool   done = false;

            List <Card> hand = myPlayer.GetHand();

            while (!done)
            {
                move = "";
                Console.WriteLine("Would you like to 'play' a card, 'discard' a card, 'reset' a caravan, or 'give up'?");
                temp = Console.ReadLine();

                if (temp == "give up")
                {
                    return(temp);
                }

                else if (temp == "play")
                {
                    move += temp;
                    ClearLastLine();
                    Console.WriteLine("Choose a card from your hand to play or enter cancel");
                    temp = GetNumber(hand.Count);
                    if (temp == "cancel")
                    {
                        ClearLastLine(); continue;
                    }
                    move += " " + temp;
                    int  n = Int32.Parse(temp);
                    Card c = hand[n - 1];

                    if (c.GetValue() > 10)
                    {
                        ClearLastLine();
                        ClearLastLine();
                        Console.WriteLine("Choose a caravan between 1-6 (4-6 are your opponent's) or enter cancel");
                        temp = GetNumber(6);
                        if (temp == "cancel")
                        {
                            ClearLastLine(); continue;
                        }
                        move += " " + temp;

                        ClearLastLine();
                        ClearLastLine();
                        Console.WriteLine("Choose a card in caravan " + temp + " or enter cancel");
                        int        r   = Int32.Parse(temp);
                        CaravanRow row = gameBoard.GetCaravan(r);
                        temp = GetNumber(row.GetSize());
                        if (temp == "cancel")
                        {
                            ClearLastLine(); continue;
                        }
                        move += " " + temp;
                        return(move);
                    }

                    else
                    {
                        ClearLastLine();
                        ClearLastLine();
                        Console.WriteLine("Choose a caravan between 1-3 or enter cancel");
                        temp = GetNumber(3);
                        if (temp == "cancel")
                        {
                            ClearLastLine(); continue;
                        }
                        move += " " + temp;
                        return(move);
                    }
                }

                else if (temp == "discard")
                {
                    move += temp;
                    ClearLastLine();
                    Console.WriteLine("Choose a card from your hand to discard or enter cancel");
                    temp = GetNumber(hand.Count);
                    if (temp == "cancel")
                    {
                        ClearLastLine();  continue;
                    }
                    move += " " + temp;
                    return(move);
                }

                else if (temp == "reset")
                {
                    move += temp;
                    ClearLastLine();
                    Console.WriteLine("Which caravan would you like to reset? Cancel action with 'cancel'");
                    temp = GetNumber(3);
                    if (temp == "cancel")
                    {
                        ClearLastLine(); continue;
                    }
                    move += " " + temp;
                    return(move);
                }

                else
                {
                    ClearLastLine();
                    Console.WriteLine("Invalid command");
                    continue;
                }
            }

            return(move);
        }