コード例 #1
0
ファイル: Form1.cs プロジェクト: salvadorc17/Prince-Monogame
        private void SaveRoom(string path)
        {
            Map map = new Map();

            if (rooms.Count > 0)

            for (int r = 0; r <= map.rows.Count() - 1; r++)
            {
                Label21.Text = r.ToString();

                for (int i = 0; i <= map.rows[r].columns.Length - 1; i++)
                {
                    Label22.Text = i.ToString();

                    map.rows[r].columns[i].tileType = (Enumeration.TileType)Enum.Parse(typeof(Enumeration.TileType), block[i, r]);
                    map.rows[r].columns[i].spriteType = (Enumeration.SpriteType)Enum.Parse(typeof(Enumeration.SpriteType), sprite[i, r]);
                    map.rows[r].columns[i].item = (Enumeration.Items)Enum.Parse(typeof(Enumeration.Items), item[i, r]);

                    if (switche[i, r] != null)
                        map.rows[r].columns[i].state = (Enumeration.StateTile)Enum.Parse(typeof(Enumeration.StateTile), switche[i, r]);
                }

            }

            XmlSerializer serialize = new XmlSerializer(typeof(Map));

            using (var writer = new StreamWriter(path))
            {
                serialize.Serialize(writer, map);
            }
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: salvadorc17/Prince-Monogame
        private void LoadRoom(string path)
        {
            richTextBox1.Clear();

            System.Xml.Serialization.XmlSerializer ax = default(System.Xml.Serialization.XmlSerializer);
            Stream txtReader = File.Open(path, FileMode.Open);

            //TextReader txtReader = File.OpenText(filePath);

            ax = new XmlSerializer(typeof(Map));
            map = (Map)ax.Deserialize(txtReader);

            //Stream astream = this.GetType().Assembly.GetManifestResourceStream(filePath);
            richTextBox1.AppendText("<Map>" + Environment.NewLine);
            richTextBox1.AppendText("<Rows>" + Environment.NewLine);
            richTextBox1.AppendText("<Row>" + Environment.NewLine);
            richTextBox1.AppendText("<columns>" + Environment.NewLine);

            for (int r = 0; r <= map.rows.Count() - 1; r++)
            {
                Label21.Text = r.ToString();

                for (int i = 0; i <= map.rows[r].columns.Length - 1; i++)
                {
                    Label22.Text = i.ToString();

                    block[i, r] = Enum.GetName(typeof(Enumeration.TileType), map.rows[r].columns[i].tileType);

                    //Load gate switch state
                    if (block[i, r] == "gate" && map.rows[r].columns[i].state == Enumeration.StateTile.opened)
                        switche[i, r] = "open";
                    else if (block[i, r] == "gate" && map.rows[r].columns[i].state == Enumeration.StateTile.closed)
                        switche[i, r] = "closed";

                    //Load exit switch state
                    if (block[i, r] == "exit" && map.rows[r].columns[i].state == Enumeration.StateTile.exit_close_left)
                        switche[i, r] = "exit_close_left";
                    else if (block[i, r] == "exit" && map.rows[r].columns[i].state == Enumeration.StateTile.exit_close_right)
                        switche[i, r] = "exit_close_right";

                    sprite[i, r] = Enum.GetName(typeof(Enumeration.SpriteType), map.rows[r].columns[i].spriteType);
                    if (sprite[i, r] == "kid")
                         {
                             Player = new Sprite(0, Enumeration.SpriteType.kid, i, r);
                             TextBox28.Text = Player.X.ToString();
                             TextBox29.Text = Player.Y.ToString();

                         }
                    else if (sprite[i, r] == "guard")
                        {

                        Guard = new Sprite(guardcount, Enumeration.SpriteType.guard, i, r);
                        TextBox30.Text = Guard.X.ToString();
                        TextBox31.Text = Guard.Y.ToString();
                        guardcount += 1;

                        }

                    item[i, r] = Enum.GetName(typeof(Enumeration.Items), map.rows[r].columns[i].item);

                    richTextBox1.AppendText("<Column>" + Environment.NewLine);

                    if ((sprite[r, i] != null))
                    {
                        richTextBox1.AppendText("<spriteType>" + sprite[r, i] + "</spriteType>" + Environment.NewLine);

                    }

                    if ((item[r, i] != null))
                    {
                        richTextBox1.AppendText("<item>" + item[r, i] + "</item>" + Environment.NewLine);

                    }
                    richTextBox1.AppendText("<tileType>" + block[r, i] + "</tileType>" + Environment.NewLine);
                    richTextBox1.AppendText("</Column>" + Environment.NewLine);

                }

            }

            txtReader.Close();

            richTextBox1.AppendText("</columns>" + Environment.NewLine);
            richTextBox1.AppendText("</Row>" + Environment.NewLine);
            richTextBox1.AppendText("</rows>" + Environment.NewLine);
            richTextBox1.AppendText("</Map>" + Environment.NewLine);

            Roomselected = true;
        }
コード例 #3
0
        public RoomNew(Maze maze, string filePath, int roomIndex, int roomType)
        {
            this.maze = maze;
            this.roomIndex = roomIndex;
            this.roomType = roomType;

            //tilesTemporaney = ArrayList.Synchronized(_tilesTemporaney);
            //LOAD MXL CONTENT
            //map = content.Load<Map>(filePath);

            //LOAD RES CONTENT
            System.Xml.Serialization.XmlSerializer ax = default(System.Xml.Serialization.XmlSerializer);

            Stream txtReader = Microsoft.Xna.Framework.TitleContainer.OpenStream(filePath);

            //TextReader txtReader = File.OpenText(filePath);

            //Stream astream = this.GetType().Assembly.GetManifestResourceStream(filePath);
            ax = new System.Xml.Serialization.XmlSerializer(typeof(Map));
            map = (Map)ax.Deserialize(txtReader);

            //LoadTilesMask();
            LoadTiles();
        }