示例#1
0
        /// <summary>
        ///     Initialize... stuff.
        /// </summary>
        protected void Initialize()
        {
            Dispatcher.Invoke((Action)(() =>
            {
                try
                {
                    App.Info("Initializing...");
                    Clear();

                    // Check input devices
                    if (0 == WaveInEvent.DeviceCount)
                    {
                        throw new Exception("No input device found. Can't continue.");
                    }

                    // Initializes the audio input device
                    var waveIn = new WaveInEvent
                    {
                        DeviceNumber = Options.InputDeviceId,
                        BufferMilliseconds = 100,
                        NumberOfBuffers = 3,
                        WaveFormat = new WaveFormat(
                            Options.InputSampleRate,
                            Options.InputSampleBits,
                            Options.InputChannels)
                    };

                    // Loading animations from XAML
                    _ledGreenBlinking = (Storyboard)Resources["GreenLedBlinking"];
                    _timerBlinking = (Storyboard)Resources["TimerBlinking"];

                    // Create the shot timer
                    ShotTimer = new ShotTimer(Options, WhenShotDetected, waveIn);

                    // For binding the TimeElapse property
                    DataContext = ShotTimer;

                    // Create the options window
                    _optionsWindow = new OptionsWindow(Options);
                }
                catch (ApplicationException exception)
                {
                    var message = String.Format("{0}\nReverting to previous settings.", exception.Message);

                    // We can stop the bleeding!
                    App.DialogContinue(message);

                    // Revert the previous config
                    Options = _previousOptions;

                    // Try again
                    var thread = new Thread(Initialize);
                    thread.Start();
                }
                catch (Exception e)
                {
                    // Let's crash that party
                    App.DialogFatalError(e);
                }
            }));
        }
    void Start()
    {
        isFiring = false;
        firstShot = true;
        active = true;
        shootTimer = 0;
        shotTimer = new ShotTimer [WeaponInfo.getWeaponCount () + 1];
        ammo = new Ammo[WeaponInfo.getWeaponCount () + 1];

        for (int i = 0; i < WeaponInfo.getWeaponCount(); i++) {
            shotTimer [i] = new ShotTimer ();
            ammo [i] = new Ammo (100, 100);
        }
    }