예제 #1
0
        public static SnakeMap CreateDefaultMap(int Width, int Height)
        {
            string BlankLevel = "Blank level | 8 | Right | Left\n";

            for (int i = 0; i < Height; i++)
            {
                for (int j = 0; j < Width; j++)
                {
                    if (new int[] { 0, Height - 1 }.Contains(i) || new int[] { 0, Width - 1 }.Contains(j))
                    {
                        BlankLevel += "%"; continue;
                    }
                    BlankLevel += (i == Height / 2 ? (j == 10 ? "1" : (j == Width - 11 ? "2" : " ")) : " ");
                }
                BlankLevel += "\n";
            }
            return(SnakeMap.Parse(BlankLevel, Width, Height));
        }
예제 #2
0
        static void LoadLevel(string F)
        {
            string   Input = "";
            SnakeMap LoadedMap;

            Console.WriteLine("Loading map " + F + "...");
            try { Input = File.ReadAllText(F); }
            catch
            {
                Console.WriteLine("Could not load " + F + ". Make sure the file exists and it is readable.");
                throw new Exception();
            }
            try { LoadedMap = SnakeMap.Parse(Input, SnakeGame.FieldWidth, SnakeGame.FieldHeight); }
            catch
            {
                Console.WriteLine("The map " + F + " contains errors. Fix them and try again.");
                throw new Exception();
            }
            Console.WriteLine("Map loaded successfully.");
            Map = LoadedMap;
        }