コード例 #1
0
    public static void Main(string[] args)
    {
        // Clear the screen, then save the top and left coordinates.
        Console.Clear();
        origRow = Console.CursorTop;
        origCol = Console.CursorLeft;

        // set the default floor size
        int rows = 20;
        int cols = 18;

        //create a default constructor b/c there are no args being passed in
        if (args.Length > 1)
        {
            try
            {
                rows = Int32.Parse(args[0]);
                cols = Int32.Parse(args[1]);
            }
            catch (Exception) {
                Console.Beep();
                Console.WriteLine("Useage example: RobotRat 20 20");
                Console.WriteLine("Creating Robot Rat with default floor dimensions.");
                Console.WriteLine("Press any key to continue.");
                Console.ReadLine();
            }
        }
        RobotRat rat = new RobotRat(rows, cols);

        rat.Go();
    } //end main
コード例 #2
0
    /// <summary>
    /// The RobotRat's Main method.
    /// </summary>
    /// <param name="args"></param>
    public static void Main(String[] args)
    {
        int rows = 20;
        int cols = 20;

        try {
            switch (args.Length)
            {
            case 0: break;

            case 1: rows = Int32.Parse(args[0]);
                rows     = (rows < 0) ? (rows *= -1) : rows;                                              // convert negative numbers
                rows     = (rows == 0) ? (rows += 5) : rows;                                              // limit min value to 5
                rows     = (rows > 50) ? (rows = 50) : rows;                                              // limit max value to 50
                cols     = rows;
                break;

            case 2: rows = Int32.Parse(args[0]);
                cols     = Int32.Parse(args[1]);
                rows     = (rows < 0) ? (rows *= -1) : rows;                                              // convert negative numbers
                rows     = (rows == 0) ? (rows += 5) : rows;                                              // limit min value to 5
                rows     = (rows > 50) ? (rows = 50) : rows;                                              // limit max value to 50
                cols     = (cols < 0) ? (cols *= -1) : cols;                                              // convert negative numbers
                cols     = (cols == 0) ? (cols += 5) : cols;                                              // limit min value to 5
                cols     = (cols > 50) ? (cols = 50) : cols;                                              // limit max value to 50
                break;

            default:        break;
            }
            RobotRat rr = new RobotRat(rows, cols);
            Console.Clear();
            rr.Run();
        }catch (FormatException) {
            Console.WriteLine("Invalid number! Please enter a valid integer value!");
        }catch (OverflowException) {
            Console.WriteLine("Please enter an integer value between: {0} and {1}", 5, 50);
        }
    }
コード例 #3
0
    public static void Main(String[] args)
    {
        RobotRat rr = new RobotRat(22, 20);

        rr.Run();
    }
コード例 #4
0
 public static void Main(String[] args)
 {
     RobotRat rr = new RobotRat();
 }