public void test_to_string() { var die = new Die(); var roll = die.Roll(); Assert.AreEqual(roll.ToString(), die.ToString()); }
// Use this for initialization void Start () { currentHealth = topHealth; Player = FindObjectOfType<Movement> (); //InvokeRepeating ("decreaseHealth", 1f,1f); die = FindObjectOfType<Die> (); decreaseHealth(); }
void OnMouseUpAsButton() { if (firstRoll) { displayer.RollDice(); firstRoll = false; } else { if (Die.selectedCounter != 0) { Debug.Log(Die.selectedCounter); GameManager.selectedDieValues = new RollValues(6); for (int i = 0; i < dice.Length; i++) { die = dice[i].GetComponent<Die>(); if (die.selected) { GameManager.selectedDieValues[die.value - 1]++; } } GameManager.dieValues.Clear(); //move selected die displayer.RollDice(); ScoreChecker.SelectedDiceChecker(GameManager.selectedDieValues); } else { Debug.Log("Please select dice"); } } }
/// <summary> /// Runs a battle between a Hero and a Dragon. Ends when one of them has 0 HitPoints. /// </summary> /// <param name="hero">The Hero in the battle.</param> /// <param name="enemy">The Dragon in the battle.</param> static void Battle(Hero hero, Dragon enemy) { // TODO++: modify Battle to take a List<Dragon> of enemies, and have each of them attack every time through the loop. // You may want to have the Hero automatically attack the first enemy in the list that is still alive. Die myDie = new Die(20); Console.WriteLine(MyHero); Console.WriteLine("VERSUS"); Console.WriteLine(MyEnemy); while (MyHero.IsAlive()) { int attackRoll = myDie.Roll(); Console.WriteLine("Rolled {0} for attack phase", attackRoll); MyHero.Attack(MyEnemy, attackRoll); Console.WriteLine(MyEnemy); if (!MyEnemy.IsAlive()) { Console.WriteLine("{0} slayed {1}!", MyHero.Name, MyEnemy.Name); break; } int defenseRoll = myDie.Roll(); Console.WriteLine("Rolled {0} for defense phase", defenseRoll); MyHero.Defend(MyEnemy, defenseRoll); Console.WriteLine(MyHero); } if (!MyHero.IsAlive()) { Console.WriteLine("{0} was defeated by {1}. :(", MyHero.Name, MyEnemy.Name); } }
public void TestDieRoll() { var d = new Die(_faces); Die.Roll(d.ListOfFaces); String sum = _faces.Aggregate("", (current, s) => current + s.FaceCharacter); Assert.IsTrue(String.Compare(sum, NamesConcat) != 0); }
public void TestDieRollRange() { Die die = new Die(); int roll = die.roll(); //Test that roll is between 1 & 6 Assert.LessOrEqual(roll, 6); Assert.GreaterOrEqual(roll, 1); }
public void should_return_the_last_number_rolled() { var die = new Die(); var numberRolled = die.Roll(); var result = die.NumberLastRolled(); Assert.AreEqual(result, numberRolled); }
public void when_rolling_die_it_should_return_a_random_number_between_1_and_6() { var die = new Die(); var result = die.Roll(); Assert.LessOrEqual(result, 6); Assert.GreaterOrEqual(result, 1); }
public void testRandomness4Fail1in6() { //Test randomness that should fail on average 1 in 6 times Die die = new Die(); int numberToTest = 10; int roll = die.roll(); Assert.AreNotEqual(roll, numberToTest); numberToTest = roll; }
public void TestDieRollOneThousandRange() { Die die = new Die(); for (int i = 0; i < 1000; i++) { int roll = die.roll(); Assert.LessOrEqual(roll, 6); Assert.GreaterOrEqual(roll, 1); } }
public Game() { playerOne = new Player(); playerTwo = new Player(); currentPlayer = playerOne; for (int i = 0; i < dice.Length; i++) { dice[i] = new Die(rnd); dice[i].Roll(); //Startvärden } }
public Dice(int count) { this.count = count; dice = new Die[count]; for (int i = 0; i < dice.Length; i++) { dice[i] = new Die(); dice[i].faces = OLD_DICE[i % 16].ToCharArray(); } visibleFaces = new int[count]; positions = new int[count]; for (int i = 0; i < count; i++) positions[i] = -1; }
void Start() { for(int i = 0; i<keys.Length; i++) { faces[keys[i]] = transform.Find(keys[i]).renderer; reverseMap[keys[i]] = i; } die = Die.GetRandomDie(); for(int lazyIdx = 0; lazyIdx<Die.SIDES; lazyIdx++) { _Setup(lazyIdx); } }
public void each_die_roll_should_occur_with_the_same_chance() { const int minimumOccurences = 160000; const int maximumOccurences = 170000; var results = new int[1000000]; var die = new Die(); for (var i = 0; i < 1000000; i++) { results[i] = die.Roll(); } var testResults = results.Where(num => num.Equals(6)).Select(num => num); Assert.GreaterOrEqual(testResults.Count(), minimumOccurences); Assert.LessOrEqual(testResults.Count(), maximumOccurences); }
private int rollDie(Vector3 toPosition) { Die[] dice = new Die[2]; Vector3 randomness = new Vector3(1.5f, 0, 1.5f); int c = 0; for(int i = 1; i <= 1; i += 2) { Die die = Instantiate(diePrefab); //die.transform.localPosition = new Vector3(0, 2) + toPosition + (randomness * i); die.transform.localPosition = new Vector3(0, 2) + toPosition; die.transform.Rotate(DieRotations[Random.Range(0, DieRotations.Length)]); dice[c] = die; c++; //Rigidbody body = die.GetComponent<Rigidbody>(); //body.AddForce((toPosition - die.transform.localPosition).normalized * 500 * body.mass); //body.AddTorque(new Vector3(Random.Range(-360, 360), Random.Range(-360, 360), Random.Range(-360, 360))); } return dice[0].getNumber(); }
/* private AudioClip dice5; private AudioClip dice2; private AudioClip dice8 ; private AudioClip dice1; private AudioClip dice3; private AudioClip dice4 ; private AudioClip[] dices; */ public Die( GameObject gameObject, string type ) { this.gameObject = gameObject; this.type = type; this.die = (Die)gameObject.GetComponent(typeof(Die)); //loading audio part /* this.gameObject.AddComponent<AudioSource>(); dice5 = Resources.Load("sound/dice6") as AudioClip; dice2 = Resources.Load("sound/dice7") as AudioClip; dice8 = Resources.Load("sound/dice8") as AudioClip; dice1 = Resources.Load("sound/dice1") as AudioClip; dice3 = Resources.Load("sound/dice3") as AudioClip; dice4 = Resources.Load("sound/dice4") as AudioClip; */ // this.dices = new AudioClip[5]{ dice2, dice5, dice8, dice1, dice3/*, dice4*/ }; // this.rigidbody.sleepVelocity = 0.01F; // this.rigidbody.sleepAngularVelocity = 0.01F; }
internal void Attack( Figure attacker, Figure defender ) { var attackDie = new Die( Global.Random, 20 ); if ( attackDie.Roll() + attacker.AttackBonus >= defender.ArmorClass ) { int damage = attacker.Damage.Roll().Sum(); defender.Health -= damage; Debug.WriteLine( "{0} hit {1} for {2} and he has {3} health remaining.", attacker.Name, defender.Name, damage, defender.Health ); if ( defender.Health <= 0 ) { if ( defender is AggressiveEnemy ) { var enemy = defender as AggressiveEnemy; _aggressiveEnemies.Remove( enemy ); } Debug.WriteLine( "{0} killed {1}", attacker.Name, defender.Name ); } } else { Debug.WriteLine( "{0} missed {1}", attacker.Name, defender.Name ); } }
public ShiftRotateExtendedInstruction(Die die) : base(die) { }
public ReadImmediateRegisterInstruction(Die die) : base(die) { }
void UnregisterDieEvents(Die die) { die.OnStateChanged -= OnDieStateChanged; die.OnTelemetry -= OnDieTelemetry; }
public static void Main() { //Greed is a dice game played with five six - sided dice./ //Your mission, should you choose to accept it, is to score a throw according to these rules. //You will always be given an array with five six-sided dice values. // Three 1's => 1000 points // Three 6's => 600 points // Three 5's => 500 points // Three 4's => 400 points // Three 3's => 300 points // Three 2's => 200 points // One 1 => 100 points // One 5 => 50 point //A single die can only be counted once in each roll. //For example, a "5" can only count as part of a triplet(contributing to the 500 points) or as a single 50 points, //but not both in the same roll. //Example scoring // Throw Score // --------------------------- // 5 1 3 4 1 50 + 2 * 100 = 250 // 1 1 1 3 1 1000 + 100 = 1100 // 2 4 4 5 4 400 + 50 = 450 //ToDo: try a class dice and print 5 objects; //TODO: Learn Group By and Sort string input = Console.ReadLine(); var dice = input.Split(' ').Select(int.Parse).ToArray(); //change all 1's to 10's, easier to add the score later on for (int index = 0; index < dice.Count(); index++) { if (dice[index] == 1) { dice[index] = 10; } } //create and populate the dice as list so they can be grouped by their value var listOfDice = new List <Die>(); for (int index = 0; index < dice.Count(); index++) { var currentDie = new Die() { value = dice[index] }; listOfDice.Add(currentDie); } var groups = listOfDice.GroupBy(Die => new { Die.value }).OrderByDescending(x => x.Count()).ToList(); int score = 0; bool quintuple = groups.Count() == 1; if (quintuple) { bool onlyOnes = int.Parse(groups[0].Key.ToString()) == 10; if (onlyOnes) { score += 1200; } } }
public RetInstruction(Die die) : base(die) { }
public void Init() { SetAttack(Die.Throw1d20()); }
public AutoCompleteInstructionPart(Die die, MachineCycleNames activeMachineCycle) : base(die, activeMachineCycle) { }
public void DisconnectDie(Die die) { Central.Instance.DisconnectDie(die); }
void OnBecameInvisible() { isDead = false; Die?.Invoke(this); }
public ActionResult Index(Die die) { ViewBag.Dice = die.Roll(); return(View(die)); }
public Greatclub(Die dieDamage, int numberOfDice, string name, int range, bool isMartial, bool isFinesse) : base(dieDamage, numberOfDice, name, range, isMartial, isFinesse) { }
public bool isValidClick(Die obj) { bool canClick = false; return canClick; }
public static int getDieScore(Die die) { return die.card.cardInfo.score; }
public IncDecIndirectInstruction(Die die) : base(die) { }
void AddDie(Die die) { this.die = die; }
public int calculate(Die die) { return die.food; }
public ComboMaxResult GetMaxCombo(List <Die> dice, bool is_sorted) { if (dice == null) { return(null); } List <Die> dice_copy = dice; if (!is_sorted) { dice_copy = new List <Die>(dice); dice_copy.Sort((d1, d2) => { return((int)d1.Side - (int)d2.Side); }); } byte[] found_combo_sides = new byte[6]; ComboMaxResult result = new ComboMaxResult(); result.Name = "Set of "; for (int i = 0; i < dice_copy.Count; ++i) { Die die = dice_copy[i]; if (die.Side == DieSide.JOKER) { continue; } ++found_combo_sides[(int)die.Side]; } DieSide best_side = DieSide.ONE; bool combo_exists = false; if (found_combo_sides[0] >= 3) { result.Score = 100; result.Name += "1"; best_side = DieSide.ONE; combo_exists = true; } else { for (int i = 5; i > 0; --i) { if (found_combo_sides[i] >= 3) { best_side = (DieSide)(i); result.Score = (i + 1) * 10; result.Name += Convert.ToString(i + 1); combo_exists = true; break; } } } if (!combo_exists) { return(null); } for (int i = 0, limit = 3; i < dice_copy.Count && limit > 0; ++i) { if (dice_copy[i].Side == best_side) { --limit; result.DiceInCombo.Add(dice_copy[i]); } } return(result); }
public void WriteDie(Die die, byte[] bytes, int length, System.Action bytesWrittenCallback) { Central.Instance.WriteDie(die, bytes, length, bytesWrittenCallback); }
public static int GetFaces(this Die die) { return((int)die); }
// button1_Click handles Button Click action that runs the program private void button1_Click(object sender, EventArgs e) { // Generate Lists to hold counts for rolled values List <int> count1 = new List <int>(); List <int> count2 = new List <int>(); List <int> count3 = new List <int>(); // Bind the charts to their respective arrays of counts chart1.Series[0].Points.DataBindY(count1); chart2.Series[0].Points.DataBindY(count2); chart3.Series[0].Points.DataBindY(count3); // initialize die 1 count for (int i = 1; i <= 6; i++) { count1.Add(0); } for (int i = 1; i <= 6; i++) { count3.Add(0); } // initialize double die count for (int i = 0; i <= 11; i++) { count2.Add(0); } // Make Random functions for two seperate "dice" //Random randomizer = new Random(); Die die1 = new Die(); Die die2 = new Die(); Die die3 = new Die(); // Pull and parse to integer the values in the textbox int nRolls = int.Parse(numRolls.Text); // Compute die rolls n times for (int i = 0; i < nRolls; i++) { // Computes the results for single die rolls on first dice die1.rollDie(1); int currRoll = die1; count1[currRoll] += 1; // Updates chart 1 chart1.Series[0].Points.DataBindY(count1); chart1.Update(); // Computes the results for single die rolls on 2nd dice die3.rollDie(1); int currRoll3 = die3; count3[currRoll3] += 1; //Updates chart 3 chart3.Series[0].Points.DataBindY(count3); chart3.Update(); // Computes the results for the sum of two die rolls die2.rollDie(2); die2.rollDie(2); int currRoll2 = die1 + die2 - 1; count2[currRoll2] += 1; // Updates chart 2 chart2.Series[0].Points.DataBindY(count2); chart2.Update(); } }
public Vector3 spawnPoint; // die spawnPoiunt #endregion Fields #region Constructors // constructor public RollingDie(GameObject gameObject, string name, string mat, Vector3 spawnPoint, Vector3 force) { this.gameObject = gameObject; this.name = name; this.mat = mat; this.spawnPoint = spawnPoint; this.force = force; // get Die script of current gameObject die = (Die)gameObject.GetComponent(typeof(Die)); }
void RegisterDieEvents(Die die) { die.OnStateChanged += OnDieStateChanged; die.OnTelemetry += OnDieTelemetry; }
// IEnumerator public void drawDice(int amount) { if (GameState.hasDrawn) return; int count = amount; Zone supportT = gameLayout.getZone(getCurrentZoneS("zoneSupport")); string support = getCurrentZoneS("zoneSupport"); string supply = getCurrentZoneS("zoneSupply"); string stored = getCurrentZoneS("zoneStored"); Die[] h = gameLayout.getDiceInZone(supply); Die[] d = gameLayout.getDiceInZone(stored); int iDraw; if (h != null && h.Length == 0 && d.Length != 0) { moveDice(stored, supply, false); h = gameLayout.getDiceInZone(supply); d = new Die[0]; } //moveDice(supply, support, amount); /* What to do if can't move the asked amount? If 'from' is "supply" then moveDice(stored, supply, false) continue */ while (count != 0 && h.Length != 0 && h != null) { iDraw = UnityEngine.Random.Range(0, h.Length); DieLogic.moveDie(h[iDraw], supportT); h[iDraw].toggleVisibility(true); SoundControl.instance.playAudio("dice", "slide"); count--; h = gameLayout.getDiceInZone(supply); if (count > 0 && h.Length == 0 && d.Length > 0) { //yield return new WaitForSeconds(h[iDraw].GetComponent<AudioSource>().clip.length); moveDice(stored, supply, false); h = gameLayout.getDiceInZone(supply); d = new Die[0]; } } Debug.Log("Moved " + (amount - count) + " dice !"); GameState.hasDrawn = true; }
void OnDieTelemetry(Die die, Vector3 acc, int millis) { trackedDice[die].OnTelemetryReceived(acc, millis); }
public void defendAttack(Die die) { int dDefense = DieLogic.getDieValue(die, Side.eValueTypes.DEFENSE); defenseLeft -= dDefense; if (defenseLeft <= 0 || GameLogic.instance.gameLayout.getDiceInZoneNext("zoneSummoned").Length == 0) defendSuccessful = true; }
public NmiInterrupt(Die die, OpcodeDefinition opcodeDefinition) : base(die, opcodeDefinition) { }
public WriteIndirectRegisterInstruction(Die die) : base(die) { }
static void Main(string[] args) { Die d = new Die(); d.Roll(); }
public static void rollDie(Die d) { float dieMag = d.transform.localScale.magnitude; Zone spawn = getCurrentSpawn(); Vector3 force = getForce(spawn.transform); moveDie(d, spawn); // Random Rotation d.transform.Rotate(new Vector3(UnityEngine.Random.value * 360, UnityEngine.Random.value * 360, UnityEngine.Random.value * 360)); // Add Force d.GetComponent<Rigidbody>().AddForce(force, ForceMode.Impulse); // Add Random Torque // -50 Vector3 tV = GameLogic.instance.rollValues.vtV; d.GetComponent<Rigidbody>().AddTorque(new Vector3(tV[0] * UnityEngine.Random.value * dieMag, tV[1] * UnityEngine.Random.value * dieMag, tV[2] * UnityEngine.Random.value * dieMag), ForceMode.Impulse); SoundControl.instance.playAudio(); }
public static Die Copy(this Die die) { return(new Die { AllocatedTo = die.AllocatedTo, Face = die.Face, Id = die.Id }); }
public static void moveDie(Die die, Zone zoneTo) { if (zoneTo != null) { // Try to update the Die's Old Zones' and New Zones' GameZone Die[] //Zone oldP = d.GetComponent<Draggable>().getParentZone(); // Use oldP and z to get gameLayout to update their dice/color //Debug.Log("Moving die to " + zoneTo.zoneName); die.GetComponent<Draggable>().setParentZone(zoneTo); die.transform.SetParent(zoneTo.holders.diceHolder); Vector3 boxSize = zoneTo.GetComponent<BoxCollider>().size; die.offsetMargin.x = boxSize.x * zoneTo.transform.localScale.x * die.transform.localScale.x; die.offsetMargin.z = boxSize.y * zoneTo.transform.localScale.y * die.transform.localScale.z; die.moveDie(0, 0, 0); die.offsetDie(); } else { Debug.Log("Zone moving to doesn't exist"); } }
protected DefenceDieTests(Die testDie, double averageShields) { _testDie = testDie; _averageShields = averageShields; }
public void rollSimilarDice(Die d) { Die[] dice = d.transform.parent.GetComponentsInChildren<Die>(); string sAudio = "rollS"; if (dice.Length > 1) sAudio = "rollM_1"; // index of the multiple dice roll sound foreach (Die die in dice) { SoundControl.instance.setAudio("dice", sAudio); DieLogic.rollDie(die); } }
public static int getDiceValue(Die[] dice, Side.eValueTypes vT) { int val = 0; foreach (Die die in dice) val += getDieValue(die, vT); return val; }
public void ConnectDie(Die die) { Central.Instance.ConnectDie(die); }
public static void Main() { var myDie = new Die(7); }
public static int getDieValue(Die die, Side.eValueTypes vT) { return die.getSideValue(vT); }
void OnBatteryLevelChanged(Die die, float?level, bool?charging) { batteryView.SetLevel(die.batteryLevel, charging); }
public LoadImmediate16Instruction(Die die) : base(die) { }
public MatchOnThreeDiceRule(Die dieToMatch, int valueIfMatched) : base(valueIfMatched) { DieToMatch = dieToMatch; }
void OnRssiChanged(Die die, int?rssi) { signalView.SetRssi(die.rssi); }
public TestSpell() : base("Test Spell", 0, new ArcaneSpell()) { DamageDice = new Die[] { D6.GetInstance() }; DamageBonus = 1; }
protected SingleCycleInstruction(Die die) : base(die) { }