コード例 #1
0
        /// <summary>
        /// The load method to parse the file format. This will throw a format
        /// exception if it fails.
        /// </summary>
        /// <param name="Stream">The stream to parse from.</param>
        /// <returns>The grid world.</returns>
        public override void Load(System.IO.TextReader Stream,
                                  out GenericGridWorldStaticState StaticState,
                                  out GenericGridWorldDynamicState DynamicState)
        {
            // First and Second lines of input are grid dimensions. @see Input 1.
            int columns = int.Parse(Stream.ReadLine( ));
            int rows    = int.Parse(Stream.ReadLine( ));

            DynamicState = new GenericGridWorldDynamicState( );
            StaticState  = new GenericGridWorldStaticState(rows, columns,
                                                           DynamicState);

            // Grid Next in input @see Input 2.
            String line = null;

            List <Unit> Units = new List <Unit>( );
            int         i     = 0;

            while ((line = Stream.ReadLine( ).Trim( )) != null &&
                   !line.Equals("--- end units ---"))
            {
                String[] split = line.Split( );
                int      x     = int.Parse(split[0]);
                int      y     = int.Parse(split[1]);
                int      dstX  = int.Parse(split[2]);
                int      dstY  = int.Parse(split[3]);
                // ignore split[4] which is LOS.
                Units.Add(new Unit(x, y, rows, columns, dstX, dstY, LOS, i++));
            }

            GridWorldFormat.FromTileStream(Stream, StaticState, DynamicState, Units);
        }
コード例 #2
0
ファイル: XMLGridWorldLoader.cs プロジェクト: chiwakii/mai
        /// <summary>
        /// The load method to parse the file format. This will throw a format
        /// exception if it fails.
        /// </summary>
        /// <param name="Stream">The stream to parse from.</param>
        /// <returns>The grid world.</returns>
        public override void Load(System.IO.TextReader Stream,
                                  out GenericGridWorldStaticState StaticState,
                                  out GenericGridWorldDynamicState DynamicState)
        {
            XmlSerializer s = new XmlSerializer(typeof(Map));
            Map           xml;

            xml = (Map)s.Deserialize(Stream);


            DynamicState = new GenericGridWorldDynamicState( );
            StaticState  = new GenericGridWorldStaticState(xml.Height, xml.Width,
                                                           DynamicState);

            List <Unit> Units = new List <Unit>( );

            Units.Add(new Unit(xml.Start.X, xml.Start.Y, xml.Height, xml.Width,
                               xml.Goal.X, xml.Goal.Y, LOS, 0));


            GridWorldFormat.FromTileStream(new StringReader(xml.Tiles),
                                           StaticState, DynamicState, Units);
            StaticState.SetChangeList(xml);
        }