예제 #1
0
        public Coordinate TakeTurn()
        {
            while (true)
            {
                _readerWriter.Write(Symbol + " Enter a coord x,y: ");
                var userSpecifiedCoord = _readerWriter.ReadLine();
                var coordArray         = userSpecifiedCoord.Split(",");

                if (coordArray.Length != 2)
                {
                    _readerWriter.Write("Invalid input. Please try again.");
                    continue;
                }

                var ifXIsNumber = int.TryParse(coordArray[0], out var xValue);
                var ifYIsNumber = int.TryParse(coordArray[1], out var yValue);

                if (ifXIsNumber && ifYIsNumber)
                {
                    return new Coordinate
                           {
                               X = xValue,
                               Y = yValue
                           }
                }
                ;
            }
        }
    }
 private List <Product> ProductQuantitySet(List <Product> products)
 {
     for (int i = 0; i < products.Count; i++)
     {
         _console.Write(string.Format("Enter quantity of product {0}", products[i].ProductName));
         int quantity = 0;
         int.TryParse(_console.ReadLine(), out quantity);
         products[i].Quantity = quantity < 0?0:quantity;
     }
     return(products);
 }
예제 #3
0
    public void Run()
    {
        var input = "";
        var sb    = new StringBuilder();

        while ((input = readerWriter.ReadLine().Trim()) != "Shutdown")
        {
            var commandResult = this.commandInterpreter.ProcessCommand(input.Split());

            sb.AppendLine(commandResult);
        }

        var lastCommand = this.commandInterpreter.ProcessCommand(input.Split());

        sb.Append(lastCommand);

        readerWriter.WriteLine(sb.ToString());
    }
예제 #4
0
 private void setNumberOfRecords(IReaderWriter readerWriter)
 {
     var value = readerWriter.ReadLine().Trim();
     value = Regex.Replace(value, "[^0-9]", "", RegexOptions.None);
     this.numberOfRecords = int.Parse(value);
 }