public List <TileV> AddObjectFromFile(List <TileV> tiles)
        {
            StreamReader reader = new StreamReader(_filename);

            if (reader != null)
            {
                TileVBuilder  builder = new TileVBuilder();
                GameObject    obj     = null;
                int           objno   = Convert.ToInt32(reader.ReadLine());
                string        line;
                List <string> array;
                for (int i = 0; i < objno; i++)
                {
                    line  = reader.ReadLine();
                    array = line.Split('|').ToList();
                    int type = Convert.ToInt32(array[0]);
                    int x    = Convert.ToInt32(array[1]);
                    int y    = Convert.ToInt32(array[2]);
                    for (int j = 0; j < 3; j++)
                    {
                        array.RemoveAt(0);
                    }
                    TileV tile = builder.FindTileAt(tiles, x, y);
                    switch (type)
                    {
                    case 0:
                        obj = GetGameObject(array);
                        break;

                    case 1:
                        int m = Convert.ToInt32(array[0]);
                        int n = Convert.ToInt32(array[1]);
                        for (int j = 0; j < 2; j++)
                        {
                            array.RemoveAt(0);
                        }
                        obj = GetActionObject(array, reader);
                        TileV atile = builder.FindTileAt(tiles, m, n);
                        if (obj != null && atile != null)
                        {
                            atile.LinkedTo = obj as ActionObject;
                        }
                        break;
                    }
                    if (obj != null && tile != null)
                    {
                        tile.Object = obj;
                    }
                }
                reader.Close();
            }
            return(tiles);
        }
Exemple #2
0
        /// <summary>
        /// convert tile to GO (tile)
        /// </summary>
        /// <param name="tile"></param>
        /// <param name="xcorner"></param>
        /// <param name="ycorner"></param>
        /// <returns></returns>
        public static GraphicObject Convert(TileV tile)
        {
            int           w  = _size;
            int           h  = _size;
            int           x  = _xcorner + tile.X * w;
            int           y  = _ycorner + tile.Y * h;
            GraphicObject go = new GraphicObject(new GameDetails(x, y, w, h));

            if (tile.Blocked)
            {
                go.Name = "tiles|Blocked";
            }
            else
            {
                go.Name = "tiles|Unblocked";
            }
            go.Priority = 2;
            return(go);
        }