Ejemplo n.º 1
0
        public ConstructionBlock Mirror()
        {
            string bblock = "";

            for (int y = 0; y < Height; y++)
            {
                for (int x = Width - 1; x >= 0; x--)
                {
                    bblock += this.block [x, y];
                }
            }
            var res = new ConstructionBlock(bblock, this.Width, this.Height, this.ID);

            foreach (var exit in this.exits)
            {
                res.AddExit(this.Width - 1 - exit.X, exit.Y, exit.MirrorDirection(), exit.CanBeClosed);
            }
            foreach (var obj in this.objects)
            {
                if (Array.IndexOf(obj.Variations, "M") > -1)
                {
                    res.AddObject(obj.ID, this.Width - 1 - obj.X, obj.Y, obj.Probability, new string[] { });
                }
            }
            return(res);
        }
Ejemplo n.º 2
0
        public ConstructionBlock Flip()
        {
            string bblock = "";

            for (int y = Height - 1; y >= 0; y--)
            {
                for (int x = 0; x < Width; x++)
                {
                    bblock += this.block [x, y];
                }
            }
            var res = new ConstructionBlock(bblock, this.Width, this.Height, this.ID);

            foreach (var exit in this.exits)
            {
                res.AddExit(exit.X, this.Height - 1 - exit.Y, exit.FlipDirection(), exit.CanBeClosed);
            }
            foreach (var obj in this.objects)
            {
                if (Array.IndexOf(obj.Variations, "F") > -1)
                {
                    res.AddObject(obj.ID, obj.X, this.Height - 1 - obj.Y, obj.Probability, new string[] { });
                }
            }
            return(res);
        }
Ejemplo n.º 3
0
        public ConstructionBlock RotateCW()
        {
            var newWidth  = block.GetLength(1);
            var newHeight = block.GetLength(0);

            char[,] newMatrix = new char[newWidth, newHeight];
            for (var oy = 0; oy < newWidth; oy++)
            {
                for (var ox = 0; ox < newHeight; ox++)
                {
                    var nx = newWidth - oy - 1;
                    var ny = ox;
                    newMatrix [nx, ny] = block [ox, oy];
                }
            }
            ////////
            string bblock = "";

            for (int y = 0; y < newHeight; y++)
            {
                for (int x = 0; x < newWidth; x++)
                {
                    bblock += newMatrix [x, y];
                }
            }
            var res = new ConstructionBlock(bblock, newWidth, newHeight, this.ID);

            foreach (var exit in this.exits)
            {
                var nx = newWidth - exit.Y - 1;
                var ny = exit.X;
                res.AddExit(nx, ny, exit.RotateDirectionCW(), exit.CanBeClosed);
            }
            foreach (var obj in this.objects)
            {
                if (Array.IndexOf(obj.Variations, "CW") > -1)
                {
                    var nx = newWidth - obj.Y - 1;
                    var ny = obj.X;
                    res.AddObject(obj.ID, nx, ny, obj.Probability, new string[] { });
                }
            }
            return(res);
        }
Ejemplo n.º 4
0
        public void BuildBlock(XmlNode xblock)
        {
            var data  = Regex.Replace(xblock.InnerText, @"\s+", "");
            var id    = XmlUtilities.GetString(xblock, "id");
            var block = new ConstructionBlock(
                data,
                XmlUtilities.GetInt(xblock, "width"),
                XmlUtilities.GetInt(xblock, "height"),
                XmlUtilities.GetString(xblock, "id")
                );
            var children = xblock.ChildNodes;

            for (int i = 0; i < children.Count; i++)
            {
                switch (children [i].Name)
                {
                case "end":
                    block.EndPoint = new BlockObject {
                        ID          = "end",
                        X           = XmlUtilities.GetInt(children [i], "x"),
                        Y           = XmlUtilities.GetInt(children [i], "y"),
                        Probability = 1f
                    };
                    break;

                case "exit":
                    block.AddExit(
                        XmlUtilities.GetInt(children [i], "x"),
                        XmlUtilities.GetInt(children [i], "y"),
                        XmlUtilities.GetString(children [i], "direction"),
                        XmlUtilities.GetBool(children [i], "canBeClosed", false)
                        );
                    break;

                case "object":
                    block.AddObject(
                        XmlUtilities.GetString(children [i], "ref"),
                        XmlUtilities.GetInt(children [i], "x"),
                        XmlUtilities.GetInt(children [i], "y"),
                        XmlUtilities.GetFloat(children [i], "probability"),
                        XmlUtilities.GetStringArray(children [i], "variations")
                        );
                    break;

                case "start":
                    block.StartPoint = new BlockObject {
                        ID          = "start",
                        X           = XmlUtilities.GetInt(children [i], "x"),
                        Y           = XmlUtilities.GetInt(children [i], "y"),
                        Probability = 1f
                    };
                    break;

                default:
                    break;
                }
            }
            var pb = XmlUtilities.GetInt(xblock, "occurs");

            this.blocks.Add(block, pb);
            this.blocksById.Add(block.ID, block);
            Logger.Debug("WorldFactory", "BuildBlock", "Built block:\n" + block.ToString());
            var variations = XmlUtilities.GetStringArray(xblock, "variations");

            if (Array.IndexOf(variations, "CCW") >= 0)
            {
                var ccwblock = block.RotateCCW();
                this.blocks.Add(ccwblock, pb);
                Logger.Debug("WorldFactory", "BuildBlock", "Built block CCW:\n" + ccwblock.ToString());
            }
            if (Array.IndexOf(variations, "CW") >= 0)
            {
                var cwblock = block.RotateCW();
                this.blocks.Add(cwblock, pb);
                Logger.Debug("WorldFactory", "BuildBlock", "Built block CW:\n" + cwblock.ToString());
            }
            if (Array.IndexOf(variations, "F") >= 0)
            {
                var fblock = block.Flip();
                this.blocks.Add(fblock, pb);
                Logger.Debug("WorldFactory", "BuildBlock", "Built block F:\n" + fblock.ToString());
            }
            if (Array.IndexOf(variations, "FM") >= 0)
            {
                var fmblock = block.FlipMirror();
                this.blocks.Add(fmblock, pb);
                Logger.Debug("WorldFactory", "BuildBlock", "Built block FM:\n" + fmblock.ToString());
            }
            if (Array.IndexOf(variations, "M") >= 0)
            {
                var mblock = block.Mirror();
                this.blocks.Add(mblock, pb);
                Logger.Debug("WorldFactory", "BuildBlock", "Built block M:\n" + mblock.ToString());
            }
        }