Ejemplo n.º 1
0
 private void TestButton_Click(object sender, EventArgs e)
 {
     PlayerTeam pt = new PlayerTeam();
     MonsterTeam mt = new MonsterTeam();
     Combat combat = new Combat(pt, mt);
     this.TestTextBox.Text = combat.BeginCombat();
 }
Ejemplo n.º 2
0
 /// <summary>
 /// 队伍执行下一个动作
 /// </summary>
 /// <param name="turn">当前回合数</param>
 /// <param name="enemy">敌人(怪物队伍)</param>
 /// <returns>本次行动日志</returns>
 public string DoNextAction(int turn, MonsterTeam enemy)
 {
     Unit nextActionUnit = null;
     //根据队伍行动状态选取下一个行动单位并执行动作
     if (this.ActionState == PlayerActionState.AllReady)
     {
         //英雄行动
         //修改队伍行动状态为英雄行动结束
         this.ActionState = PlayerActionState.HeroDone;
         if (Hero.ActionState != UnitActionState.Dead)
         {
             //执行英雄动作
             nextActionUnit = Hero;
             //return Hero.Action(turn, enemy);
         }
     }
     else if (this.ActionState == PlayerActionState.HeroDone)
     {
         //部队行动
         double maxValue = 0;
         double randValue = 0;
         //Corps nextCorps = null;
         int count = 0;
         //随机选取未行动的部队行动(分配随机数,选取随机数最大的部队准备执行动作)
         for (int i = 0; i < Corps.Length; i++)
         {
             if (Corps[i].ActionState == UnitActionState.Ready)
             {
                 count++;
                 randValue = RandomBuilder.GetDouble();
                 if (randValue > maxValue)
                 {
                     nextActionUnit = Corps[i];
                     maxValue = randValue;
                 }
             }
         }
         //如果为最后一个未行动部队,修改队伍行动状态为全部单位行动结束
         if (count <= 1)
         {
             this.ActionState = PlayerActionState.AllDone;
         }
     }
     //如果无可行动单位,返回空字符串
     if (nextActionUnit == null)
     {
         return "";
     }
     else
     {
         //执行该单位动作
         return nextActionUnit.Action(turn, enemy);
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// 战斗构造函数
 /// 初始化一场战斗
 /// </summary>
 /// <param name="player">玩家队伍</param>
 /// <param name="monster">怪物队伍</param>
 public Combat(PlayerTeam player, MonsterTeam monster)
 {
     this.PlayerTeam = player;
     this.MonsterTeam = monster;
 }