当前位置: 首页>>代码示例>>C#>>正文


C# Battle.DoBattle方法代码示例

本文整理汇总了C#中Battle.DoBattle方法的典型用法代码示例。如果您正苦于以下问题:C# Battle.DoBattle方法的具体用法?C# Battle.DoBattle怎么用?C# Battle.DoBattle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Battle的用法示例。


在下文中一共展示了Battle.DoBattle方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: btnAttackSettings_Click

        protected void btnAttackSettings_Click(object sender, EventArgs e)
        {
            if (!player.CanAttack(enemy)) {
                Response.Redirect("Sector.aspx");
                return;
            }

            bool hasUnits = false;
            bool hasAlliedUnits = false;
            foreach (Unit u in sector.Units)
                if (u.IsAvailable)
                    if (player == u.Owner)
                        hasUnits = true;
                    else if (player.IsAlly(u.Owner) && player.HasAHigherAllianceRank(u.Owner))
                        hasAlliedUnits = true;
            if (!hasUnits) {
                Response.Redirect("Sector.aspx");
                return;
            }

            Army attackersArmy = new Army(player);
            Army defendersArmy = new Army(enemy);

            List<Player> otherAttackers = new List<Player>();
            List<Player> otherDefenders = new List<Player>();

            foreach (Unit u in sector.Units)
                if (u.IsAvailable || u.IsWorking) {
                    if (u.Owner == player)
                        attackersArmy.Entities.Add(u);
                    else if (chkAllied.Checked && player.IsAlly(u.Owner) && player.HasAHigherAllianceRank(u.Owner) && !u.IsWorking) {
                        if (!otherAttackers.Contains(u.Owner))
                            otherAttackers.Add(u.Owner);
                        attackersArmy.Entities.Add(u);
                    }
                    else if (u.Owner == enemy)
                        defendersArmy.Entities.Add(u);
                    else if (enemy.IsAlly(u.Owner)) {
                        if (!otherDefenders.Contains(u.Owner))
                            otherDefenders.Add(u.Owner);
                        defendersArmy.Entities.Add(u);
                    }
                }

            if (sector.Owner == enemy)
                foreach (Building b in sector.Buildings)
                    if (!b.IsInConstruction)
                        defendersArmy.Entities.Add(b);

            foreach (Entity f in attackersArmy.Entities)
                f.Destroy();
            foreach (Entity f in defendersArmy.Entities)
                f.Destroy();
            Battle battle = new Battle(attackersArmy, defendersArmy, sector);
            BattleResult result = battle.DoBattle(int.Parse(drpRounds.SelectedValue), int.Parse(drpBuildingRounds.SelectedValue), chkArrival.Checked);
            foreach (Entity f in attackersArmy.Entities)
                f.Create(sector);
            foreach (Entity f in defendersArmy.Entities)
                f.Create(sector);

            //TODO proceed here

            string message = "";
            switch (result.Status) {
                case BattleStatus.AttackerWins:
                    message += "You've been attacked by " + attackersArmy.Owner.FullName + " at " + sector.ToString() + " and suffered a defeat. You've lost " + Wc3o.Game.Format(result.Gold) + " gold and " + Wc3o.Game.Format(result.Lumber) + " lumber. In addition, you lost <ul>";
                    lblMessage.Text = "You won the battle and " + Wc3o.Game.Format(result.Gold) + " gold and " + Wc3o.Game.Format(result.Lumber) + " lumber.";
                    break;
                case BattleStatus.DefenderWins:
                    message += "You've been attacked by " + attackersArmy.Owner.FullName + " at " + sector.ToString() + ", but your surpreme forces were able to defeat the enemy. Therefore you won " + Wc3o.Game.Format(-result.Gold) + " gold and " + Wc3o.Game.Format(-result.Lumber) + " lumber. Your losses were <ul>";
                    lblMessage.Text = "You've lost the battle and " + Wc3o.Game.Format(-result.Gold) + " gold and " + Wc3o.Game.Format(-result.Lumber) + " lumber.";
                    break;
                case BattleStatus.NonWins:
                    message += "You've been attacked by " + attackersArmy.Owner.FullName + " at " + sector.ToString() + ", but none of you was able to win that battle. Nevertheless, you lost " + Wc3o.Game.Format(result.Gold) + " gold and " + Wc3o.Game.Format(result.Lumber) + " lumber. Your losses were <ul>";
                    lblMessage.Text = "This battle had no winner. But you were able to gain " + Wc3o.Game.Format(result.Gold) + " gold and " + Wc3o.Game.Format(result.Lumber) + " lumber.";
                    break;
            }

            lblHostileLosses.Text += "<table style='width:100%;' cellspacing='0' cellpadding='0' border='0'>";
            foreach (Entity f in result.DefendersLosses) {
                message += "<li>" + Wc3o.Game.Format(f.Number) + " " + f.Info.Name + "</li>";
                lblHostileLosses.Text += "<tr><td style='width:1px;'><img src='" + player.Gfx + f.Info.Image + "'></td><td align='left'>" + Wc3o.Game.Format(f.Number) + " " + f.Info.Name + "</td></tr>";
            }
            lblHostileLosses.Text += "</table>";

            message += "</ul>" + attackersArmy.Owner.FullName + " lost:<ul>";
            lblPlayerLosses.Text = "<table style='width:300px;' cellspacing='0' cellpadding='0' border='0'>";
            foreach (Entity f in result.PlayerLosses) {
                message += "<li>" + Wc3o.Game.Format(f.Number) + " " + f.Info.Name + "</li>";
                lblPlayerLosses.Text += "<tr><td style='width:1px;'><img src='" + player.Gfx + f.Info.Image + "'></td><td align='left'>" + Wc3o.Game.Format(f.Number) + " " + f.Info.Name + "</td></tr>";
            }
            lblPlayerLosses.Text += "</table>";

            message += "</ul><br />If you need more details, take a look at the  <a href='Logs/BattleLogs/" + result.Log + "'>Battle Log</a>.";

            hplLog.NavigateUrl = "~/Game/Logs/BattleLogs/" + result.Log;

            if (enemy != null)
                new Message(defendersArmy.Owner, null, "You've been attacked by " + attackersArmy.Owner.FullName + " at " + sector.ToString() + ".", message);

//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:wc3o-svn,代码行数:101,代码来源:Battle.aspx.cs


注:本文中的Battle.DoBattle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。