Beispiel #1
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();
            }
        }