Beispiel #1
0
        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++;
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Returns a clone of the current state. I am not sure if this is legal
        /// with the current laws in the US but oh well. Cloning is fun.
        ///
        /// NOTE!: This does not clone the book keeping.
        /// </summary>
        /// <returns>A clone.</returns>
        public override object Clone( )
        {
            GridWorldDynamicState <SS, DS> GS = base.Clone( )
                                                as GridWorldDynamicState <SS, DS>;

            GS.WorldObjects = new HashSet <GridWorldObject <SS, DS> >( );
            GS.BookKeeping  = null;
            foreach (var e in this.WorldObjects)
            {
                GS.WorldObjects.Add(e.Clone( ) as GridWorldObject <SS, DS>);
            }
            return(GS);
        }
Beispiel #3
0
        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( ));
        }
Beispiel #4
0
 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( ));
 }