Ejemplo n.º 1
0
        /// <summary>
        /// ОБРАБОТКА СОБЫТИЙ КЛАВИАТУРЫ
        /// Низкоскоростные события
        /// </summary>
        private bool KeyboardProc()
        {
            // Запрос к клавиатуре
            keyboardState = Keyboard.GetState();

            // В НЕЗАВИСИМОСТИ ОТ СОСТОЯНИЯ ИГРЫ
            // Настройки звука
            if (!showExitMsg)
            {
                if (keyboardState.IsKeyDown(Keys.S))                        // Sound on/off
                {
                    isSound = !isSound;
                    SOnOff.Play();

                    // Была нажата клавиша
                    return(true);
                }

                if (keyboardState.IsKeyDown(Keys.M))
                {
                    if (isMusic)                                                // Music on/off
                    {
                        isMusic = false;
                        MediaPlayer.Stop();
                    }
                    else
                    {
                        isMusic = true;
                        MediaPlayer.Play(Content.Load <Song> ("Sounds/Music1"));
                    }
                    SOnOff.Play();

                    return(true);
                }
            }

            // В ЗАВИСИМОСТИ ОТ СОСТОЯНИЯ ИГРЫ
            switch (gameStatus)
            {
            //////////////////////////////////////////////////////////////////
            case GameStatus.Start:
                // Немедленный выход
                if (keyboardState.IsKeyDown(Keys.Escape))
                {
                    this.Exit();
                }

                // Справка
                if (keyboardState.IsKeyDown(Keys.F1))
                {
                    gameStatus = GameStatus.Help;

                    return(true);
                }

                // Переход далее
                if (keyboardState.IsKeyDown(Keys.Space))
                {
                    // Переключение параметров
                    gameStatus = GameStatus.Playing;

                    // Загрузка уровня
                    levelNumber--;
                    LoadNextLevel();

                    return(true);
                }

                break;

            //////////////////////////////////////////////////////////////////
            case GameStatus.Help:
                // Возврат
                if (keyboardState.IsKeyDown(Keys.Escape))
                {
                    gameStatus = GameStatus.Start;

                    return(true);
                }

                break;

            //////////////////////////////////////////////////////////////////
            case GameStatus.Playing:

                // Нажатие паузы и продолжения
                if (!showExitMsg)                                       // Нельзя ничего делать, если появилось сообщение о выходе
                {
                    if (isAlive && keyboardState.IsKeyDown(Keys.Space)) // Pause
                    {
                        if (isWorking)
                        {
                            isWorking = false;

                            if (isSound)
                            {
                                SStop.Play();
                            }
                        }
                        else                                                                                // Continue
                        {
                            showLevelMsg = false;
                            isWorking    = true;

                            if (isSound)
                            {
                                SStart.Play();
                            }
                        }

                        return(true);
                    }

                    // Нажатие клавиши продолжения
                    if (keyboardState.IsKeyDown(Keys.Space) && !isWorking && !isAlive)
                    {
                        LoadNextLevel();

                        return(true);
                    }

                    // Проверка на выход
                    if (keyboardState.IsKeyDown(Keys.Escape))
                    {
                        // Пауза
                        isWorking = false;

                        // Сообщение
                        showExitMsg = true;

                        // Звук
                        if (isSound)
                        {
                            SOnOff.Play();
                        }

                        return(true);
                    }
                }

                // Попытка выхода
                if (showExitMsg)
                {
                    // Выход из игры (yes)
                    if (keyboardState.IsKeyDown(Keys.Y))
                    {
                        this.Exit();
                    }

                    // Продолжение (back)
                    if (keyboardState.IsKeyDown(Keys.N))
                    {
                        showExitMsg = false;

                        return(true);
                    }
                }

                break;

            //////////////////////////////////////////////////////////////////
            case GameStatus.Finish:
                if (keyboardState.IsKeyDown(Keys.Space))
                {
                    // Переключение
                    gameStatus = GameStatus.Start;

                    return(true);
                }

                break;

                //////////////////////////////////////////////////////////////////
            }

            // Не было ни одного нажатия
            return(false);
        }
Ejemplo n.º 2
0
        protected override void OnBarUpdate()
        {
            #region Filtered Wave

            if (CurrentBar == 0)                                                               //initialize variables
            {
                dVal = devType == DeviationType.Points ? devValue * TickSize : devValue / 100; // adjust deviation value to points or percent
                ResetPK(); ResetTR();
                return;
            }

            if (WaveCount() == 0)             //update variables unitl first peak or trough is formed
            {
                if (Comp(High[0], pk) >= 0)
                {
                    ResetPK();                                         // new high
                }
                else if (Comp(Low[0], tr) <= 0)
                {
                    ResetTR();                                             // new low
                }
            }

            if (Comp(Low[0], pkRS) <= 0)         //Peak has formed; downswing
            {
                if (swing != -1)                 // Set peak and switch to downswing
                {
                    peak.Insert(0, pk);
                    peakBar.Insert(0, pkBar);
                    if (trough.Count > 0)
                    {
                        midPoint.Insert(0, ((double)peak[0] + (double)trough[0]) / 2);
                        midBar.Insert(0, ((int)peakBar[0] + (int)troughBar[0]) / 2);
                        if (midBar.Count > 1)
                        {
                            int xMid = CurrentBar - (int)midBar[0];
                            DrawDot("Mid" + CurrentBar, true, xMid, (double)midPoint[0], Color.Gold);
                        }
                    }
                    int xPeak = CurrentBar - pkBar;
                    DrawDot("Peak" + pkBar, true, xPeak, (double)peak[0], Color.Green);
                    swing = -1;
                }
                ResetTR();
                pk = trRS; pkRS = pk - LDev(pk, dVal);
            }

            else if (Comp(High[0], trRS) >= 0)  //Trough has formed; upswing
            {
                if (swing != 1)                 // Set trough and switch to upswing
                {
                    trough.Insert(0, tr);
                    troughBar.Insert(0, trBar);
                    if (peak.Count > 0)
                    {
                        midPoint.Insert(0, ((double)peak[0] + (double)trough[0]) / 2);
                        midBar.Insert(0, ((int)peakBar[0] + (int)troughBar[0]) / 2);
                        if (midBar.Count > 1)
                        {
                            int xMid = CurrentBar - (int)midBar[0];
                            DrawDot("Mid" + CurrentBar, true, xMid, (double)midPoint[0], Color.Gold);
                        }
                    }
                    int xTrough = CurrentBar - trBar;
                    DrawDot("Trough" + trBar, true, xTrough, (double)trough[0], Color.Blue);
                    swing = 1;
                }
                ResetPK();
                tr = pkRS; trRS = tr + HDev(tr, dVal);
            }

            #endregion

            #region Set Initial Stops

            if (WaveCount() < 5)
            {
                ll = Math.Min(ll, Low[0]);
                hh = Math.Max(hh, High[0]);
                return;
            }
            if (WaveCount() == 5)
            {
                init += 1;
                if (init == 1)
                {
                    //double b = MAX(High, CurrentBar)[0] + TickSize;
                    //double s = MIN(Low, CurrentBar)[0] - TickSize;
                    double b = hh + TickSize;
                    double s = ll - TickSize;
                    BStop.Set(b);
                    SStop.Set(s);
                    return;
                }
            }

            #endregion

            #region Strategy

            switch (trend)
            {
            case 0:                               // neutral trend - strategy starting
                if (Comp(High[0], BStop[1]) >= 0) // up trend
                {
                    BStop.Set(High[0] + TickSize); SStop.Set(SStop[1]);
                    trend = 1; ss = SStop[1]; slope = 0;
                }
                else if (Comp(Low[0], SStop[1]) <= 0)                           // down trend
                {
                    SStop.Set(Low[0] - TickSize); BStop.Set(BStop[1]);
                    trend = -1; bs = BStop[1]; slope = 0;
                }
                else
                {
                    BStop.Set(BStop[1]); SStop.Set(SStop[1]);
                }
                break;

            case 1:
                if (Comp(Low[0], SStop[1]) <= 0)                                // switch to down trend
                {
                    SStop.Set(Low[0] - TickSize); BStop.Set(BStop[1]);
                    trend = -1; bs = BStop[1]; slope = 0;
                }
                else                         // continue uptrend
                {
                    BStop.Set(Math.Max(BStop[1], High[0] + TickSize));
                    slope = Math.Max(slope, MSlope());
                    ss   += slope;
                    double s = Math.Floor(ss * (1.0 / TickSize)) / (1.0 / TickSize);
                    if (Comp(s, MIN(Low, period)[0] - TickSize) >= 0)
                    {
                        s = MIN(Low, period)[0] - TickSize; ss = s;
                    }
                    SStop.Set(s);
                }

                break;

            case -1:
                if (Comp(High[0], BStop[1]) >= 0)                                       // switch to up trend
                {
                    BStop.Set(High[0] + TickSize); SStop.Set(SStop[1]);
                    trend = 1; ss = SStop[1]; slope = 0;
                }
                else                         // continue downtrend
                {
                    SStop.Set(Math.Min(SStop[1], Low[0] - TickSize));
                    slope = Math.Min(slope, MSlope());
                    bs   += slope;
                    double b = Math.Ceiling(bs * (1.0 / TickSize)) / (1.0 / TickSize);
                    //b = Math.Max(b, MAX(High, period)[0] + TickSize);
                    if (Comp(b, MAX(High, period)[0] + TickSize) <= 0)
                    {
                        b = MAX(High, period)[0] + TickSize; bs = b;
                    }
                    BStop.Set(b);
                }

                break;
            }

            #endregion
        }