示例#1
1
        /// <summary>
        /// Initializes a new instance of the MainViewModel class.
        /// </summary>
        public MainViewModel()
        {
            scoreStorage = new ScoreStorage();
            HighScores = new ObservableCollection<Score>(scoreStorage.GetScores());
            game = new Game();
            game.PlayerLost += GameOnPlayerLost;
            game.PlayerTooFast += GameOnPlayerTooFast;
            game.PlayerWon += GameOnPlayerWon;
            game.CountdownTick += GameOnCountdownTick;
            game.WaitForItStarted += GameOnWaitForItStarted;
            game.TapDanceStarted += GameOnTapDanceStarted;
            game.ButtonsCanBeClickedChanged += GameOnButtonsCanBeClickedChanged;

            patternTimer = new DispatcherTimer();
            patternTimer.Tick += PatternTimerOnTick;
            patternTimer.Interval = buttonLightingTime;

            Button1Command = new RelayCommand(() => game.ButtonClicked(0), () => game.ButtonsCanBeClicked);
            Button2Command = new RelayCommand(() => game.ButtonClicked(1), () => game.ButtonsCanBeClicked);
            Button3Command = new RelayCommand(() => game.ButtonClicked(2), () => game.ButtonsCanBeClicked);
            Button4Command = new RelayCommand(() => game.ButtonClicked(3), () => game.ButtonsCanBeClicked);
            StartRetryCommand = new RelayCommand(() => StartNewPattern(game.GetNewPattern()), () => true);

            Button1BackColor = new SolidColorBrush(Colors.Black);
            Button2BackColor = new SolidColorBrush(Colors.Black);
            Button3BackColor = new SolidColorBrush(Colors.Black);
            Button4BackColor = new SolidColorBrush(Colors.Black);
            StartRetryText = "Start";
            SetNumberButtonsToDefault();
        }