Esempio n. 1
0
        // customize snake from input provider
        private Snake CustomizeSnake()
        {
            // Ask the user to enter a character to use as the snake
            outputProvider.WriteLine(Message.Make_A_Character);
            string snakeHead = inputProvider.Read();
            Snake  newSnake  = new Snake(snakeHead);

            return(newSnake);
        }
Esempio n. 2
0
        public int GetBet(IInputProvider ip)
        {
            int bet = 0;

            int.TryParse(ip.Read().Trim(), out bet);

            bank.Withdraw(bet);

            return(bet);
        }
Esempio n. 3
0
        /// <summary>
        /// Get a move
        /// </summary>
        /// <returns>The move</returns>
        public IMove GetMove()
        {
            // This function should get input from the input provider
            // and create a move from it, returning that move

            // if the input is invalid (can't be parsed into an int, for example),
            // you should throw an InvalidInputException
            Console.WriteLine("Choose a piece to move and give the x coordinate.");
            string _sSourceX = ip.Read();

            Console.WriteLine("Choose a piece to move and give the y coordinate.");
            string _sSourceY = ip.Read();

            Console.WriteLine("Choose an x coordinate to move to.");
            string _sDestX = ip.Read();

            Console.WriteLine("Choose a y coordinate to move to.");
            string _sDestY = ip.Read();

            try
            {
                int sourceX = Convert.ToInt32(_sSourceX);
                int sourceY = Convert.ToInt32(_sSourceY);

                int destX = Convert.ToInt32(_sDestX);
                int destY = Convert.ToInt32(_sDestY);

                var move = new Move
                {
                    Source = new Position(sourceY, sourceX),
                    Dest   = new Position(destY, destX)
                };
                return(move);
            }
            catch (InvalidCastException e)
            {
                Console.WriteLine($"{e.Message}: invalid input.");
                throw new InvalidInputException();
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Implements the IMove interface, returns the player's action
        /// also throws invalid exception if the move cannot be parsed
        /// </summary>
        /// <returns>player's action - hit or stand</returns>
        public PlayerAction GetMove()
        {
            PlayerAction playerAction;
            var          userInput = consoleInputProvider.Read();

            if (Enum.TryParse(userInput, true, out playerAction))
            {
                return(playerAction);
            }
            else
            {
                throw new InvalidInputException();
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Create Players from input provider
        /// </summary>
        private void createPlayersForTable()
        {
            outputProvider.Write("How many players: ");
            var numsPlayer = 1;

            int.TryParse(inputProvider.Read(), out numsPlayer);

            if (numsPlayer <= 0)
            {
                numsPlayer = 1;
                outputProvider.WriteLine();
                outputProvider.WriteLine($"Defaulting to {numsPlayer} players");
            }


            this.players = new List <IPlayer>();
            for (int i = 0; i < numsPlayer; i++)
            {
                var name = GetName();
                this.players.Add(new HumanPlayer(name));
            }

            this.table.Players = this.players as IEnumerable <IPlayer>;
        }