示例#1
0
        private void NewGame()
        {
            //set the health of the first enemy
            EnemyHealth = 10;


            //set rnd to an random seed
            rnd = new Random();

            //set the number of dice the player starts with
            NumberOfStartingDice = 3;

            //create an array with empty dice
            DiceToRoll    = new Die[10];
            DieInHoldArea = new DieInHold[5];


            //disable all hold slots
            DiceHoldGroup.Children.Cast <Button>().ToList().ForEach(button =>
            {
                button.IsEnabled = false;
                button.Content   = "";
            });


            //Create disabled emtpy dice in hold
            for (int i = 0; i < DieInHoldArea.Count(); i++)
            {
                DieInHoldArea[i] = new DieInHold(0, false, false);
            }


            //disable all buttons exept a number of dice equal to the starting dice, give to still enabled basic dice data
            for (int i = 0; i < DiceToRoll.Length; i++)
            {
                Button button = (Button)DiceToRollGroup.FindName("DiceToRoll" + "_" + (i).ToString());
                if (i < NumberOfStartingDice)
                {
                    button.IsEnabled = true;
                    DiceToRoll[i]    = new Die(0, new List <string> {
                        "N.0", "A.1", "A.1", "A.1", "A.2", "A.3"
                    }, 6);
                }
                else
                {
                    button.IsEnabled = false;
                    DiceToRoll[i]    = new Die(0, new List <string>(), 0);
                }
            }

            bool HasRoled = RollAllDice();
        }
示例#2
0
        /// <summary>
        /// Deal the damage of the dice
        /// then disable all dice in hold area and enable the available dice in the to roll zone
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void NextTurnClick(object sender, RoutedEventArgs e)
        {
            EnemyHealth -= UpdateDiceMove();

            EnemyHPLabel.Content = "Enemy HP: " + EnemyHealth.ToString();

            DiceHoldGroup.Children.Cast <Button>().ToList().ForEach(button =>
            {
                if (button.IsEnabled)
                {
                    int DieToDisable            = int.Parse(button.Name.Split('_')[1]);
                    DieInHoldArea[DieToDisable] = new DieInHold(0, false, false);
                    button.IsEnabled            = false;
                    button.Content = "";
                }
            });

            for (int i = 0; i < DiceToRoll.Length; i++)
            {
                Button button = (Button)DiceToRollGroup.FindName("DiceToRoll" + "_" + (i).ToString());
                if (i < NumberOfStartingDice)
                {
                    button.IsEnabled = true;
                    DiceToRoll[i]    = new Die(0, new List <string> {
                        "N.0", "A.1", "A.1", "A.1", "A.2", "A.3"
                    }, 6);
                }
                else
                {
                    button.IsEnabled = false;
                    DiceToRoll[i]    = new Die(0, new List <string>(), 0);
                }
            }

            TimesRolledTurn = 0;

            UpdateDiceRoll(RollAllDice());
        }