コード例 #1
0
        public void BuildTree()
        {
            CreateSubNode();
            if (LeftTop == null)
            {
                return;
            }
            foreach (ObjectGame o in listObj)
            {
                Rectangle r = new Rectangle(o.location.X, o.location.Y, o.bm.Width, o.bm.Height);
                if (LeftTop.rec.IntersectsWith(r))
                {
                    LeftTop.listObj.Add(o);
                }
                if (RightTop.rec.IntersectsWith(r))
                {
                    RightTop.listObj.Add(o);
                }
                if (LeftBot.rec.IntersectsWith(r))
                {
                    LeftBot.listObj.Add(o);
                }
                if (RightBot.rec.IntersectsWith(r))
                {
                    RightBot.listObj.Add(o);
                }
            }

            LeftTop.BuildTree();
            RightTop.BuildTree();
            LeftBot.BuildTree();
            RightBot.BuildTree();
            listObj.Clear();
        }
コード例 #2
0
        private void btn_Save_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();
            // saveFileDialog1.Filter = "Images|*.bmp;";
            ImageFormat format = ImageFormat.Png;

            if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                fileDirectory = Path.GetDirectoryName(saveFileDialog1.FileName);
                fileName      = Path.GetFileName(saveFileDialog1.FileName);
                format        = ImageFormat.Bmp;
                pictureBox2.BackgroundImage.Save(Path.Combine(fileDirectory, fileName + ".bmp"), format);
                //  StreamWriter writer = new StreamWriter(Path.Combine(fileDirectory,Name+"txt"));
                string text = "";
                text += listTile.Count + "\r\n";
                text += countRow + "\r\n";
                text += countCol + "\r\n";
                text += writeMatrix;
                File.WriteAllText(Path.Combine(fileDirectory, fileName + ".txt"), text);


                String s = "";

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

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

                foreach (ObjectGame obj in listobjmap)
                {
                    s += obj.ID + "\r\n";
                    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(saveFileDialog1.FileName + "Quadtree.txt");
                rootNode = new QuadNode("0", new Rectangle(0, 0, pictureBox1.Width, pictureBox1.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");
            }
        }