Example #1
0
 public TileMap(MapSize mapSize)
 {
     Size = mapSize;
 }
Example #2
0
        //
        // Souhrn:
        //  Vrátí velikost mapy podle toho, co vybral nebo vybere uživatel.
        //
        private MapSize getMapSizeFromInput(ConsoleKeyInfo readKey)
        {
            MapSize size;

            switch (readKey.Key)
            {
            case ConsoleKey.NumPad1:
            {
                size = new MapSize(10, 10);
                break;
            }

            case ConsoleKey.NumPad2:
            {
                size = new MapSize(15, 15);
                break;
            }

            case ConsoleKey.NumPad3:
            {
                size = new MapSize(20, 20);
                break;
            }

            case ConsoleKey.NumPad4:
            {
                int width;
                int height;
                Console.Clear();
                while (true)
                {
                    Console.Write("Select width: ");
                    var pickWidth = Console.ReadLine();

                    if (!int.TryParse(pickWidth, out width))
                    {
                        Console.Clear();
                        Console.WriteLine("You didn't write a number");
                        continue;
                    }
                    else if (width == 1)
                    {
                        Console.Clear();
                        Console.WriteLine("Number must be at least 2 or more");
                        continue;
                    }
                    else
                    {
                        break;
                    }
                }

                Console.Clear();
                while (true)
                {
                    Console.Write("Select height: ");
                    var pickHeight = Console.ReadLine();

                    if (!int.TryParse(pickHeight, out height))
                    {
                        Console.Clear();
                        Console.WriteLine("You didn't write a number");
                        continue;
                    }
                    else if (width == 1)
                    {
                        Console.Clear();
                        Console.WriteLine("Number must be at least 2 or more");
                        continue;
                    }
                    else
                    {
                        break;
                    }
                }

                size = new MapSize(width, height);
                break;
            }

            default:
                return(null);
            }
            return(size);
        }