Пример #1
0
 private void RevertMove(VialSet set, Pouring pouring)
 {
     for (int i = 0; i < pouring.Quantity; i++)
     {
         set.Vials.ElementAt(pouring.From).Stack(
             set.Vials.ElementAt(pouring.To).Pop());
     }
 }
Пример #2
0
        public VialSet Redo(VialSet set)
        {
            if (CanRedo)
            {
                currentIndex++;
                ApplyMove(set, _pourings[currentIndex]);
            }

            return(set);
        }
Пример #3
0
        public VialSet Undo(VialSet set)
        {
            if (CanUndo)
            {
                RevertMove(set, _pourings[currentIndex]);
                currentIndex--;
            }

            return(set);
        }
Пример #4
0
        private VialSet MarkOptions(VialSet set, Vial selected)
        {
            var color = selected.TopColor;

            foreach (var vial in set.Vials)
            {
                vial.IsOption = !vial.IsSelected && vial.CanPour(color);
            }

            return(set);
        }
Пример #5
0
        private VialSet TryPouring(VialSet set, int indexFrom, int indexTo)
        {
            var from = set.Vials.ElementAt(indexFrom);
            var to   = set.Vials.ElementAt(indexTo);

            if (from.IsEmpty)
            {
                return(set);
            }

            var fromColor = from.TopColor;

            while (from.TopColor == fromColor && to.CanPour(fromColor))
            {
                to.Stack(from.Pop());
                from.IsSelected = false;

                if (set.LastAppliedPouring == null)
                {
                    set.LastAppliedPouring = new Pouring(indexFrom, indexTo);
                }
                else
                {
                    set.LastAppliedPouring.Increment();
                }
            }

            if (set.HasChanged)
            {
                foreach (var vial in set.Vials)
                {
                    vial.IsOption = false;
                }
            }

            return(set);
        }
Пример #6
0
        public VialSet Select(VialSet set, int index)
        {
            set.LastAppliedPouring = null;
            var selected = set.Vials.SingleOrDefault(v => v.IsSelected);

            if (selected != null)
            {
                var target = set.Vials.ElementAt(index);

                if (target.IsSelected)
                {
                    target.IsSelected = false;
                    foreach (var vial in set.Vials)
                    {
                        vial.IsOption = false;
                    }
                    return(set);
                }
                else
                {
                    return(TryPouring(set,
                                      set.Vials.FirstIndexOf(v => v.IsSelected),
                                      index));
                }
            }
            else
            {
                var target = set.Vials.ElementAt(index);
                if (target.IsEmpty)
                {
                    return(set);
                }

                target.IsSelected = true;
                return(MarkOptions(set, target));
            }
        }