示例#1
0
        //创建step场景实例,包括其下的所有子场景及不同点
        public static bool CreateBattleScence(int nStageID, int nStepID, int nSubID, Team pTA, Team pTB, out BattleStep poutStep)
        {
            if (StageData.StageList.ContainsKey(nStageID))
            {
                if (StageData.StageList[nStageID].StepList.ContainsKey(nStepID))
                {
                    StepData   pDataStep = StageData.StageList[nStageID].StepList[nStepID];
                    BattleStep pStep     = new BattleStep();
                    pStep.nStageID = nStageID;
                    pStep.nID      = nStepID;
                    pStep.nIndex   = nStepID;

                    if (pDataStep.SubStepList.ContainsKey(nSubID))
                    {
                        SubStepData psub     = pDataStep.SubStepList[nSubID];
                        SubStep     pSubStep = new SubStep(pStep);
                        pSubStep.ID    = psub.ID;
                        pSubStep.Index = 1;
                        for (int i = 1; i <= psub.MaxDiff; ++i)
                        {
                            Random r   = new Random(Guid.NewGuid().GetHashCode());
                            int    rID = r.Next(1, psub.DiffList.Count + 1);
                            while (pSubStep.DiffList.ContainsKey(rID))
                            {
                                r   = new Random(Guid.NewGuid().GetHashCode());
                                rID = r.Next(1, psub.DiffList.Count + 1);
                            }

                            int  rorl  = r.Next(0, 2);
                            Diff pDiff = new Diff(i, rorl, psub.DiffList[rID]);
                            pSubStep.DiffList.TryAdd(pDiff.ID, pDiff);
                            //DiffData pDiff = new DiffData();
                        }
                        foreach (int nMKey in psub.MonsterList.Keys)
                        {
                            Monster pMonster = new Monster(pStep.nMonsterInseIndex, psub.MonsterList[nMKey], pSubStep);
                            pStep.nMonsterInseIndex++;
                            pStep.MonsterList.TryAdd(pMonster.Index, pMonster);
                            pSubStep.MonsterList.TryAdd(pMonster.Index, pMonster);
                            pMonster.CurStep = pStep;
                        }
                        pStep.cdSubList.TryAdd(psub.ID, pSubStep);
                        pStep.pCurSubStep = pSubStep;
                    }

                    //目前对战场景只有一关
                    //int nSubIndex = 1;
                    //foreach (SubStepData psub in pDataStep.SubStepList.Values)
                    //{
                    //    SubStep pSubStep = new SubStep(pStep);
                    //    pSubStep.ID = psub.ID;
                    //    pSubStep.Index = nSubIndex;
                    //    nSubIndex++;
                    //    for (int i = 1; i <= psub.MaxDiff; ++i)
                    //    {
                    //        Random r = new Random(Guid.NewGuid().GetHashCode());
                    //        int rID = r.Next(1, psub.DiffList.Count + 1);
                    //        while (pSubStep.DiffList.ContainsKey(rID))
                    //        {
                    //            r = new Random(Guid.NewGuid().GetHashCode());
                    //            rID = r.Next(1, psub.DiffList.Count + 1);
                    //        }

                    //        int rorl = r.Next(0, 2);
                    //        Diff pDiff = new Diff(i, rorl, psub.DiffList[rID]);
                    //        pSubStep.DiffList.TryAdd(pDiff.ID, pDiff);
                    //        //DiffData pDiff = new DiffData();
                    //    }
                    //    foreach (int nMKey in psub.MonsterList.Keys)
                    //    {
                    //        Monster pMonster = new Monster(pStep.nMonsterInseIndex, psub.MonsterList[nMKey]);
                    //        pStep.nMonsterInseIndex++;
                    //        pStep.MonsterList.TryAdd(pMonster.Index, pMonster);
                    //        pSubStep.MonsterList.TryAdd(pMonster.Index, pMonster);
                    //        pMonster.CurStep = pStep;
                    //    }
                    //    pStep.cdSubList.TryAdd(psub.ID, pSubStep);
                    //}

                    pStep.NStepType = Step.StepType.Battle;
                    pStep.PTeamA    = pTA;
                    pStep.PTeamB    = pTB;
                    pTA.NTeamState  = Team.TeamState.Battle;
                    pTB.NTeamState  = Team.TeamState.Battle;
                    poutStep        = pStep;
                    //查看是否是完成一关,包含子场景
                    if (0 < poutStep.cdSubList.Count)
                    {
                        //ThreadPool.QueueUserWorkItem(poutStep.Open);
                        return(true);
                    }
                }
            }
            poutStep = null;
            return(false);
        }
示例#2
0
        public static void LoadFile()                           //参数为指定的目录
        {
            //在指定目录及子目录下查找文件,在listBox1中列出子目录及文件
            DirectoryInfo Dir = new DirectoryInfo(OpenFilePath);

            try
            {
                foreach (DirectoryInfo stage in Dir.GetDirectories())     //查找子目录
                {
                    if ("." == stage.ToString() || ".." == stage.ToString() ||
                        -1 != stage.Attributes.ToString().IndexOf("Hidden"))
                    {
                        continue;
                    }
                    string tDir = OpenFilePath + "\\" + stage.ToString();
                    xmlDocStage.Load(tDir + @"\stage.xml");
                    XmlNode rootnode  = xmlDocStage.SelectSingleNode(RootNodeName);
                    XmlNode stagenode = rootnode.SelectSingleNode(StageNodeName);
                    //XmlNodeList nodes = rootnode.SelectNodes(StageNodeName);

                    StageData tstage = new StageData();
                    tstage.ID = System.Convert.ToInt32(stage.ToString());
                    //Data_Xml.SwanpPos_H.Add(stage.ID, stage);

                    foreach (DirectoryInfo step in stage.GetDirectories())     //查找子目录
                    {
                        if ("." == step.ToString() || ".." == step.ToString() ||
                            -1 != step.Attributes.ToString().IndexOf("Hidden"))
                        {
                            continue;
                        }
                        //FindFile(Dir + d.ToString() + "\\");
                        //listBox1.Items.Add(Dir + d.ToString() + "\\");       //listBox1中填加目录名
                        string tDirS = tDir + "\\" + step.ToString();
                        xmlDocStep.Load(tDirS + @"\step.xml");
                        int index = System.Convert.ToInt32(step.ToString());

                        XmlNode srootnode    = xmlDocStep.SelectSingleNode(RootNodeName);
                        XmlNode stepnode     = srootnode.SelectSingleNode(StepNodeName);
                        XmlNode steptimenode = stepnode.SelectSingleNode(TimeNodeName);

                        StepData tstep = new StepData();
                        tstep.ID   = index;
                        tstep.Time = System.Convert.ToInt32(steptimenode.InnerText);

                        foreach (DirectoryInfo substep in step.GetDirectories())     //查找子目录
                        {
                            if ("." == substep.ToString() || ".." == substep.ToString() ||
                                -1 != substep.Attributes.ToString().IndexOf("Hidden"))
                            {
                                continue;
                            }
                            string tDirSubstep = tDirS + "\\" + substep.ToString();
                            xmlDocSubStep.Load(tDirSubstep + @"\substep.xml");
                            int substepIndex = System.Convert.ToInt32(substep.ToString());;

                            XmlNode substeprootnode = xmlDocSubStep.SelectSingleNode(RootNodeName);
                            XmlNode substepnode     = substeprootnode.SelectSingleNode(SubStepNodeName);

                            SubStepData tsubstep = new SubStepData();
                            tsubstep.ID      = substepIndex++;
                            tsubstep.MaxDiff = System.Convert.ToInt32(substepnode.SelectSingleNode(MaxNodeName).InnerText);

                            XmlNode bossnode = substepnode.SelectSingleNode(BossNodeName);

                            if (null != bossnode)
                            {
                                int nBossID = System.Convert.ToInt32(bossnode.SelectSingleNode("bossid").InnerText);
                                BossData.init(nBossID,
                                              System.Convert.ToInt32(bossnode.SelectSingleNode("fireloop").InnerText));

                                tsubstep.m_BossID = nBossID;
                            }
                            else
                            {
                                tsubstep.m_BossID = 0;
                            }

                            XmlNodeList diffnodes = substepnode.SelectNodes(DiffNodeName);

                            int nDiffindex = 1;
                            foreach (XmlNode diff in diffnodes)
                            {
                                DiffData tdiff = new DiffData();

                                tdiff.ID     = nDiffindex++;
                                tdiff.PosX   = System.Convert.ToInt32(diff.SelectSingleNode("posx").InnerText);
                                tdiff.PosY   = System.Convert.ToInt32(diff.SelectSingleNode("posy").InnerText);
                                tdiff.LeftX  = System.Convert.ToInt32(diff.SelectSingleNode("leftx").InnerText);
                                tdiff.LeftY  = System.Convert.ToInt32(diff.SelectSingleNode("lefty").InnerText);
                                tdiff.RightX = System.Convert.ToInt32(diff.SelectSingleNode("rightx").InnerText);
                                tdiff.RightY = System.Convert.ToInt32(diff.SelectSingleNode("righty").InnerText);

                                tsubstep.DiffList.TryAdd(tdiff.ID, tdiff);
                            }

                            XmlNodeList monsternodes  = substepnode.SelectNodes("monster");
                            int         nMonsterindex = 1;
                            MonsterData.init();
                            foreach (XmlNode monsternode in monsternodes)
                            {
                                //int nMonsterID = Convert.ToInt32(monsternode.Attributes["ID"].Value);
                                int nMonsterID = System.Convert.ToInt32(monsternode.SelectSingleNode("id").InnerText);
                                if (MonsterData.MonsterDataList.ContainsKey(nMonsterID))
                                {
                                    MonsterData md = MonsterData.MonsterDataList[nMonsterID];
                                    tsubstep.MonsterList.TryAdd(nMonsterindex, md);
                                    nMonsterindex++;
                                }
                            }

                            tstep.SubStepList.TryAdd(tsubstep.ID, tsubstep);
                        }

                        ////遍历substep
                        //XmlNodeList subnodes = stepnode.SelectNodes(SubStepNodeName);
                        //int i = 1;
                        //foreach (XmlNode sub in subnodes)
                        //{
                        //    SubStepData tsubstep = new SubStepData();
                        //    tsubstep.Index = i++;
                        //    tsubstep.MaxDiff = System.Convert.ToInt32(sub.SelectSingleNode(MaxNodeName).InnerText);

                        //    XmlNodeList diffnodes = sub.SelectNodes(DiffNodeName);
                        //    int nDiffindex = 1;
                        //    foreach (XmlNode diff in diffnodes)
                        //    {
                        //        DiffData tdiff = new DiffData();

                        //        tdiff.Index = nDiffindex++;
                        //        tdiff.PosX = System.Convert.ToInt32(diff.SelectSingleNode("posx").InnerText);
                        //        tdiff.PosY = System.Convert.ToInt32(diff.SelectSingleNode("posy").InnerText);
                        //        tdiff.LeftX = System.Convert.ToInt32(diff.SelectSingleNode("leftx").InnerText);
                        //        tdiff.LeftY = System.Convert.ToInt32(diff.SelectSingleNode("lefty").InnerText);
                        //        tdiff.RightX = System.Convert.ToInt32(diff.SelectSingleNode("rightx").InnerText);
                        //        tdiff.RightY = System.Convert.ToInt32(diff.SelectSingleNode("righty").InnerText);

                        //        tsubstep.DiffList.TryAdd(tdiff.Index, tdiff);
                        //    }
                        //    tstep.SubStepList.TryAdd(tsubstep.Index, tsubstep);
                        //}

                        tstage.StepList.TryAdd(tstep.ID, tstep);
                    }
                    StageData.StageList.TryAdd(tstage.ID, tstage);
                }
                //foreach (FileInfo f in Dir.GetFiles("*.*"))             //查找文件
                //{
                //    listBox1.Items.Add(Dir + f.ToString());     //listBox1中填加文件名
                //}
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }