Example #1
0
 /// <summary>
 /// Rolls the specified die type.
 /// </summary>
 /// <param name="dieType">Type of the die to roll.</param>
 /// <returns>The most recent DiceRoll collection</returns>
 public RollCollection Roll(DiceType diceType)
 {
     if (this.timer.ElapsedMilliseconds > 500)
     {
         this.roll = new RollCollection();
     }
     this.roll.Roll(diceType);
     this.timer.Restart();
     return(this.roll);
 }
Example #2
0
        /// <summary>
        /// Handles the keypress action, I.e. dice rolled
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="PreviewKeyDownEventArgs"/> instance containing the event data.</param>
        private void MainForm_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
        {
            RollCollection dr = null;

            switch (e.KeyCode)
            {
            case Keys.Q:
                dr = this.rollDice(DiceType.D20);
                break;

            case Keys.W:
                dr = this.rollDice(DiceType.D12);
                break;

            case Keys.E:
                dr = this.rollDice(DiceType.D10);
                break;

            case Keys.R:
                dr = this.rollDice(DiceType.D8);
                break;

            case Keys.T:
                dr = this.rollDice(DiceType.D6);
                break;

            case Keys.Y:
                dr = this.rollDice(DiceType.D4);
                break;

            case Keys.Space:
                dr = diceController.Lucky();
                this.setLabelColor(Color.DarkGreen);
                break;

            case Keys.Back:
            case Keys.Delete:
                this.clearLabels();
                break;

            default:
                if (e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9)
                {
                    dr = diceController.AddModifier(e.KeyValue - 48);
                }
                break;
            }
            if (dr != null)
            {
                this.resultLabel.Text = dr.Result();
                this.sumLabel.Text    = dr.ToString();
            }
        }
Example #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DiceController"/> class.
 /// </summary>
 public DiceController()
 {
     this.timer = new Stopwatch();
     this.roll  = new RollCollection();
 }
Example #4
0
 public Frame(int frameNr)
 {
     this.frameNr = frameNr;
     Rolls = new RollCollection(frameNr < 10 ? 2 : 3);// if is frame less then 10 then 2 rolles else 3 rolles can be added
 }