public void Test_BasicAttack_AbilityScoreRangedWeaponCombinations(int strength, int constitution, int dexterity, int intelligence, RangedType type, WeaponHandedness handedness, WeaponWeight weight, int expectedAttackBonus, int expectedDamageDiceCount, DiceType expectedDamageDiceType, int expectedDamageBonus, int expectedRange) { Character character; BasicAttack basicAttack; character = new Character(new int[] { strength, constitution, dexterity, intelligence }, new NullOrigin(ScoreType.Wisdom), new NullOrigin(ScoreType.Charisma), ScoreType.Acrobatics); character.SetHeldItem(Hand.Main, new RangedWeapon(type, handedness, weight)); character.Update(); basicAttack = character.GetPowers().First(x => x is BasicAttack) as BasicAttack; Assert.That(basicAttack, !Is.Null, "Basic Attack is null"); Assert.That(basicAttack.Attacks.Count, Is.EqualTo(1), "Incorrect number of Basic Attack attacks"); Assert.That(basicAttack.Attacks[0].AttackBonus.Total, Is.EqualTo(expectedAttackBonus), string.Format("Incorrect Basic Attack attack bonus: {0}", basicAttack.Attacks[0].AttackBonus)); Assert.That(basicAttack.Attacks[0].Damage.Dice, Is.EqualTo(new Dice(expectedDamageDiceCount, expectedDamageDiceType)), "Incorrect Basic Attack damage"); Assert.That(basicAttack.Attacks[0].DamageBonus.Total, Is.EqualTo(expectedDamageBonus), string.Format("Incorrect Basic Attack damage bonus: {0}", basicAttack.Attacks[0].DamageBonus)); Assert.That(basicAttack.AttackTypeAndRange.AttackType, Is.EqualTo(AttackType.Ranged), "Incorrect Basic Attack attack type"); Assert.That(basicAttack.AttackTypeAndRange.Range, Is.EqualTo(expectedRange.ToString()), "Incorrect Basic Attack range"); }
public static int Throw(DiceType diceType) { /*byte[] array = new byte[1]; System.Security.Cryptography.RandomNumberGenerator.Create().GetNonZeroBytes(array); return (array[0] % (int)diceType) + 1;*/ return randomClass.Next(1,(int)diceType + 1); }
public static int Roll (int number, DiceType type, int modify) { int result = modify; for (int i = 0; i < number; i++) { result += Dice.Roll ((int)type); } return result; }
public void TestRepresentation(int number, DiceType diceType, string expectedToString, int minRoll, int maxRoll) { Dice dice = new Dice(number, diceType); Assert.That(dice.ToString(), Is.EqualTo(expectedToString)); Assert.That(dice.MinRoll, Is.EqualTo(minRoll), "Incorrect minimum roll"); Assert.That(dice.MaxRoll, Is.EqualTo(maxRoll), "Incorrect maximum roll"); }
/// <summary> /// Return a value equal to the roll of a die. /// </summary> /// <param name="type"></param> /// <returns></returns> public int Dice(DiceType? type = null) { var diceTypes = EnumExtensions.GetEnumValues<DiceType>().ToList(); type = type.HasValue ? type.Value : Pick(diceTypes); var max = (int)type.Value; return Natural(1, max); }
public void Game_can_be_started_with_normal_dice_or_crooked_dice(DiceType diceType) { var gameSetting = new GameSetting { BoardSetting = new BoardSetting { Min = 1, Max = 100 }, MaxPlayersAllowed = 1, MinPlayersNeeded = 1, TotalTurns = 1 }; var dice = new DiceFactory().Create(diceType); var player = new Player { Id = "p123" }; int playerOriginalPosition = player.CurrentPosition; var playerProgressListnerMock = new Mock <IPlayerProgressListener>(); playerProgressListnerMock.Setup(x => x.OnPlayed(It.IsAny <PlayerMoveResult>())) .Callback((PlayerMoveResult playerResult) => { playerResult.Should().NotBeNull(); playerResult.NewPosition.Should().BeGreaterThan(playerOriginalPosition); playerResult.Status.Should().Be(MoveStatus.Moved); }); var endGameListnerMock = new Mock <IEndGameListener>(); endGameListnerMock.Setup(x => x.OnEndGame(It.IsAny <GameResult>())) .Callback((GameResult gameResult) => { var playerResult = gameResult.PlayerResults.FirstOrDefault(x => x.Key.Equals(player)); playerResult.Should().NotBeNull(); playerResult.Value.NewPosition.Should().BeGreaterThan(playerOriginalPosition); playerResult.Value.Status.Should().Be(MoveStatus.Moved); }); var game = new Game(dice, gameSetting, endGameListnerMock.Object); game.AddPlayer(player); game.RegisterPlayerProgressListener(playerProgressListnerMock.Object); game.Start(); endGameListnerMock.Setup(x => x.OnEndGame(It.IsAny <GameResult>())) .Callback((GameResult gameResult) => { var playerResult = gameResult.PlayerResults.FirstOrDefault(x => x.Key.Equals(player)); playerResult.Value.Status.Should().Be(MoveStatus.Stopped); }); game.Stop(); }
private void ShowDice(IList <int> results, DiceType dice) { this.DiceResults.Controls.Clear(); foreach (var die in results) { var face = new DiceFace(); face.Height = face.Width = this.DiceResults.Height > 200 ? 200 : this.DiceResults.Height - 10; face.SetNumber(dice, die); this.DiceResults.Controls.Add(face); } }
// INIT private void init(int size, DiceType type, ref NPack.MersenneTwister _rand) { _result = new int[size]; _dice_type = type; _size = size; for (int i = 0; i < _size; i++) { // Cast enum to int to get the value _result[i] = _rand.Next( 1, (int) type); } }
public List<int> Roll(DiceType diceType, int numberOfDice) { List<int> listOfRolls = new List<int>(); for (int i = 1; i < numberOfDice; i++) { listOfRolls.Add(Roll(diceType)); } return listOfRolls; }
private static IDiceComparer GetComparer(DiceType diceType) { var diceComparerLookup = new Dictionary <DiceType, IDiceComparer>() { { DiceType.SameColor, new SameColorDiceComparer() }, { DiceType.NoPoints, new NoPointsDiceComparer() }, { DiceType.NormalPoints, new NormalPointsDiceComparer() } }; return(diceComparerLookup[diceType]); }
public void Dice_ShouldBeInRange_OfSpecifiedType(DiceType type, int expectedMin, int expectedMax) { // Arrange // Act var result = _sut.Dice(type); // Assert Assert.IsNotNull(result); result.ShouldBeInRange(expectedMin, expectedMax); }
// INIT private void init(int size, DiceType type, ref NPack.MersenneTwister _rand) { _result = new int[size]; _dice_type = type; _size = size; for (int i = 0; i < _size; i++) { // Cast enum to int to get the value _result[i] = _rand.Next(1, (int)type); } }
public static DiceType IntToDiceType(int index) { DiceType diceType = DiceType.Zero; switch (index) { case 0: diceType = DiceType.Zero; break; case 1: diceType = DiceType.One; break; case 2: diceType = DiceType.D2; break; case 3: diceType = DiceType.D3; break; case 4: diceType = DiceType.D4; break; case 5: diceType = DiceType.D6; break; case 6: diceType = DiceType.D8; break; case 7: diceType = DiceType.D10; break; case 8: diceType = DiceType.D12; break; case 9: diceType = DiceType.D20; break; case 10: diceType = DiceType.D100; break; } return(diceType); }
/*************************************************************/ /* Functionality */ /*************************************************************/ #region Methods #region Constructors // -------------------- /// <summary> /// Constructor for a dice object /// </summary> /// /// <param name="initialFaceValue"> /// Optional face value of the new dice /// </param> /// /// <param name="initialStatus"> /// Optional status of the new dice of type /// "enum DiceStatus" /// </param> /// /// <exception cref="ArgumentOutOfRangeException"> /// Thrown when trying to set the dice value outside the /// valid range of dice face values. /// </exception> /// /// <returns> /// Nothing. This is a constructor. /// </returns> public Dice( int initialFaceValue = MIN_FACE_VALUE, DiceType initialType = DiceType.Rollable, Image initialImage = null, Availability initialAvailability = Availability.Available, UpdateImageSource initialImageModifier = null) { this.faceValue = initialFaceValue; this.type = initialType; this.imageControl = initialImage; this.availability = initialAvailability; updateImageDelegate = initialImageModifier; }
public static int Roll(int numberOfDice, DiceType type) { int TotalRolled = 0; for (int i = 0; i < numberOfDice; i++) { //this generates a randomly seeded random number generator - avoids duplicate random numbers Random rnd = new Random(Guid.NewGuid().GetHashCode()); //add 1 as random will generate a number between 0 and 1 less than the max TotalRolled += rnd.Next((int)type) + 1; } return(TotalRolled); }
public static string GetDiceValueString(int diceCount, DiceType type, int bonus = 0) { StringBuilder sb = new StringBuilder(); sb.Append(diceCount); sb.Append(type.ToString()); if (bonus != 0) { sb.Append(GetSignedValueString(bonus, true)); } return(sb.ToString()); }
public Dice Create(DiceType diceType) { switch (diceType) { case DiceType.Random: return(new RandomDice()); case DiceType.RandomCrooked: return(new RandomCrookedDice()); } throw new NotSupportedException($"{diceType.ToString()} is not a supported device"); }
public override void OnRollEnd(int number, DiceType type, Poring poring = null) { stepWalking = number; state = DokaponGameState.plan; SetCamera(CameraType.TopDown); panelStepRemain.SetActive(true); ParseMovableNode(); DisplayNodeHeat(); bgm.ChangeVolume(0.5f); }
static bool Prefix(ref int __result, int rolls, DiceType dice) { switch (dice) { case DiceType.Zero: __result = 0; break; case DiceType.One: __result = 1; break; case DiceType.D2: __result = BucketWrapper.D2.Result(rolls); break; case DiceType.D3: __result = BucketWrapper.D3.Result(rolls); break; case DiceType.D4: __result = BucketWrapper.D4.Result(rolls); break; case DiceType.D6: __result = BucketWrapper.D6.Result(rolls); break; case DiceType.D8: __result = BucketWrapper.D8.Result(rolls); break; case DiceType.D10: __result = BucketWrapper.D10.Result(rolls); break; case DiceType.D12: __result = BucketWrapper.D12.Result(rolls); break; case DiceType.D20: __result = BucketWrapper.D20.Result(rolls); break; case DiceType.D100: __result = BucketWrapper.D100.Result(rolls); break; } //Main.Mod.Debug(__result); return(false); }
public static bool IsDiceAviliable(this Player player, DiceType diceType) { if (player == null) { throw new ArgumentNullException(nameof(player)); } if (!Enum.IsDefined(typeof(DiceType), diceType)) { throw new ArgumentOutOfRangeException(nameof(diceType), "Value should be defined in the DiceType enum."); } //todo: return(player.DiceList.ContainsKey(diceType) && player.DiceList [diceType] != 0); }
public Dice GetDice(DiceType diceType) { Dice dice = null; switch (diceType) { case DiceType.Red: if (_stack_RedDice.Count == 0) { MakeDice(DiceType.Red, 1); } dice = _stack_RedDice.Pop(); break; case DiceType.Blue: if (_stack_BlueDice.Count == 0) { MakeDice(DiceType.Blue, 1); } dice = _stack_BlueDice.Pop(); break; case DiceType.Green: if (_stack_GreenDice.Count == 0) { MakeDice(DiceType.Green, 1); } dice = _stack_GreenDice.Pop(); break; case DiceType.Purple: if (_stack_PurpleDice.Count == 0) { MakeDice(DiceType.Purple, 1); } dice = _stack_PurpleDice.Pop(); break; case DiceType.Yellow: if (_stack_YellowDice.Count == 0) { MakeDice(DiceType.Yellow, 1); } dice = _stack_YellowDice.Pop(); break; } return(dice); }
public DiceWithValue(DiceType diceType, int value) { if (!Enum.IsDefined(typeof(DiceType), diceType)) { throw new ArgumentOutOfRangeException(nameof(diceType), "Value should be defined in the DiceType enum."); } if (value <= 0 || value > ( int )diceType) { throw new ArgumentOutOfRangeException(nameof(value)); } DiceType = diceType; Value = value; }
/// <summary> /// 请求大富翁掷色子 /// </summary> /// <param name="diceType"></param> /// <param name="callBack"></param> public static void NotifyServerDice(DiceType diceType, Action <SCDiceResult> callBack) { CSDice cSDice = new CSDice(); cSDice.Dice = diceType; ProtocalManager.Instance().SendCSDice(cSDice, (SCDiceResult sCDiceResult) => { Debug.Log("请求大富翁掷色子成功!"); callBack?.Invoke(sCDiceResult); }, (ErrorInfo er) => { Debug.Log("请求大富翁掷色子失败!err:" + er.ErrorMessage); callBack?.Invoke(null); }); }
private static IComparer <Dice> GetComparer(DiceType type) { switch (type) { case DiceType.OneColor: //1 > 4 > 6 > 5 > 3 > 2 return(new OneColorComparer()); case DiceType.NormalPoints: return(new NormalPointsComparer()); case DiceType.NoPoints: return(new NoPointsComparer()); } return(null); }
/// <summary> /// Click handler for the Roll button for basic dice definition. /// </summary> /// <param name="sender">sender</param> /// <param name="e">event args</param> private void RollButton_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e) { // first clear any expression in the dice service this.diceService.Clear(); // setup the dice expression DiceType diceType = (DiceType)this.DiceTypeCombobox.SelectedItem; this.diceService.Dice(diceType.DiceSides, (int)this.DiceNumberNumeric.Value); this.diceService.Constant((int)this.DiceModifierNumeric.Value); // roll the dice and save the results DiceResult result = this.diceService.Roll(this.dieRoller); this.DiceRollResults.Insert(0, result); }
public static DiceType SearchDiceType(string diceTypeName) { DiceType returnDiceType = null; GameObject diceTypeManager = GameObject.Find("DiceTypeManager"); foreach (DiceType dT in diceTypeManager.GetComponents <DiceType>()) { if (dT.GetName().Contains(diceTypeName)) { returnDiceType = dT; } } return(returnDiceType); }
public async Task <int> RollTheDice(int times, DiceType diceType, int modifier) { int amount = 0; if (times == 0) { return(amount); } for (int i = 0; i < times; i++) { amount += randomGenerator.Next((int)diceType); } return(await Task.FromResult(amount + modifier)); }
public void ChangeDice(string diceType) { DiceType myDiceType = DiceManager.SearchDiceType(diceType); if (myDiceType != null) { this.gameObject.SetActive(true); this.GetComponent <Animator>().runtimeAnimatorController = myDiceType.GetAnimationController(); m_OnDiceStopped = myDiceType.GetOnStoppedEvent(); m_OnAttack = myDiceType.GetOnAttackEvent(); m_OnStatusEffect = myDiceType.GetOnStatusEvent(); } else { this.gameObject.SetActive(false); } }
public DiceRollView Create(DiceType diceType, int index) { switch (diceType) { case DiceType.D3: return(_diceRollD3.Create(index)); case DiceType.D6: return(_diceRollD6.Create(index)); case DiceType.D8: return(_diceRollD8.Create(index)); default: throw new ArgumentOutOfRangeException(); } }
public static int Roll(int totalDice, DiceType diceType) { int result = 0; switch (diceType) { case DiceType.D4: result = Roll(totalDice, 4); break; case DiceType.D6: result = Roll(totalDice, 6); break; case DiceType.D8: result = Roll(totalDice, 8); break; case DiceType.D10: result = Roll(totalDice, 10); break; case DiceType.D12: result = Roll(totalDice, 12); break; case DiceType.D20: result = Roll(totalDice, 20); break; case DiceType.D24: result = Roll(totalDice, 24); break; case DiceType.D30: result = Roll(totalDice, 30); break; default: result = Roll(totalDice, 6); break; } return(result); }
/// <summary>AbilityRankType is only relevant for ContextValueType.Rank</summary> public static ContextDiceValue CreateContextDiceValue(DiceType Dx, ContextValueType diceType = ContextValueType.Simple, AbilityRankType diceRank = AbilityRankType.Default, int diceValue = 0, ContextValueType bonusType = ContextValueType.Simple, AbilityRankType bonusRank = AbilityRankType.Default, int bonusValue = 0) { var result = new ContextDiceValue(); result.DiceType = Dx; result.DiceCountValue = new ContextValue(); result.DiceCountValue.ValueType = diceType; result.DiceCountValue.ValueRank = diceRank; result.DiceCountValue.Value = diceValue; result.BonusValue = new ContextValue(); result.BonusValue.ValueType = bonusType; result.BonusValue.ValueRank = bonusRank; result.BonusValue.Value = bonusValue; return(result); }
public virtual void TestAttackPower(Type type, int attack, int attackBonus, int damageDiceCount, DiceType damageDiceType, int damageBonus, string additionalText) { AttackPower attackPower; attackPower = Character.GetPowers().Where(x => (x.GetType() == type)).First() as AttackPower; Assert.NotNull(attackPower, "Attack power not found"); Assert.GreaterOrEqual(attack, 0, "Attack index is negative"); Assert.Less(attack, attackPower.Attacks.Count, "Attack index is greater than the number of the power's attacks"); Assert.AreEqual(attackBonus, attackPower.Attacks[attack].AttackBonus.Total, "Attack bonuses differ"); if (damageDiceCount > 0) { Assert.AreEqual(damageDiceCount, attackPower.Attacks[attack].Damage.Dice.Number, "Damage dice count differs"); Assert.AreEqual(damageDiceType, attackPower.Attacks[attack].Damage.Dice.DiceType, "Damage dice type differs"); Assert.AreEqual(damageBonus, attackPower.Attacks[attack].DamageBonus.Total, "Damage differs"); } Assert.AreEqual(additionalText, attackPower.Attacks[attack].AdditionalText, "Additional text differs"); }
public void AddDice(DiceType diceType) { switch (diceType) { case DiceType.D3: _d3.Value++; break; case DiceType.D6: _d6.Value++; break; case DiceType.D8: _d8.Value++; break; default: throw new ArgumentOutOfRangeException(); } }
private void FreezeOnRoll(int num) { Dice.LastDiceClicked().GetComponent <Animator>().enabled = false; DiceType myDiceType = DiceManager.SearchDiceType("Poison"); List <Sprite> freezeSprites = myDiceType.GetFreezeSprites(); Sprite freezeSprite = null; foreach (Sprite s in freezeSprites) { if (s.name.Contains(num.ToString())) { freezeSprite = s; } } Dice.LastDiceClicked().GetComponent <Image>().sprite = freezeSprite; }
public void SetAnimations(DiceType diceType, Animations.EditAnimationSet animationSet) { if (animationSet.animations == null) { animationSet.animations = new List <Animations.EditAnimation>(); } if (animationSet.animations.Count == 0) { animationSet.animations.Add(new Animations.EditAnimation()); } // Drop current animation _animIndex = -1; // Store animation set DiceType = diceType; _animationSet = animationSet; RefreshNames(); ShowAnimation(0); }
public int GetSynergyCount(DiceType type) { switch (type) { case DiceType.Red: return(_redSynergy.Count); case DiceType.Blue: return(_blueSynergy.Count); case DiceType.Green: return(_greenSynergy.Count); case DiceType.Purple: return(_purpleSynergy.Count); case DiceType.Yellow: return(_yellowSynergy.Count); } return(0); }
/// <summary> /// 当前选中的骰子的下标 /// </summary> /// <param name="index"></param> private void CurSelectDice(int index) { switch (index) { case 0: _selectDiceType = DiceType.LowDice; break; case 1: _selectDiceType = DiceType.PureDice; break; case 2: _selectDiceType = DiceType.HighDice; break; default: _selectDiceType = DiceType.PureDice; break; } Debug.Log("当前选中的骰子的下标 index = " + index); }
public void Collabo() { StopAttackCoroutine(); lv++; damage = (int)((Mathf.Pow(lv, 2) * 2) + 1); attackSpeed = _attackSpeed - lv * 0.1f; int randomType = Random.Range(0, (int)DiceType.None); diceType = (DiceType)randomType; Color c; if (ColorUtility.TryParseHtmlString(InGameManager.instance.DiceColorHexCode[randomType], out c) == false) { return; } _diceColor.color = c; int len = _diceLv.Length; for (int i = 0; i < len; i++) { _diceLv[i].SetActive(false); } SpriteRenderer[] srs = _diceLv[lv].GetComponentsInChildren <SpriteRenderer>(); int srLen = srs.Length; for (int i = 0; i < srLen; i++) { srs[i].color = c; } _diceLv[lv].SetActive(true); }
public static int Roll (DiceType type) { return Dice.Roll (1, type, 0); }
public static int Roll (int number, DiceType type) { return Dice.Roll (number, type, 0); }
public override void TestAttackPower(Type type, int attack, int attackBonus, int damageDiceCount, DiceType damageDiceType, int damageBonus, string additionalText) { base.TestAttackPower(type, attack, attackBonus, damageDiceCount, damageDiceType, damageBonus, additionalText); }
public static int Roll (DiceType type, int modify) { return Dice.Roll (1, type, modify); }
public static int RollDice(DiceType dice) { return Rand.Next(0, (int) dice) + 1; }
public void TestExpectedDamageDice(RangedType rangedType, WeaponHandedness handedness, WeaponWeight weight, int expectedNumber, DiceType expectedDiceType) { Assert.That(new RangedWeapon(rangedType, handedness, weight).Damage, Is.EqualTo(new Dice(expectedNumber, expectedDiceType))); }
public int Roll(DiceType diceType) { return Random((byte) diceType); }
// CONSTRUCTOR public DiceRoll(int size, DiceType type, ref NPack.MersenneTwister _rand) { if (size < 1) throw new ArgumentOutOfRangeException ("Number of dices shlud be > 0"); init(size,type,ref _rand); }
/// <summary> /// Get a dice throw /// </summary> /// <param name="dice"></param> /// <returns></returns> public static short GetRandomNumber(DiceType dice) { return (short) rnd.Next(1, (int) dice + 1); }