Beispiel #1
0
        public static WorldSlow from_ascii(string[] rows, int frames = 1200, int fps = 10)
        {
            var w = rows[0].Length;
            var h = rows.Length;

            if (w < 3 || h < 3)
            {
                throw new Exception("Cave dimensions are too small");
            }
            var world = new WorldSlow(w, h, frames, fps);

            for (var y = 0; y < h; y++)
            {
                var row = rows[y];
                if (row.Length != w)
                {
                    throw new Exception("All rows must have the same length");
                }
                for (var x = 0; x < w; x++)
                {
                    var c = row[x];
                    if (c != '#' && (x == 0 || x == w - 1 || y == 0 || y == h - 1))
                    {
                        throw new Exception("All cells along the borders must contain #");
                    }
                    var point = new Point(x, y);
                    switch (c)
                    {
                    case ' ': break;

                    case '#': world.set(point, new SteelWall(world)); break;

                    case '+': world.set(point, new BrickWall(world)); break;

                    case ':': world.set(point, new Dirt(world)); break;

                    case 'O': world.set(point, new Boulder(world)); break;

                    case '*': world.set(point, new Diamond(world)); break;

                    case '-':
                    case '/':
                    case '|':
                    case '\\':
                        world.set(point, new Butterfly(world));
                        break;

                    case 'A':
                        if (world.player.point != null)
                        {
                            throw new Exception("More than one player position found");
                        }
                        world.set(point, world.player);
                        break;

                    default:
                        throw new Exception("Unknown character: " + c);
                    }
                }
            }
            if (world.player.point == null)
            {
                throw new Exception("Player position not found");
            }
            return(world);
        }