示例#1
0
        static void Main(string[] args)
        {
            // Skapar två tärningsobjekt.
            Die die1 = new Die();
            Die die2 = new Die();

            // Kastar de två tärningarna och skriver ut
            // resultatet av tärningskasten.
            for (int i = 0; i < 1000; ++i)
            {
                Console.WriteLine("1: {0}\t2: {1}",
                    die1.Roll(), die2.Roll());
            }

            // Skriver ut resultatet av det senaste
            // kastet med den första tärningen.
            Console.WriteLine(die1);
        }
示例#2
0
        internal void RequestDiceRoll()
        {
            while (_dicecount > Dice.Count)
                Dice.Add(new Die(SelectedDieType));
            while (_dicecount < Dice.Count)
                Dice.RemoveAt(Dice.Count - 1);
            foreach (var die in Dice)
                die.Roll();
            while (BonusDice > 0 && App.Rules.RuleOfSixesEnabled)
            {
                var d = new Die(SelectedDieType);
                Dice.Add(d);
                d.Roll();
                BonusDice--;
            }
            var badCount = 0;
            var hitCount = 0;
            foreach (var die in Dice)
            {
                if (die.Value >= App.Rules.HitThreshold)
                    hitCount++;
                else if (die.Value == 1)
                    badCount++;
            }

            if (badCount >= Math.Max((Dice.Count / 2.0) - (GremlinsEnabledSwitch ? GremlinsCount : 0), 0))
            {
                if (hitCount == 0)
                    HitStatus = "CRITICAL GLITCH!";
                else
                    HitStatus = string.Format("Glitch, {0} Hits", hitCount);
                HitStatusColor = App.Brushes.GlitchColor;
            }
            else
            {
                HitStatus = string.Format("{0} Hits!", hitCount);
                HitStatusColor = App.Brushes.NormalColor;
            }

            PropertyChanged(this, new PropertyChangedEventArgs("HitStatus"));
            PropertyChanged(this, new PropertyChangedEventArgs("HitStatusColor"));
        }