示例#1
0
        public void LoadNode(string quadtree, List <ObjectGame> listAllobj)
        {
            int curentIndex = 0;
            int left        = int.Parse(quadtree.Substring(curentIndex, quadtree.IndexOf("\t\t\t", curentIndex) - curentIndex));

            curentIndex = quadtree.IndexOf("\t\t\t", curentIndex) + 3;
            int top = int.Parse(quadtree.Substring(curentIndex, quadtree.IndexOf("\t\t\t", curentIndex) - curentIndex));

            curentIndex = quadtree.IndexOf("\t\t\t", curentIndex) + 3;
            int right = int.Parse(quadtree.Substring(curentIndex, quadtree.IndexOf("\t\t\t", curentIndex) - curentIndex));

            curentIndex = quadtree.IndexOf("\t\t\t", curentIndex) + 3;
            int bot = int.Parse(quadtree.Substring(curentIndex, quadtree.IndexOf("\t\t\t", curentIndex) - curentIndex));

            curentIndex = quadtree.IndexOf("\t\t\t", curentIndex) + 3;
            this.rec    = new Rectangle(left, top, right, bot);
            int num_node = int.Parse(quadtree.Substring(curentIndex, quadtree.IndexOf("\t\t\t", curentIndex) - curentIndex));

            curentIndex = quadtree.IndexOf("\t\t\t", curentIndex) + 3;
            int num_obj = int.Parse(quadtree.Substring(curentIndex, quadtree.IndexOf("\t\t\t", curentIndex) - curentIndex));

            curentIndex = quadtree.IndexOf("\t\t\t", curentIndex) + 3;



            if (num_node == 0 && num_obj == 0)
            {
                return;
            }

            if (num_node == 4)
            {
                int halfWidth  = rec.Width / 2;
                int halfHeight = rec.Height / 2;
                LeftTop  = new QuadNode(this.id + "0", new Rectangle(rec.Location, new Size(halfWidth, halfHeight)));
                RightTop = new QuadNode(this.id + "1", new Rectangle(new Point(rec.Left + halfWidth, rec.Top), new Size(halfWidth, halfHeight)));
                LeftBot  = new QuadNode(this.id + "2", new Rectangle(new Point(rec.Left, rec.Top + halfHeight), new Size(halfWidth, halfHeight)));
                RightBot = new QuadNode(this.id + "3", new Rectangle(new Point(rec.Left + halfWidth, rec.Top + halfHeight), new Size(halfWidth, halfHeight)));
                quadtree = quadtree.Substring(quadtree.IndexOf("\r\n") + 2);
                LeftTop.LoadNode(quadtree, listAllobj);
                quadtree = quadtree.Substring(quadtree.IndexOf("\r\n") + 2);
                RightTop.LoadNode(quadtree, listAllobj);
                quadtree = quadtree.Substring(quadtree.IndexOf("\r\n") + 2);
                LeftBot.LoadNode(quadtree, listAllobj);
                quadtree = quadtree.Substring(quadtree.IndexOf("\r\n") + 2);
                RightBot.LoadNode(quadtree, listAllobj);
            }
            else
            {
                for (int i = 0; i < num_obj; i++)
                {
                    int index = int.Parse(quadtree.Substring(curentIndex, quadtree.IndexOf("\t\t", curentIndex) - curentIndex));
                    curentIndex = quadtree.IndexOf("\t\t", curentIndex) + 2;
                    listObj.Add(listAllobj[index]);
                }
                quadtree = quadtree.Substring(quadtree.IndexOf("\r\n") + 2);
            }
        }
示例#2
0
        private void btn_Open_Click(object sender, EventArgs e)
        {
            openFileDialog1.ShowDialog();
            try
            {
                fileDirectory = Path.GetDirectoryName(openFileDialog1.FileName);
                fileName      = Path.GetFileName(openFileDialog1.FileName).Substring(0, Path.GetFileName(openFileDialog1.FileName).LastIndexOf("."));
                pictureBox2.BackgroundImage = Image.FromFile(openFileDialog1.FileName);
                pictureBox2.Width           = pictureBox2.BackgroundImage.Width;
                pictureBox2.Height          = pictureBox2.BackgroundImage.Height;
                readMatrix = File.ReadAllText(Path.Combine(fileDirectory, fileName + ".txt"));
                countRow   = pictureBox2.Height / 32;
                countCol   = pictureBox2.Width / 32;
                matTile    = new int[countRow, countCol];

                Cut(pictureBox2.BackgroundImage);
                decodeMatrix();


                // FileStream fileStream = new FileStream("")
                String readObj = File.ReadAllText(Path.Combine(fileDirectory, fileName + "OBJ.txt"));
                decodeObj(readObj);

                buildBackground();
                //pictureBox1.Width = pictureBox1.BackgroundImage.Width;
                //pictureBox1.Height = pictureBox1.BackgroundImage.Height;
                //pictureBox1.Image = new Bitmap(pictureBox1.Width, pictureBox1.Height);
                String readQuadTree = File.ReadAllText(Path.Combine(fileDirectory, fileName + "QuadTree.txt"));
                rootNode = new QuadNode("0", new Rectangle(0, 0, pictureBox1.Width, pictureBox1.Height));
                rootNode.LoadNode(readQuadTree, listobjmap);
                DrawDash(countMatrixRow, countMatrixCol);
            }


            catch
            {
            }
        }