Ejemplo n.º 1
0
        public void Save(StreamWriter sw)
        {
            int subnode = 0;

            if (LeftTop != null)
            {
                subnode = 4;
            }
            sw.Write(rec.X.ToString("00000") + "\t\t" + rec.Y.ToString("00000") + "\t\t" + rec.Width.ToString("00000") + "\t\t" + rec.Height.ToString("00000") + "\t\t" + subnode + "\t\t\t" + listObjects.Count + "\t\t\t");
            if (listObjects.Count > 0)
            {
                foreach (Objects o in listObjects)
                {
                    sw.Write(o.Id + "\t");
                }
            }
            sw.WriteLine();
            if (LeftTop != null)
            {
                LeftTop.Save(sw);
                RightTop.Save(sw);
                LeftBot.Save(sw);
                RightBot.Save(sw);
            }
        }
Ejemplo n.º 2
0
        public void saveMap(string dir, Node root_node)
        {
            int    height = (1 + this.tilesList.Count / 20) * 16;
            Bitmap set    = new Bitmap(320, height);

            set.SetResolution(72.0F, 72.0F);

            foreach (Bitmap bm in this.tilesList)
            {
                int i = this.tilesList.IndexOf(bm) % 20;
                int j = this.tilesList.IndexOf(bm) / 20;

                using (Graphics g = Graphics.FromImage(set))
                {
                    g.InterpolationMode = InterpolationMode.NearestNeighbor;
                    g.DrawImage(bm, i * 16, j * 16, 17, 17);
                }
            }

            string name = dir.Split('.')[0];

            set.Save(name + ".bmp", ImageFormat.Bmp);

            using (FileStream fs = new FileStream(name + ".txt", FileMode.Create, FileAccess.Write))
            {
                StreamWriter sw = new StreamWriter(fs);
                sw.AutoFlush = true;
                sw.WriteLine("HEADER");
                sw.WriteLine("Map Info");
                sw.WriteLine("State_Num" + "\t" + "Tiles_Num" + "\t" + "Tiles_pRow" + "\t" + "Object_Num");
                sw.WriteLine(listState.Count + "\t\t\t" + tilesList.Count + "\t\t\t" + "20" + "\t\t\t" + listObject.Count);
                sw.WriteLine("\nState Info");
                sw.WriteLine("Pos_X" + "\t\t" + "Pos_Y" + "\t\t" + "Col_Num" + "\t\t" + "Row_Num");
                foreach (State st in this.listState)
                {
                    sw.WriteLine(st.position.X.ToString("00000") + "\t\t" + st.position.Y.ToString("00000") + "\t\t" + st.cols + "\t\t\t" + st.rows);
                }
                sw.WriteLine("END_HEADER\n");

                sw.WriteLine("STATE_SET");
                foreach (State st in this.listState)
                {
                    sw.WriteLine("State " + (listState.IndexOf(st) + 1));
                    for (int i = 0; i < st.rows; i++)
                    {
                        for (int j = 0; j < st.cols; j++)
                        {
                            sw.Write(st.setArr[i, j] + "\t");
                        }
                        sw.WriteLine();
                    }
                }
                sw.WriteLine("END_STATE_SET\n");

                sw.WriteLine("OBJECT_LIST");
                sw.WriteLine("ID" + "\t\t" + "Type" + "\t" + "Item" + "\t" + "Pos_X" + "\t\t" + "Pos_Y" + "\t\t" + "Var1" + "\t" + "Var2" + "\t" + "Var3");
                foreach (Objects o in this.listObject)
                {
                    sw.WriteLine(o.Id + "\t\t" + o.Type + "\t\t" + o.Item + "\t\t" +
                                 o.Point.X.ToString("00000") + "\t\t" + o.Point.Y.ToString("00000") + "\t\t" + o.Value_1 + "\t\t" + o.Value_2 + "\t\t" + o.Value_3);
                }
                sw.WriteLine("END_OBJECT_LIST\n");

                sw.WriteLine("QUAD_TREE");
                sw.WriteLine("Pos_X" + "\t\t" + "Pos_Y" + "\t\t" + "Width" + "\t\t" + "Height" + "\t\t" + "Node_Num" + "\t" + "Objs_Num" + "\t" + "List_Obj");
                root_node.Save(sw);
                sw.WriteLine("END_QUAD_TREE");
                sw.Close();
                fs.Close();
            }
        }