Exemple #1
0
 public void RemoveDie(DieStep step)
 {
     if (this.die == step.Die)
     {
         this.count -= step.Count;
         if (this.count < 0)
         {
             this.count = 0;
         }
     }
     else
     {
         if (_extraRolls != null)
         {
             for (int i = 0; i < _extraRolls.Count; i++)
             {
                 DieStep ex = extraRolls[i];
                 if (ex.Die == step.Die)
                 {
                     ex.Count -= step.Count;
                     if (ex.Count <= 0)
                     {
                         _extraRolls.RemoveAt(i);
                     }
                     break;
                 }
             }
         }
     }
 }
Exemple #2
0
        private static DieRoll StepUpDieRoll(DieRoll roll)
        {
            DieRoll outRoll = roll;

            DieStep step = new DieStep(roll.count, roll.die);

            if (stepUpList.ContainsKey(step))
            {
                step = stepUpList[step];
            }
            else
            {
                if (step.Count < 2)
                {
                    step.Count += 1;
                }
                else
                {
                    step.Count += 2;
                }
            }

            outRoll.count = step.Count;
            outRoll.die   = step.Die;

            return(outRoll);
        }
Exemple #3
0
        public void AddDie(DieStep step)
        {
            if (this.die == step.Die)
            {
                this.count += step.Count;
            }
            else
            {
                bool added = false;
                if (_extraRolls != null)
                {
                    foreach (DieStep ex in _extraRolls)
                    {
                        if (ex.Die == step.Die)
                        {
                            ex.Count += step.Count;
                            added     = true;
                            break;
                        }
                    }
                }

                if (!added)
                {
                    if (_extraRolls == null)
                    {
                        _extraRolls = new List <DieStep>();
                    }
                    _extraRolls.Add(new DieStep(step.Count, step.Die));
                }
            }
        }
        private void AddDieButton_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            DieStep d = new DieStep();

            d.PropertyChanged += new PropertyChangedEventHandler(DieStep_PropertyChanged);
            _Steps.Add(d);

            UpdateUI();
        }
        private void DeleteButton_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            DieStep d = (DieStep)((FrameworkElement)sender).DataContext;

            _Steps.Remove(d);

            d.PropertyChanged -= new PropertyChangedEventHandler(DieStep_PropertyChanged);

            UpdateUI();
        }
Exemple #6
0
        public override bool Equals(object obj)
        {
            if (obj.GetType() != typeof(DieStep))
            {
                return(false);
            }

            DieStep step = (DieStep)obj;

            return(Count == step.Count && Die == step.Die);
        }
Exemple #7
0
        private static DieRoll StepDownDieRoll(DieRoll roll)
        {
            DieRoll outRoll = roll;

            DieStep step = new DieStep(roll.count, roll.die);

            if (stepDownList.ContainsKey(step))
            {
                step = stepDownList[step];
            }
            else
            {
                if (step.Count > 3)
                {
                    step.Count -= 3;
                }
                else if (step.Count > 1)
                {
                    step.Count -= 1;
                }
                else if (step.Die > 1)
                {
                    {
                        step.Die -= 1;
                    }
                }
                else
                {
                    step.Count = 0;
                    step.Die   = 1;
                }
            }

            outRoll.count = step.Count;
            outRoll.die   = step.Die;

            return(outRoll);
        }
Exemple #8
0
        public static DieRoll FromString(string text, int start)
        {
            DieRoll roll = null;

            if (text != null)
            {
                try
                {
                    Regex regRoll = new Regex(DieRollRegexString);

                    Match match = regRoll.Match(text, start);

                    if (match.Success)
                    {
                        roll = new DieRoll();

                        roll.count = int.Parse(match.Groups[1].Value);


                        if (match.Groups[2].Success)
                        {
                            roll.fraction = int.Parse(match.Groups[2].Value.Substring(1));
                        }
                        else
                        {
                            roll.fraction = 1;
                        }

                        roll.die = int.Parse(match.Groups[3].Value);


                        if (roll.die == 0)
                        {
                            throw new FormatException("Invalid Die Roll");
                        }

                        if (match.Groups["extra"].Success)
                        {
                            roll.extraRolls = new List <DieStep>();

                            Regex extraReg = new Regex("([0-9]+)d([0-9]+)");

                            foreach (Match d in extraReg.Matches(match.Groups["extra"].Value))
                            {
                                DieStep step = new DieStep();
                                step.Count = int.Parse(d.Groups[1].Value);
                                step.Die   = int.Parse(d.Groups[2].Value);


                                if (step.Die == 0)
                                {
                                    throw new FormatException("Invalid Die Roll");
                                }

                                roll.extraRolls.Add(step);
                            }
                        }

                        if (match.Groups[7].Success)
                        {
                            roll.mod = int.Parse(match.Groups[7].Value);
                        }
                    }
                }
                catch (FormatException)
                {
                    roll = null;
                }
                catch (OverflowException)
                {
                    roll = null;
                }
            }

            return(roll);
        }
Exemple #9
0
        public static DieStep StepDie(DieStep step, int diff)
        {
            DieRoll r = new DieRoll(step.Count, step.Die, 0);

            return(StepDie(r, diff).Step);
        }