示例#1
0
        public void Save(StreamWriter sw)
        {
            int subnode = 0;

            if (LeftTop != null)
            {
                subnode = 4;
            }

            sw.Write(rec.X.ToString() + "\t\t\t" + rec.Y.ToString() + "\t\t\t" + rec.Width.ToString() + "\t\t\t" + rec.Height.ToString() + "\t\t\t" + subnode + "\t\t\t" + listObj.Count + "\t\t\t");
            if (listObj.Count > 0)
            {
                foreach (ObjectGame o in listObj)
                {
                    sw.Write(o.index + "\t\t");
                }
            }
            sw.WriteLine();
            if (LeftTop != null)
            {
                LeftTop.Save(sw);
                RightTop.Save(sw);
                LeftBot.Save(sw);
                RightBot.Save(sw);
            }
        }
示例#2
0
        private void btnSaveMatrix_Click(object sender, EventArgs e)
        {
            String         s  = "";
            SaveFileDialog sv = new SaveFileDialog();

            sv.ShowDialog();

            StreamWriter writer = new StreamWriter(sv.FileName + ".txt");

            s += listobjmap.Count + "\r\n" + "\r\n";

            foreach (ObjectGame obj in listobjmap)
            {
                s += obj.ID + "\r\n";

                if (obj.ID == 11) //unknow
                {
                    int i = 0;

                    foreach (ObjectGame o in listobjmap)
                    {
                        if (o.location.X == obj.location.X && o.location.Y == obj.location.Y - 16)
                        {
                            s += i + "\r\n";
                        }
                        i++;
                    }
                }

                if (obj.ID == 10) // brick
                {
                    int i = 0;
                    foreach (ObjectGame o in listobjmap)
                    {
                        if (o.ID == 10)
                        {
                            s += "0" + "\r\n";
                        }
                        if (o.ID != 10 && o.location.X == obj.location.X && o.location.Y == obj.location.Y - 16)
                        {
                            s += i + "\r\n";
                        }
                        i++;
                    }
                }

                s += obj.location.X + "\r\n";
                s += obj.location.Y + "\r\n";
                s += obj.bm.Width + "\r\n";
                s += obj.bm.Height + "\r\n";
                s += "\r\n";
            }
            writer.Write(s);
            writer.Close();

            StreamWriter quadtree = new StreamWriter(sv.FileName + "Quadtree.txt");

            rootNode = new QuadNode("0", new Rectangle(0, 0, pbMap.Width, pbMap.Height));
            int ind = 0;

            foreach (ObjectGame obj in listobjmap)
            {
                obj.index = ind;
                ind++;
            }
            rootNode.listObj = listobjmap;
            rootNode.BuildTree();
            rootNode.Save(quadtree);
            quadtree.Close();
            MessageBox.Show("Saved");
        }