Beispiel #1
0
        public void Print()
        {
            IEnumerable <Atom> diceGroupAtoms = this.AtomList.Where(a => a.IsDiceGroup);
            IEnumerable <Atom> modifierAtoms  = this.AtomList.Where(a => a.IsModifier);

            foreach (Atom a in diceGroupAtoms)
            {
                DiceGroup dg = a.DiceGroupInstance;

                dg.DiceList.ToList().ForEach(d =>
                {
                    if (d.Size == 20)
                    {
                        if (d.Value == 1)
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                        }
                        else if (d.Value == 20)
                        {
                            Console.ForegroundColor = ConsoleColor.Green;
                        }
                    }

                    Console.WriteLine($"{d}: {d.Value}");
                    Console.ForegroundColor = ConsoleColor.White;
                });
            }

            Console.Write("Modifiers: ");
            Console.WriteLine(string.Join(", ", modifierAtoms.Select(a => a.ModifierInstance.ToString())));
        }
Beispiel #2
0
        public override object VisitAtom([NotNull] DiceParser.AtomContext context)
        {
            Atom atom = new Atom();

            if (context.diceGroup() == null)
            {
                atom.SetModifier(int.Parse(context.NUMBER().GetText()));
                return(atom);
            }
            else
            {
                DiceGroup diceGroup = (DiceGroup)this.VisitDiceGroup(context.diceGroup());
                atom.SetDiceGroup(diceGroup);

                return(atom);
            }
        }
Beispiel #3
0
        public override object VisitDiceGroup([NotNull] DiceParser.DiceGroupContext context)
        {
            int count, size;

            if (context.NUMBER().Length == 1)
            {
                count = 1;
                size  = int.Parse(context.NUMBER()[0].GetText());
            }
            else
            {
                count = int.Parse(context.NUMBER()[0].GetText());
                size  = int.Parse(context.NUMBER()[1].GetText());
            }

            DiceGroup diceGroup = new DiceGroup(Enumerable.Range(1, count).Select((_) => new Dice(size)));

            return(diceGroup);
        }
Beispiel #4
0
 public void SetDiceGroup(DiceGroup dg)
 {
     this.DiceGroupInstance = dg;
     this.IsDiceGroup       = true;
 }