Exemple #1
0
 public override Thing Clone(WorldSlow world)
 {
     return(new Dirt(world)
     {
         point = point.Clone()
     });
 }
Exemple #2
0
 public override Thing Clone(WorldSlow world)
 {
     return(new Butterfly(world)
     {
         point = point.Clone(), dir = dir, alive = alive, reached = reached
     });
 }
Exemple #3
0
 public override Thing Clone(WorldSlow world)
 {
     return(new BrickWall(world)
     {
         point = point.Clone()
     });
 }
Exemple #4
0
 public override Thing Clone(WorldSlow world)
 {
     return(new Player(world)
     {
         point = point.Clone(), control = control, alive = alive
     });
 }
Exemple #5
0
 public override Thing Clone(WorldSlow world)
 {
     return(new Explosion(world)
     {
         point = point.Clone(), stage = stage
     });
 }
Exemple #6
0
 public override Thing Clone(WorldSlow world)
 {
     return(new Diamond(world)
     {
         point = point.Clone(), falling = falling
     });
 }
Exemple #7
0
        public static IDictionary <char, int> scan_reachable(WorldSlow world, Point start, string allowed)
        {
            //var res = {};
            var res     = new Dictionary <char, int>();
            var seen    = new HashSet <Point>();
            var pending = new Queue <Point>();

            pending.Enqueue(start);
            seen.Add(start);
            while (pending.Count != 0)
            {
                var point = pending.Dequeue();
                for (var i = 0; i < 4; i++)
                {
                    var neighbor = point.step((Dir)i);
                    if (seen.Contains(neighbor))
                    {
                        continue;
                    }
                    seen.Add(neighbor);
                    var cell = world.get(neighbor);
                    var c    = cell != null?cell.get_char() : ' ';

                    if (c == '-' || c == '\\' || c == '|')
                    {
                        c = '/';
                    }
                    if (res.ContainsKey(c))// (res[c])
                    {
                        res[c]++;
                    }
                    else
                    {
                        res[c] = 1;
                    }
                    if (allowed.Contains(c))
                    {
                        pending.Enqueue(neighbor);
                    }
                }
            }
            return(res);
        }
Exemple #8
0
        private WorldSlow(WorldSlow world)
        {
            this.frame       = world.frame;
            this.width       = world.width;
            this.height      = world.height;
            this.frames_left = world.frames_left;
            this.fps         = world.fps;
            //this.butterflies_killed = world.butterflies_killed;
            this.diamonds_collected = world.diamonds_collected;
            this.longest_streak     = world.longest_streak;
            this.scored_expiry      = world.scored_expiry;
            this.score         = world.score;
            this.settled       = world.settled;
            this.streak        = world.streak;
            this.streak_expiry = world.streak_expiry;
            this.streaks       = world.streaks;
            //this.player = new Player(this);
            this.cells = new Thing[height, width];
            var list = new List <Butterfly>();

            for (var y = 0; y < height; y++)
            {
                for (var x = 0; x < width; x++)
                {
                    var cell = world.cells[y, x];
                    if (cell != null)
                    {
                        var thing = this.cells[y, x] = cell.Clone(this);
                        if (thing is Player)
                        {
                            this.player = thing as Player;
                        }
                        else if (thing is Butterfly)
                        {
                            list.Add(thing as Butterfly);
                        }
                    }
                }
            }
            this.butterflies = list.ToArray();
        }
Exemple #9
0
 public Thing(WorldSlow world)
 {
     this.world = world;
     //this.point = undefined;
     this.mark = world.frame;
 }
Exemple #10
0
 public Player(WorldSlow world) : base(world)
 {
 }
Exemple #11
0
 public BrickWall(WorldSlow world) : base(world)
 {
 }
Exemple #12
0
 public Butterfly(WorldSlow world) : base(world)
 {
 }
Exemple #13
0
 public Dirt(WorldSlow world) : base(world)
 {
 }
Exemple #14
0
 public LooseThing(WorldSlow world) : base(world)
 {
 }
Exemple #15
0
 public SteelWall(WorldSlow world) : base(world)
 {
 }
Exemple #16
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);
        }
Exemple #17
0
 public Diamond(WorldSlow world) : base(world)
 {
 }
Exemple #18
0
 public Boulder(WorldSlow world) : base(world)
 {
 }
Exemple #19
0
 public Explosion(WorldSlow world) : base(world)
 {
 }
Exemple #20
0
        }                                                        // can walk into?

        public abstract Thing Clone(WorldSlow world);