public override Thing Clone(WorldSlow world) { return(new Dirt(world) { point = point.Clone() }); }
public override Thing Clone(WorldSlow world) { return(new Butterfly(world) { point = point.Clone(), dir = dir, alive = alive, reached = reached }); }
public override Thing Clone(WorldSlow world) { return(new BrickWall(world) { point = point.Clone() }); }
public override Thing Clone(WorldSlow world) { return(new Player(world) { point = point.Clone(), control = control, alive = alive }); }
public override Thing Clone(WorldSlow world) { return(new Explosion(world) { point = point.Clone(), stage = stage }); }
public override Thing Clone(WorldSlow world) { return(new Diamond(world) { point = point.Clone(), falling = falling }); }
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); }
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(); }
public Thing(WorldSlow world) { this.world = world; //this.point = undefined; this.mark = world.frame; }
public Player(WorldSlow world) : base(world) { }
public BrickWall(WorldSlow world) : base(world) { }
public Butterfly(WorldSlow world) : base(world) { }
public Dirt(WorldSlow world) : base(world) { }
public LooseThing(WorldSlow world) : base(world) { }
public SteelWall(WorldSlow world) : base(world) { }
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); }
public Diamond(WorldSlow world) : base(world) { }
public Boulder(WorldSlow world) : base(world) { }
public Explosion(WorldSlow world) : base(world) { }
} // can walk into? public abstract Thing Clone(WorldSlow world);