Ejemplo n.º 1
0
//--------------------Su kien New Game frame------------------
        void StateMenu_Move_Complete_NewGame(object sender, EventArgs e)
        {
            if (_indexOfNextState != 0)
            {
                return;
            }
            GameFrame _frame = (GameFrame)sender;

            if (_frame.IsVisible == false)
            {
                int nObjectManager = 12;
                GameObjectManager[] objectManagerArray = new GameObjectManager[nObjectManager];

                objectManagerArray[1]  = new MapManager(@"Data\Map\map.xml");
                objectManagerArray[0]  = new PlayerCharacterManager(@"Data\character\character.xml");
                objectManagerArray[2]  = new MonsterManager(@"Data\monster\monster.xml");
                objectManagerArray[3]  = new ProcessBarManager(@"Data\XML\processbar-stateloading.xml");
                objectManagerArray[4]  = new PortralManager(@"Data\Portral\Portral.xml");
                objectManagerArray[5]  = new MapObstacleManager(@"Data\MapObstacle\MapObstacle.xml");
                objectManagerArray[6]  = new ProjectileManager(@"Data\Projectile\Projectile.xml");
                objectManagerArray[7]  = new SkillManager(@"Data\Skill\Skill.xml");
                objectManagerArray[8]  = new GameFrameManager(@"Data\XML\gameframe-statemaingame.xml");
                objectManagerArray[9]  = new ProcessBarManager(@"Data\XML\processbar-statemaingame.xml");
                objectManagerArray[10] = new ButtonManger(@"Data\XML\buttonmanager-statemaingame.xml");
                objectManagerArray[11] = new LabelManager(@"Data\XML\labelmanager-statemaingame.xml");


                Owner.GameState = new StateLoading();
                Owner.GameState.InitState(null, Owner);
                ((StateLoading)Owner.GameState).GetDataLoading(Owner.Content, @"./Data/XML/loadingtomenu.xml", objectManagerArray, typeof(StateMainGame));
                Owner.GameState.EnterState();
            }
        }
        //Lấy vào chuỗi xml định nghĩa một số thông tin riêng của Loading state (hình
        //ảnh backGround, hình ảnh processBar) mảng các objectManager cần load và kiểu
        //của Game state kế tiếp.
        public void GetDataLoading(ContentManager content, string xmlInfo, GameObjectManager[] objectManagerArray, Type type)
        {
            _nObjectManager     = objectManagerArray.Length;
            _objectManagerArray = new GameObjectManager[_nObjectManager];

            for (int i = 0; i < _nObjectManager; i++)
            {
                _objectManagerArray[i] = objectManagerArray[i];
                //1 step là 1 doi tuong prototype cần load.
                _stepLengh += _objectManagerArray[i]._nprototype;
            }
            _stepLengh++;       // them cai innit cho gamestate tip theo.
            _type    = type;    //Lưu lại type của state tip theo
            _xmlInfo = xmlInfo; //Lưu lại chuoi XML luu thong tin rieng cua loadind state

            XmlDocument _doc = new XmlDocument();

            _doc.Load(_xmlInfo);

            XmlNode     _backGroundNote = _doc.DocumentElement.SelectSingleNode("BackGround");
            XmlNodeList _imageNoteList  = _backGroundNote.SelectNodes("//Image");

            _nBackGroundImage = _imageNoteList.Count;
            _backGroundImage  = new GameSprite[_nBackGroundImage];
            for (int i = 0; i < _nBackGroundImage; i++)
            {
                Texture2D _temp  = content.Load <Texture2D>(_imageNoteList[i].SelectSingleNode("Path").InnerText);
                int       _xTemp = int.Parse(_imageNoteList[i].SelectSingleNode("X").InnerText) - (int)GlobalVariables.dX;
                int       _yTemp = int.Parse(_imageNoteList[i].SelectSingleNode("Y").InnerText) - (int)GlobalVariables.dY;
                _backGroundImage[i]         = new GameSprite(_temp, _xTemp, _yTemp);
                _backGroundImage[i].Xoffset = 0;
                _backGroundImage[i].Yoffset = 0;
            }

            _delayTime = int.Parse(_doc.DocumentElement.SelectSingleNode("DelayTime").InnerText);
            string _processXMLInfo = _doc.DocumentElement.SelectSingleNode("ProcessBar").SelectSingleNode("ContentName").InnerText;

            //Truyền va init tại chỗ vì cái ProcessBarManager chỉ xài cho loading state
            ProcessBarManager pbm = new ProcessBarManager(_processXMLInfo);

            for (int i = 0; i < pbm._nprototype; i++)
            {
                pbm.InitOne(content, i);
            }
            _processBar = (ProcessBar)pbm.CreateObject(0);
        }
        //Lấy vào chuỗi xml định nghĩa một số thông tin riêng của Loading state (hình
        //ảnh backGround, hình ảnh processBar) mảng các objectManager cần load và kiểu
        //của Game state kế tiếp.
        public void GetDataLoading(ContentManager content, string xmlInfo, GameObjectManager[] objectManagerArray, Type type)
        {
            _nObjectManager = objectManagerArray.Length;
            _objectManagerArray = new GameObjectManager[_nObjectManager];

            for (int i = 0; i < _nObjectManager; i++)
            {
                _objectManagerArray[i] = objectManagerArray[i];
                //1 step là 1 doi tuong prototype cần load.
                _stepLengh += _objectManagerArray[i]._nprototype;
            }
            _stepLengh++; // them cai innit cho gamestate tip theo.
            _type = type; //Lưu lại type của state tip theo
            _xmlInfo = xmlInfo; //Lưu lại chuoi XML luu thong tin rieng cua loadind state

            XmlDocument _doc = new XmlDocument();
            _doc.Load(_xmlInfo);

            XmlNode _backGroundNote = _doc.DocumentElement.SelectSingleNode("BackGround");
            XmlNodeList _imageNoteList = _backGroundNote.SelectNodes("//Image");

            _nBackGroundImage = _imageNoteList.Count;
            _backGroundImage = new GameSprite[_nBackGroundImage];
            for (int i = 0; i < _nBackGroundImage; i++)
            {
                Texture2D _temp = content.Load<Texture2D>(_imageNoteList[i].SelectSingleNode("Path").InnerText);
                int _xTemp = int.Parse(_imageNoteList[i].SelectSingleNode("X").InnerText) - (int)GlobalVariables.dX;
                int _yTemp = int.Parse(_imageNoteList[i].SelectSingleNode("Y").InnerText) - (int)GlobalVariables.dY;
                _backGroundImage[i] = new GameSprite(_temp, _xTemp, _yTemp);
                _backGroundImage[i].Xoffset = 0;
                _backGroundImage[i].Yoffset = 0;
            }

            _delayTime = int.Parse(_doc.DocumentElement.SelectSingleNode("DelayTime").InnerText);
            string _processXMLInfo = _doc.DocumentElement.SelectSingleNode("ProcessBar").SelectSingleNode("ContentName").InnerText;

            //Truyền va init tại chỗ vì cái ProcessBarManager chỉ xài cho loading state
            ProcessBarManager pbm = new ProcessBarManager(_processXMLInfo);
            for (int i = 0; i < pbm._nprototype; i++)
            {
                pbm.InitOne(content, i);
            }
            _processBar = (ProcessBar)pbm.CreateObject(0);
        }
        //--------------------Su kien New Game frame------------------
        void StateMenu_Move_Complete_NewGame(object sender, EventArgs e)
        {
            if (_indexOfNextState != 0)
                return;
            GameFrame _frame = (GameFrame)sender;
            if (_frame.IsVisible == false)
            {
                int nObjectManager = 12;
                GameObjectManager[] objectManagerArray = new GameObjectManager[nObjectManager];

                objectManagerArray[1] = new MapManager(@"Data\Map\map.xml");
                objectManagerArray[0] = new PlayerCharacterManager(@"Data\character\character.xml");
                objectManagerArray[2] = new MonsterManager(@"Data\monster\monster.xml");
                objectManagerArray[3] = new ProcessBarManager(@"Data\XML\processbar-stateloading.xml");
                objectManagerArray[4] = new PortralManager(@"Data\Portral\Portral.xml");
                objectManagerArray[5] = new MapObstacleManager(@"Data\MapObstacle\MapObstacle.xml");
                objectManagerArray[6] = new ProjectileManager(@"Data\Projectile\Projectile.xml");
                objectManagerArray[7] = new SkillManager(@"Data\Skill\Skill.xml");
                objectManagerArray[8] = new GameFrameManager(@"Data\XML\gameframe-statemaingame.xml");
                objectManagerArray[9] = new ProcessBarManager(@"Data\XML\processbar-statemaingame.xml");
                objectManagerArray[10] = new ButtonManger(@"Data\XML\buttonmanager-statemaingame.xml");
                objectManagerArray[11] = new LabelManager(@"Data\XML\labelmanager-statemaingame.xml");

                Owner.GameState = new StateLoading();
                Owner.GameState.InitState(null, Owner);
                ((StateLoading)Owner.GameState).GetDataLoading(Owner.Content, @"./Data/XML/loadingtomenu.xml", objectManagerArray, typeof(StateMainGame));
                Owner.GameState.EnterState();
            }
        }