public HDDialog(Context context, string HD) : base(context) { _DieRoll = DieRoll.FromString(HD); RequestWindowFeature((int)WindowFeatures.NoTitle); SetContentView(Resource.Layout.HDDialog); SetCanceledOnTouchOutside(true); Window.SetSoftInputMode(SoftInput.StateHidden); EditText et = FindViewById <EditText>(Resource.Id.modText); et.Text = _DieRoll.mod.ToString(); et.TextChanged += (object sender, Android.Text.TextChangedEventArgs e) => { int val; if (int.TryParse(et.Text, out val)) { _DieRoll.mod = val; } }; ((Button)FindViewById(Resource.Id.cancelButton)).Click += (object sender, EventArgs e) => { Dismiss(); }; ((Button)FindViewById(Resource.Id.okButton)).Click += (object sender, EventArgs e) => { Dismiss(); FireOk(); }; SetupDice(); }
protected void Page_Load(object sender, EventArgs e) { // create a dictionary to use as a rollable table Dictionary <int, string> d = new Dictionary <int, string>(); d.Add(4, "Orc"); d.Add(8, "Goblin"); d.Add(9, "Hobgoblin"); d.Add(12, "Kobold"); d.Add(16, "Gnoll"); d.Add(20, "Derro"); // roll d20 10x; each time get the first item whose key is >= the roll result, and append it to a string StringBuilder sb = new StringBuilder(); for (int i = 0; i < 10; i++) { int roll = DieRoll.Roll("d20"); foreach (int key in d.Keys) { if (key >= roll) { sb.Append(", "); sb.Append(d[key]); break; } } } Label1.Text = sb.ToString(2, sb.Length - 2); }
public static void DetermineHP(Character character) { Console.WriteLine("Would you like to roll for your HP or take the average?"); CLIHelper.Print2Choices("Take average", "Roll"); int input = CLIHelper.GetNumberInRange(1, 2); int firstLvlHP = character.HitDie + character.ConMod; int remainingLvls = character.Lvl - 1; if (input == 1) { int hitDieAvg = (character.HitDie / 2) + 1; character.HP += firstLvlHP + (remainingLvls * (hitDieAvg + character.ConMod)); } else { DieRoll hitDie = new DieRoll(character.HitDie); int HP = firstLvlHP; for (int i = 0; i < remainingLvls; i++) { HP += (hitDie.RollDie() + character.ConMod); } character.HP += HP; } }
public static short Generate(string orbitType, int size) { int dieRoll = DieRoll.Roll2D6() - 7 + size; if (orbitType.Equals(OrbitTypes.Inner)) { dieRoll -= 2; } if (orbitType.Equals(OrbitTypes.Outer)) { dieRoll -= 4; } if (size == 0) { dieRoll = 0; } if (dieRoll < 1) { dieRoll = 0; } return((short)dieRoll); }
public static void Assign(List <Orbit> orbits, int numberToAssign, string assignmentType, int rollAdjustment = 0) { int i = numberToAssign; int hitCount = 0; while (i > 0) { int roll = DieRoll.Roll2D6() + rollAdjustment; if (roll > SystemConstants.MaxOrbits) { roll = SystemConstants.MaxOrbits - 1; } var orbit = orbits[roll]; if (orbit.OccupiedType is null) { orbit.OccupiedType = assignmentType; i--; } else { hitCount++; if (hitCount > 100) { //Give up and don't place empty orbits. break; } } } }
public static short Generate() { int dieRoll = DieRoll.Roll2D6(); switch (dieRoll) { case 2: return(0); case 3: return(0); case 4: return(1); case 5: return(2); case 6: return(3); case 7: return((short)(4 + DieRoll.Roll1D6())); case 8: return((short)(5 + DieRoll.Roll1D6())); case 9: return((short)(6 + DieRoll.Roll1D6())); case 10: return((short)(7 + DieRoll.Roll1D6())); case 11: return((short)(8 + DieRoll.Roll1D6())); case 12: return(99); } throw new Exception("Unexpected die roll"); }
public static DieRoll[] GetSetOfRolls(DieRoll DieRoll, int repetitions) { if (repetitions < 1) { throw new ArgumentException("Idiot, you can't have something repeated {0} times", repetitions.ToString()); } if (repetitions > maxDice) { repetitions = maxDice; } DieRoll[] rollSet = new DieRoll[5]; GetRollArray(DieRoll, repetitions).CopyTo(rollSet, 0); for (int i = 0; i < repetitions; i++) { rollSet[i] = DieRoll; } if (repetitions == maxDice) { return(rollSet); } for (int i = repetitions; i < maxDice; i++) { rollSet[i] = (DieRoll)DiceHelper.GetRollExcept(DieRoll); } return(rollSet); }
private DieRollResult GetResult(DieRoll die) { var diceSet = new DiceRoll(FakeDiceRollFactory.GetSetOfRolls(die, 3)); var threeOfAKind = new ThreeOfAKindRule(); return(threeOfAKind.CountPoints(diceSet)); }
public static short Generate(short orbit, string stellarClassification) { int dieRoll = DieRoll.Roll2D6() - 2; if (orbit == 0) { dieRoll -= 5; } if (orbit == 1) { dieRoll -= 4; } if (orbit == 2) { dieRoll -= 2; } if (stellarClassification == StellarClassifications.M) { dieRoll -= 2; } if (dieRoll < 1) { dieRoll = 0; } return((short)dieRoll); }
public AttackRollResult(Attack atk) { _Attack = atk; _Name = atk.Name; Rolls = new List <SingleAttackRoll>(); if (atk.Weapon != null) { _Name = atk.Weapon.Name; } int totalAttacks = atk.Count * atk.Bonus.Count; for (int atkcount = 0; atkcount < atk.Count; atkcount++) { foreach (int mod in atk.Bonus) { SingleAttackRoll sr = new SingleAttackRoll(); DieRoll roll = new DieRoll(1, 20, mod); sr.Result = roll.Roll(); sr.Damage = atk.Damage.Roll(); if (atk.Plus != null) { Regex plusRegex = new Regex("(?<die>[0-9]+d[0-9]+((\\+|-)[0-9]+)?) (?<type>[a-zA-Z]+)"); Match dm = plusRegex.Match(atk.Plus); if (dm.Success) { DieRoll bonusRoll = DieRoll.FromString(dm.Groups["die"].Value); BonusDamage bd = new BonusDamage(); bd.Damage = bonusRoll.Roll(); bd.DamageType = dm.Groups["type"].Value; sr.BonusDamage.Add(bd); } } if (sr.Result.Rolls[0].Result >= atk.CritRange) { sr.CritResult = roll.Roll(); sr.CritDamage = new RollResult(); for (int i = 1; i < atk.CritMultiplier; i++) { RollResult crit = atk.Damage.Roll(); sr.CritDamage = crit + sr.CritDamage; } } Rolls.Add(sr); } } }
private static bool IsSystemPresent(SubsectorDensity density) { int roll; switch (density) { case SubsectorDensity.Rift: roll = DieRoll.Roll2D6(); if (roll == 12) { return(true); } break; case SubsectorDensity.Sparse: roll = DieRoll.Roll1D6(); if (roll == 6) { return(true); } break; case SubsectorDensity.Scattered: roll = DieRoll.Roll1D6(); if (roll >= 5) { return(true); } break; case SubsectorDensity.Standard: roll = DieRoll.Roll1D6(); if (roll >= 4) { return(true); } break; case SubsectorDensity.Dense: roll = DieRoll.Roll1D6(); if (roll >= 3) { return(true); } break; } return(false); }
void RollButtonClicked(object sender, EventArgs e) { DieRoll r = DieRoll.FromString(_DieText); AddRoll(r); RenderResults(); }
void Roll() { EditText dieText = View.FindViewById <EditText>(Resource.Id.rollText); DieRoll roll = DieRoll.FromString(dieText.Text); Roll(roll); }
public void RollSave(Monster.SaveType type, Character ch) { int? save = ch.Monster.GetSave(type); int mod = (save == null)?0:save.Value; DieRoll roll = new DieRoll(1, 20, mod); AddRoll(Monster.GetSaveText(type) + ": ", roll); }
public void AwardsAHundredPointsMultipliedByTheNumberOnTheDie(DieRoll die) { int points = _pointsBase * (int)die; var result = GetResult(die); Assert.True(result.Points == points, $"Awarded {result.Points}, was {((int)die)}, should be {points}"); }
public ObtainingAHighStraight() { var dice = new DieRoll[] { DieRoll.Two, DieRoll.Four, DieRoll.Three, DieRoll.Five, DieRoll.Six }; var diceSet = new DiceRoll(dice); var rule = new StraightRule(); result = rule.CountPoints(diceSet); }
public void FromStringTest() { string st = "2d8-1"; DieRoll expected = new DieRoll(2, 8, -1); DieRoll actual = DieRoll.FromString(st); Assert.AreEqual(expected.ToString(), actual.ToString()); }
public void DieRollConstructorTest1() { string roll = "2d6"; DieRoll target = new DieRoll(roll); Assert.AreEqual(2, target.DieCount); Assert.AreEqual(6, target.DieSides); }
public void DieRollConstructorTest() { int dice = 3; int sides = 8; int modifier = -1; // TODO: Initialize to an appropriate value DieRoll dr = new DieRoll(dice, sides, modifier); Assert.IsTrue(dr.Dice == dice && dr.Sides == sides && dr.Modifier == modifier); }
private static DieRoll[] GetRollArray(DieRoll dieRoll, int repetitions) { DieRoll[] rollSet = new DieRoll[repetitions]; for (int i = 0; i < repetitions; i++) { rollSet[i] = dieRoll; } return(rollSet); }
private static DieRoll[] GetRandomRolls(int repetitions, DieRoll[] except) { DieRoll[] rollSet = new DieRoll[repetitions]; for (int i = repetitions; i < maxDice; i++) { rollSet[i] = (DieRoll)DiceHelper.GetRollExcept(except); } return(rollSet); }
public RollResult Roll(string dieRollString) { DieRoll dr = new DieRoll(dieRollString); RollResult result = new RollResult(); result.DieRollString = dieRollString; result.RolledValue = dr.Roll(); return(result); }
public void Awards1000PtsForAllRolls(DieRoll dice) { var diceSet = FakeDiceRollFactory.GetSetOfRolls(dice, 4); var fourOfAKind = new FourOfAKindRule(); var result = fourOfAKind.CountPoints(new DiceRoll(diceSet)); Assert.True(result.Points == _points); }
protected override void Read(CelesteNetBinaryReader reader) { data = new(); data.rolls = new int[reader.ReadInt32()]; for (int i = 0; i < data.rolls.Length; i++) { data.rolls[i] = reader.ReadInt32(); } }
public void DieRollConstructorTest() { const int dieCount = 2; const int dieSides = 6; DieRoll target = new DieRoll(dieCount, dieSides); Assert.AreEqual(dieCount, target.DieCount); Assert.AreEqual(dieSides, target.DieSides); }
public void ToStringTest() { string roll = "2d6"; DieRoll target = new DieRoll(roll); // TODO: Initialize to an appropriate value string expected = string.Empty; // TODO: Initialize to an appropriate value var actual = target.ToString(); Assert.AreEqual(roll, actual); }
public void CanBeAchievedByFourOfAnyRoll(DieRoll dice) { var diceSet = FakeDiceRollFactory.GetSetOfRolls(dice, 4); var fourOfAKind = new FourOfAKindRule(); var result = fourOfAKind.CountPoints(new DiceRoll(diceSet)); Assert.True(result.DiceCombination == _combination); }
public void CanBeAchievedByFiveOfAnyRoll(DieRoll dice) { var diceSet = new DiceRoll(FakeDiceRollFactory.GetSetOfRolls(dice, 5)); var fiveOfAKind = new FiveOfAKindRule(); var result = fiveOfAKind.CountPoints(diceSet); Assert.True(result.Points == _points); }
public void Awards1500PtsForAllRolls(DieRoll dice) { var diceSet = new DiceRoll(FakeDiceRollFactory.GetSetOfRolls(dice, 5)); var fiveOfAKind = new FiveOfAKindRule(); var result = fiveOfAKind.CountPoints(diceSet); Assert.True(result.Points == _points); }
protected void ButtonRoll_Click(object sender, EventArgs e) { DieRoll dr = DieRoll.FromString(TextDieRoll.Text); int rollCount; try { rollCount = Convert.ToInt32(TextRollCount.Text); } catch (Exception ex) { rollCount = 1; } if (rollCount > 0) { DieRollResults results = Roll(dr, rollCount); StringBuilder sb = new StringBuilder(); sb.Append("Minimum, Maximum, Average for "); sb.Append(dr.ToString()); sb.Append(": "); sb.Append(dr.Minimum.ToString()); sb.Append(", "); sb.Append(dr.Maximum.ToString()); sb.Append(", "); sb.Append(dr.Average.ToString()); sb.Append("<br />Roll results: "); sb.Append(results.ToString()); sb.Append("<br />Sorted: "); sb.Append(results.Sorted().ToString()); sb.Append("<br />Reversed: "); sb.Append(results.Sorted(DieRollResults.SortOrder.Descending).ToString()); sb.Append("<br />Lowest, Highest, Average rolled: "); sb.Append(results.Lowest.ToString()); sb.Append(", "); sb.Append(results.Highest.ToString()); sb.Append(", "); sb.Append(results.Average.ToString()); if (rollCount > 3) { results.KeepBest(3); sb.Append("<br />Top 3 rolls: "); sb.Append(results.ToString()); sb.Append(", total "); sb.Append(results.Total.ToString()); } LabelResult.Text = sb.ToString(); } else { LabelResult.Text = "Number of Rolls must be a positive integer."; } }