public static void FromTileStream(TextReader Stream, GridWorldStaticState <GenericGridWorldStaticState, GenericGridWorldDynamicState> ss, GridWorldDynamicState <GenericGridWorldStaticState, GenericGridWorldDynamicState> ds, List <Unit> Units) { string line; for (int y = 0; ss.Height > y && (line = Stream.ReadLine( )) != null; y++) { if (line.Length != ss.Width) { System.Console.WriteLine(line.Length); System.Console.WriteLine(line); throw new FormatException( "Stream Load Failed, Invalid Grid Format"); } int x = 0; foreach (char c in line) { switch (c) { case (char)GridWorldFormat.TileKind.UNIT: Unit d = Units.First(v => v.X == x && v.Y == y); ds.AddWorldObject(d); goto case (char)GridWorldFormat.TileKind.BLANK; case (char)GridWorldFormat.TileKind.CHOKEUNIT: d = Units.First(v => v.X == x && v.Y == y); ds.AddWorldObject(d); goto case (char)GridWorldFormat.TileKind.CHOKE; case (char)GridWorldFormat.TileKind.CHOKE: ss.Tiles[y][x] = new ChokeTile <GenericGridWorldStaticState, GenericGridWorldDynamicState>(x, y, ss.Height, ss.Width); break; case (char)GridWorldFormat.TileKind.BLANK: case ' ': ss.Tiles[y][x] = new PassableTile <GenericGridWorldStaticState, GenericGridWorldDynamicState>(x, y, ss.Height, ss.Width); break; case (char)GridWorldFormat.TileKind.BLOCKED: ss.Tiles[y][x] = new BlockedTile <GenericGridWorldStaticState, GenericGridWorldDynamicState>(x, y, ss.Height, ss.Width); break; default: throw new FormatException( "Stream Load Failed, Invalid Grid " + "Format, Unknown Title Type [" + c + "]"); } x++; } } }
public static string ToFileString(GridWorldStaticState < GenericGridWorldStaticState, GenericGridWorldDynamicState> GridWorldStaticState, GridWorldDynamicState <GenericGridWorldStaticState, GenericGridWorldDynamicState> GridWorldDynamicState) { Unit U = GridWorldDynamicState.FindUnit(0); System.Text.StringBuilder sb = new System.Text.StringBuilder( ); sb.AppendLine(GridWorldStaticState.Width.ToString( )); sb.AppendLine(GridWorldStaticState.Height.ToString( )); sb.AppendLine(U.X + " " + U.Y + " " + U.DstX + " " + U.DstY); sb.AppendLine("--- end units ---"); sb.Append(ToTileString(GridWorldStaticState, GridWorldDynamicState)); return(sb.ToString( )); }
public static string ToTileString(GridWorldStaticState < GenericGridWorldStaticState, GenericGridWorldDynamicState> GridWorldStaticState, GridWorldDynamicState <GenericGridWorldStaticState, GenericGridWorldDynamicState> GridWorldDynamicState) { System.Text.StringBuilder sb = new System.Text.StringBuilder( ); for (int i = 0; i < GridWorldStaticState.Tiles.Length; i++) { foreach (var x in GridWorldStaticState.Tiles[i]) { sb.Append(GetAscii(x, GridWorldDynamicState. GetWorldObjects( ))); } sb.AppendLine( ); } return(sb.ToString( )); }