Ejemplo n.º 1
0
        public override double Fight(Character opponant)
        {
            var damageCaused = 0;

            var actionsRemaining = Actions;

            while (actionsRemaining > 0)
            {
                actionsRemaining--;

                var hit = opponant.TakeHit(AttackType.Melee, Might);

                var damageSpread = new DamageExpression[4] {
                    new DamageExpression(0),
                    new DamageExpression(1),
                    new DamageExpression(1, DiceShape.D4),
                    new DamageExpression(1, DiceShape.D4, 2)
                };

                damageCaused += opponant.TakeDamage(AttackType.Melee, hit, damageSpread);
            }

            damageCaused += DiceRoller.Roll(DiceShape.D4, 2);

            return((double)damageCaused / opponant.Health * 100);
        }
Ejemplo n.º 2
0
        public void GiveNameToActor(DiceRoller roller, Actor actor, string[] firstNames, string[] lastNames)
        {
            actor.IsProperName = true;
            string randomName = firstNames[roller.Roll(0, firstNames.Length)] + " " + lastNames[roller.Roll(0, lastNames.Length)];

            actor.Name = randomName;
        }
Ejemplo n.º 3
0
    public List <int> ArmyRoll(bool offense)
    {
        List <int> rolls = roller.Roll(GetNumberRolls(offense));

        rolls.Sort();
        return(rolls);
    }
Ejemplo n.º 4
0
        public void RollIsInRange()
        {
            var roller = new DiceRoller();

            var result = roller.Roll(100);

            result.Should().BeInRange(1, 100);
        }
Ejemplo n.º 5
0
        public void CanRollDice()
        {
            var roller = new DiceRoller();

            var result = roller.Roll(1);

            result.ShouldBeEquivalentTo(1);
        }
Ejemplo n.º 6
0
        public void CompoundRollWithShorthands()
        {
            const string expression = "d12+d8";
            var          result     = DiceRoller.Roll(expression);

            AssertRange(result.Total, 2, 20);
            Assert.AreEqual(0, result.Modifier);
            Assert.AreEqual(2, result.Rolls.Count);
        }
Ejemplo n.º 7
0
        public void SimpleRollShorthandUppercase()
        {
            const string expression = "D20";
            var          result     = DiceRoller.Roll(expression);

            AssertRange(result.Total, 1, 20);
            Assert.AreEqual(0, result.Modifier);
            Assert.AreEqual(1, result.Rolls.Count);
        }
Ejemplo n.º 8
0
        public void CompoundRoll()
        {
            const string expression = "1d20+2d6";
            var          result     = DiceRoller.Roll(expression);

            AssertRange(result.Total, 3, 32);
            Assert.AreEqual(0, result.Modifier);
            Assert.AreEqual(2, result.Rolls.Count);
        }
Ejemplo n.º 9
0
 public void DressArmy(DiceRoller roller, Actor actor)
 {
     actor.Doll.RemoveAllDecorations();
     actor.Doll.AddDecoration(DollPart.SKIN, MALE_SKINS[roller.Roll(0, MALE_SKINS.Length)]);
     actor.Doll.AddDecoration(DollPart.HEAD, GameImages.ARMY_HELMET);
     actor.Doll.AddDecoration(DollPart.TORSO, GameImages.ARMY_SHIRT);
     actor.Doll.AddDecoration(DollPart.LEGS, GameImages.ARMY_PANTS);
     actor.Doll.AddDecoration(DollPart.FEET, GameImages.ARMY_SHOES);
 }
Ejemplo n.º 10
0
        public void WhitespaceStress()
        {
            const string expression = "   1     d      20 +    5      ";
            var          result     = DiceRoller.Roll(expression);

            AssertRange(result.Total, 6, 25);
            Assert.AreEqual(5, result.Modifier);
            Assert.AreEqual(1, result.Rolls.Count);
        }
Ejemplo n.º 11
0
        public void MultiDigitNumber()
        {
            const string expression = "2895";
            var          result     = DiceRoller.Roll(expression);

            Assert.AreEqual(2895, result.Total);
            Assert.AreEqual(2895, result.Modifier);
            Assert.AreEqual(0, result.Rolls.Count);
        }
Ejemplo n.º 12
0
        public void ChainExpression()
        {
            // NOTE(istarnion): This is sort of an unintended feature.
            // discuss with users and see if this is actually something
            // we should reject as invalid syntax.
            const string expression = "1d1 - 1d1d100d100d100";
            var          result     = DiceRoller.Roll(expression);

            Assert.Positive(result.Total);
        }
Ejemplo n.º 13
0
        public async Task RollingDiceWithZeroSidesIsInvalid()
        {
            var rng = new FakeDiceRng {
                1, 2, 3
            };
            var         diceRoller = new DiceRoller(rng);
            Func <Task> task       = async() => await diceRoller.Roll("1d0");

            await task.Should().ThrowAsync <InvalidOperationException>();
        }
Ejemplo n.º 14
0
        public async Task RollingZeroDiceIsValid()
        {
            var rng = new FakeDiceRng {
                1, 2, 3
            };
            var diceRoller = new DiceRoller(rng);
            var result     = await diceRoller.Roll("0d6");

            result.ExpressionTotal.Should().Be(0);
            result.DiceRolls.Should().BeEmpty();
        }
        public int GetDamage()
        {
            var result = 0;

            if (NoOfDice > 0)
            {
                result += DiceRoller.Roll(Dice, NoOfDice);
            }

            return(result + ConstantDamage);
        }
Ejemplo n.º 16
0
        public async Task MultiplyingDiceByAConstantIsValid()
        {
            var rng = new FakeDiceRng {
                1, 2, 3
            };
            var diceRoller = new DiceRoller(rng);
            var result     = await diceRoller.Roll("2d6*2");

            result.ExpressionTotal.Should().Be(6);
            result.DiceRolls.Should().BeEquivalentTo(rng.Take(2));
        }
Ejemplo n.º 17
0
        public async Task DividingDiceByAConstantIsValid()
        {
            var rng = new FakeDiceRng {
                1, 2, 3
            };
            var diceRoller = new DiceRoller(rng);
            var result     = await diceRoller.Roll("3d6/2");

            result.ExpressionTotal.Should().Be(3);
            result.DiceRolls.Should().BeEquivalentTo(rng);
        }
Ejemplo n.º 18
0
        public async Task SubtractingAConstantFromDiceIsValid()
        {
            var rng = new FakeDiceRng {
                1, 2, 3
            };
            var diceRoller = new DiceRoller(rng);
            var result     = await diceRoller.Roll("2d6-10");

            result.ExpressionTotal.Should().Be(-7);
            result.DiceRolls.Should().BeEquivalentTo(rng.Take(2));
        }
Ejemplo n.º 19
0
        public async Task WhenNoCountIsSpecifiedOneDiceIsRolled()
        {
            var rng = new FakeDiceRng {
                1, 2, 3
            };
            var diceRoller = new DiceRoller(rng);
            var result     = await diceRoller.Roll("d6");

            result.ExpressionTotal.Should().Be(1);
            result.DiceRolls.Should().BeEquivalentTo(rng.Take(1));
        }
Ejemplo n.º 20
0
        public async Task ParenthesesTakePrecedence()
        {
            var rng = new FakeDiceRng {
                1, 2, 3
            };
            var diceRoller = new DiceRoller(rng);
            var result     = await diceRoller.Roll("(3d6+2)*2");

            result.ExpressionTotal.Should().Be(16);
            result.DiceRolls.Should().BeEquivalentTo(rng);
        }
Ejemplo n.º 21
0
        public async Task MultiplyingTakesPrecedenceOverAdding()
        {
            var rng = new FakeDiceRng {
                1, 2, 3
            };
            var diceRoller = new DiceRoller(rng);
            var result     = await diceRoller.Roll("3d6+2*2");

            result.ExpressionTotal.Should().Be(10);
            result.DiceRolls.Should().BeEquivalentTo(rng);
        }
Ejemplo n.º 22
0
        public async Task RollingSimpleDiceExpressionIsValid()
        {
            var rng = new FakeDiceRng {
                1, 2, 3
            };
            var diceRoller = new DiceRoller(rng);
            var result     = await diceRoller.Roll("3d6");

            result.ExpressionTotal.Should().Be(6);
            result.DiceRolls.Should().BeEquivalentTo(rng);
        }
Ejemplo n.º 23
0
        public async Task SubtractingTwoDiceIsValid()
        {
            var rng = new FakeDiceRng {
                1, 2, 3
            };
            var diceRoller = new DiceRoller(rng);
            var result     = await diceRoller.Roll("2d6-1d5");

            result.ExpressionTotal.Should().Be(0);
            result.DiceRolls.Should().BeEquivalentTo(rng);
        }
Ejemplo n.º 24
0
        public void GivenGameIsStarted_WhenPlayerRollsADie_ThenResultShouldBeBetweenOneAndSixInclusive()
        {
            // Arrange
            var validDices = new[] { 1, 2, 3, 4, 5, 6 };
            var diceRoller = new DiceRoller();

            // Act
            var dice = diceRoller.Roll();

            // Assert
            dice.Should().BeOneOf(validDices);
        }
Ejemplo n.º 25
0
        public string GenerateRain()
        {
            DiceRoller die    = new DiceRoller();
            int        select = die.Roll(1, 5);
            string     rain   = "";


            switch (select)
            {
            case 1:
                rain = "No Rain";
                break;

            case 2:
                rain = "Drizzle";
                break;

            case 3:
                rain = "Light Rain";
                break;

            case 4:
                rain = "Normal Rain";
                break;

            case 5:
                Boolean isStorm;
                if (die.Roll100() > 75)
                {
                    isStorm = true;
                }
                else
                {
                    isStorm = false;
                }
                if (isStorm)
                {
                    rain = "Tropical Storm";
                }
                else
                {
                    rain = "Heavy Rain";
                }
                break;

            default:
                rain = "Error in DayData.Day.GenerateRain()";
                break;
            }
            return(rain);
        }
Ejemplo n.º 26
0
        public void ExplicitPositiveExpression()
        {
            const string expression = "+1d20";

            try
            {
                var result = DiceRoller.Roll(expression);
                Assert.Positive(result.Total);
            }
            catch
            {
                Assert.Fail();
            }
        }
Ejemplo n.º 27
0
        public void NegativeExpression()
        {
            const string expression = "-1d20";

            try
            {
                var result = DiceRoller.Roll(expression);
                Assert.Negative(result.Total);
            }
            catch
            {
                Assert.Fail();
            }
        }
Ejemplo n.º 28
0
 /// <summary>
 /// Rolls all available dice in 'Game Components'
 /// </summary>
 public void Roll()
 {
     if (RemainingRolls == 0)
     {
         return;
     }
     State = State.Rolling;
     DiceRoller.Roll();
     RemainingRolls--;
     if (RemainingRolls == 0)
     {
         EndRolling();
     }
 }
Ejemplo n.º 29
0
        public void WhenRollingMultipleD12_ThenResultReflectsCorrectTypeAndCorrectResult()
        {
            var fakeDiceResult   = 12;
            var numberOfDice     = 3;
            var expectedDiceType = DiceType.d12;

            _rng.Setup(i => i.Next(It.IsAny <int>(), It.IsAny <int>())).Returns(fakeDiceResult);
            var result = _diceRoller.Roll(expectedDiceType, numberOfDice);

            var expectedTotal = fakeDiceResult * numberOfDice;

            Assert.AreEqual(3, result.Results.Count(i => i.DiceType == DiceType.d12));
            Assert.AreEqual(expectedTotal, result.Total);
        }
Ejemplo n.º 30
0
        public IEnumerator DiceCheck()
        {
            // Wait for scene to load
            yield return(null);

            // Roll the dice once
            DiceRoller   diceRoller   = GameObject.FindObjectOfType <DiceRoller>();
            StateManager stateManager = GameObject.FindObjectOfType <StateManager>();

            diceRoller.Roll();
            yield return(new WaitForSeconds(6));

            // Check the result is collected correctly
            Assert.IsTrue(stateManager.LastRollResult >= 1);
        }