Esempio n. 1
0
        /// <summary>
        /// Retrieves the user's choice in card to lay.
        /// </summary>
        /// <param name="valids"> The list of valid cards to play. </param>
        /// <param name="args"> The current game info. </param>
        /// <returns> The card chosen by the user. </returns>
        protected Card RetrieveInput(List <Card> valids, WhistInfo args)
        {
            do
            {
                // Read the next character entered and reset to new line
                string s = Console.ReadLine();

                // Test if s is a valid number
                int i;
                try
                {
                    i = int.Parse(s.ToString());
                }
                catch
                {
                    this.PrintInputError();
                    continue;
                }

                // Make it the correct index (start at 0 as apposed to 1)
                i--;

                // Test if i is too large or less than 0
                if (i >= valids.Count || i < 0)
                {
                    this.PrintInputError();
                    continue;
                }

                // This will return only if the input is valid
                Console.WriteLine("You Laid: " + valids.ElementAt(i) + "\n");

                return(valids.ElementAt(i));
            }while (true);
        }
Esempio n. 2
0
        /// <summary>
        /// Prints the trumps, laid suit and previous cards laid.
        /// </summary>
        /// <param name="args"> The current game info. </param>
        protected void PrintGameInfo(WhistInfo args)
        {
            Console.WriteLine("Trumps are {0}", args.Trumps);
            Console.WriteLine("Suit laid is {0}", args.FirstSuitLaid);

            Console.Write("Cards laid: ");
            foreach (Card laid in args.CardsInPlay)
            {
                Console.Write(laid.ToUnicodeString() + "  ");
            }

            Console.WriteLine();
        }
Esempio n. 3
0
        /// <summary>
        /// Prints the trumps, laid suit and previous cards laid.
        /// </summary>
        /// <param name="args"> The current game info. </param>
        protected void PrintGameInfo(WhistInfo args)
        {
            Console.WriteLine("Trumps are {0}", args.Trumps);
            Console.WriteLine("Suit laid is {0}", args.FirstSuitLaid);

            Console.Write("Cards laid: ");
            foreach (Card laid in args.CardsInPlay)
            {
                Console.Write(laid.ToUnicodeString() + "  ");
            }

            Console.WriteLine();
        }
Esempio n. 4
0
        /// <summary>
        /// Makes the appropriate move using the given arguments.
        /// </summary>
        /// <param name="args"> The information required to make the move. </param>
        /// <returns> The card chosen. </returns>
        public override Card MakeMove(WhistInfo args)
        {
            // Order the hand
            this.OrderCards();

            // Prints relevant info, eg trumps and first suit laid
            this.PrintGameInfo(args);

            // First evaluates the cards the could be played, then prints the hand with these as selectable
            List<Card> valids = DetectValidCards(args);
            this.PrintHand(valids);

            // Retrieves a card which is returned as the move made
            return this.RetrieveInput(valids, args);
        }
Esempio n. 5
0
        /// <summary>
        /// Makes the appropriate move using the given arguments.
        /// </summary>
        /// <param name="args"> The information required to make the move. </param>
        /// <returns> The card chosen. </returns>
        public override Card MakeMove(WhistInfo args)
        {
            // Order the hand
            this.OrderCards();

            // Prints relevant info, eg trumps and first suit laid
            this.PrintGameInfo(args);

            // First evaluates the cards the could be played, then prints the hand with these as selectable
            List <Card> valids = DetectValidCards(args);

            this.PrintHand(valids);

            // Retrieves a card which is returned as the move made
            return(this.RetrieveInput(valids, args));
        }
        /// <summary>
        /// Retrieves the user's choice in card to lay.
        /// </summary>
        /// <param name="valids"> The list of valid cards to play. </param>
        /// <param name="args"> The current game info. </param>
        /// <returns> The card chosen by the user. </returns>
        protected Card RetrieveInput(List<Card> valids, WhistInfo args)
        {
            do
            {
                // Read the next character entered and reset to new line
                string s = Console.ReadLine();

                // Test if s is a valid number
                int i;
                try
                {
                    i = int.Parse(s.ToString());
                }
                catch
                {
                    this.PrintInputError();
                    continue;
                }

                // Make it the correct index (start at 0 as apposed to 1)
                i--;

                // Test if i is too large or less than 0
                if (i >= valids.Count || i < 0)
                {
                    this.PrintInputError();
                    continue;
                }

                // This will return only if the input is valid
                Console.WriteLine("You Laid: " + valids.ElementAt(i) + "\n");

                return valids.ElementAt(i);
            }
            while (true);
        }