Esempio n. 1
0
        /// <summary>
        /// Реализация броска монеты
        /// </summary>
        /// <param name="_headsOrTailsModel">Модель</param>
        /// <param name="_statistic">Ссылка на статистику</param>
        public TossCoin(IHeadsOrTailsModel _headsOrTailsModel, Statistic _statistic)
        {
            headsOrTailsModel = _headsOrTailsModel;
            statistic = _statistic;

            ThrownCointAnimation = new AnimationSprite();
            ThrownCointAnimation.AnimationStoped += (sender, sprite) =>
            {
                SideOfCoin = sprite.HeadsOrTails;
                statistic.AllCoinThrowCount++;

                if (sprite.HeadsOrTails == HeadsOrTailsEnum.Heads)
                    statistic.HeadsCount++;
                else
                {
                    statistic.TailsCount++;
                }
            };

            #region Команда броска монеты
            var Command = new ViewModelCommand(ThrownCointAnimation, "IsStopped");
            // Бросить монету
            Command.Action = (o) => ThrowCoinMethod();
            //Выполнятся может когда анимация остановлена
            Command.Predicate = o => ThrownCointAnimation.IsStopped;
            ThrowCoinCommand = Command;
            #endregion
        }
 public HeadsOrTailsViewModel()
 {
     headsOrTailsModel = new HeadsOrTailsModel();
     var statistic = new Statistic();
     TossCoin = new TossCoin(headsOrTailsModel, statistic);
     GuessToss = new GuessToss(headsOrTailsModel, statistic);
     TossSeveralCoins = new TossSeveralCoins(headsOrTailsModel, statistic);
     Statistic = statistic;
 }
        public TossSeveralCoins(IHeadsOrTailsModel _headsOrTailsModel, Statistic _statistic)
        {
            headsOrTailsModel = _headsOrTailsModel;
            statistic = _statistic;

            CollectionOfFlippedCoins = new ObservableCollection<HeadsOrTailsEnum>();

            #region Команда броска нескольких монет
            var Command = new ViewModelCommand(this, "ThrowCount");
            Command.Action = o => ThrowSeveralCoin();
            Command.Predicate = o => ThrowCount > 0;    // Если больше чем 0 бросков
            ThrowSeveralCoinCommand = Command;
            #endregion
        }
Esempio n. 4
0
        /// <summary>
        /// Реализация угадования броска монеты
        /// </summary>
        /// <param name="_headsOrTailsModel">Модель</param>
        /// <param name="_statistic">Ссылка на статистику</param>
        public GuessToss(IHeadsOrTailsModel _headsOrTailsModel, Statistic _statistic)
        {
            headsOrTailsModel = _headsOrTailsModel;
            statistic = _statistic;

            GuessCointAnimation = new AnimationSprite();
            GuessCointAnimation.AnimationStoped += (sender, sprite) =>
            {
                throw new Exception();
            };

            #region Команда броска угадывания монет
            var Command = new ViewModelCommand(this, "GuessSideOfCoin");
            Command.Action = o => TryToGuess();
            Command.Predicate = o => GuessSideOfCoin != null;   // Если монета выбрана
            TryToGuessCommand = Command;
            #endregion
        }