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); }
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; }
public List <int> ArmyRoll(bool offense) { List <int> rolls = roller.Roll(GetNumberRolls(offense)); rolls.Sort(); return(rolls); }
public void RollIsInRange() { var roller = new DiceRoller(); var result = roller.Roll(100); result.Should().BeInRange(1, 100); }
public void CanRollDice() { var roller = new DiceRoller(); var result = roller.Roll(1); result.ShouldBeEquivalentTo(1); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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>(); }
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); }
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)); }
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); }
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)); }
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)); }
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); }
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); }
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); }
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); }
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); }
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); }
public void ExplicitPositiveExpression() { const string expression = "+1d20"; try { var result = DiceRoller.Roll(expression); Assert.Positive(result.Total); } catch { Assert.Fail(); } }
public void NegativeExpression() { const string expression = "-1d20"; try { var result = DiceRoller.Roll(expression); Assert.Negative(result.Total); } catch { Assert.Fail(); } }
/// <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(); } }
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); }
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); }