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


C# IUnit.DecreaseLifePoints方法代码示例

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


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

示例1: TestLifePoints

        private void TestLifePoints(IUnit unit)
        {
            Assert.AreEqual(unit.DefaultLifePoints, unit.LifePoints);
            Assert.IsTrue(unit.IsAlive());
            Assert.IsTrue(unit.DecreaseLifePoints());
            Assert.AreEqual(unit.DefaultLifePoints - 1, unit.LifePoints);

            // Removes life points until the unit is dead:
            while(unit.LifePoints > 0) {
                Assert.IsTrue(unit.IsAlive());
                Assert.IsTrue(unit.DecreaseLifePoints());
            }
            Assert.IsFalse(unit.IsAlive());
        }
开发者ID:pchaigno,项目名称:smallworld,代码行数:14,代码来源:TestUnit.cs

示例2: Combat

        /// <summary>
        /// Computes a fight between the currently selected unit
        /// and the best one from the selected destination.
        /// </summary>
        /// <param name="unit">The unit who fight.</param>
        /// <returns>A constant from the CombatResult enumeration to describe the result.</returns>
        private CombatResult Combat(IUnit unit)
        {
            IUnit enemy = GetBestUnit();

            Random randCombat = new Random();
            Random rand = new Random();

            int nbRound = 3 + randCombat.Next((Math.Max(unit.LifePoints, enemy.LifePoints)) + 2);
            int n = 0;

            while(nbRound > n && unit.IsAlive() && enemy.IsAlive()) {
                double ratioLife = (double)unit.LifePoints / (double)unit.DefaultLifePoints;
                double ratioLifeDef = (double)enemy.LifePoints / (double)enemy.DefaultLifePoints;
                double attaUnit = (double)unit.Attack * (double)ratioLife;
                double defUnitdef = (double)enemy.Defense * (double)ratioLifeDef;
                double ratioAttDef = (double)(attaUnit / defUnitdef);
                double ratioChanceDef = 0;
                if(ratioAttDef > 1) {
                    // Advantage for the attacker.
                    ratioChanceDef = (1 / ratioAttDef) / 2;
                    ratioChanceDef = (0.5 - ratioChanceDef) + 0.5;
                } else if(ratioAttDef == 1) {
                    // Draw: 50% chances to win.
                    ratioChanceDef = 0.5;
                } else {
                    // Advantage for the defender.
                    ratioChanceDef = ratioAttDef / 2;
                }
                double ratioCombat = (double)((double)rand.Next(100) / 100);

                if(ratioCombat <= ratioChanceDef) {
                    enemy.DecreaseLifePoints();
                } else {
                    unit.DecreaseLifePoints();
                }
                n++;
            }

            // Computes the result of the fight:
            if(!unit.IsAlive()) {
                this.game.Map.RemoveUnit(unit, this.selectedPosition);
                this.lastMoveInfo = this.player.Name + " lost the fight.";
                this.lastCombatResult = CombatResult.LOSE;
            } else if(!enemy.IsAlive()) {
                this.game.Map.RemoveUnit(enemy, this.destination);
                this.lastMoveInfo = this.player.Name + " won the fight.";
                this.lastCombatResult = CombatResult.WIN;
            } else {
                this.lastMoveInfo = "The fight ended with a draw";
                this.lastCombatResult = CombatResult.DRAW;
            }
            return this.lastCombatResult;
        }
开发者ID:pchaigno,项目名称:smallworld,代码行数:59,代码来源:Round.cs


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