Example #1
0
        // Запускает игру
        public void Start()
        {
            int now = DateTime.Now.Second;

            _gamePad.PressDown = () => MoveBomber(1, 0);

            _gamePad.PressLeft  = () => MoveBomber(0, -1);
            _gamePad.PressRight = () => MoveBomber(0, 1);

            _gamePad.PressUp = () => MoveBomber(-1, 0);

            _gamePad.PressSpace = () => OnPressSpace();

            _gamePad.PressR = () => RemoteBombBoom();
            _gamePad.PressP = () => PressPause(isPaused);



            while (true)
            {
                if (ListWithMonster.Count == 0)
                {
                    if (_mapManager.CheckAvailableMap())
                    {
                        GetNextLevel();
                    }
                    else
                    {
                        _display.ShowYouWin();

                        break;
                    }
                }



                if (_bomber.IsDead) //если бомбера убили, то рисуем его на первочальной позиции
                {
                    Logging.WriteDebbug("Пытаюсь помереть");
                    _display.SignalOnDead();
                    _bomber.IsHaveFarUpgrate       = false;
                    _bomber.IsHaveRemoteUpgrate    = false;
                    _bomber.IsHaveMultiBombUpgrade = false;
                    _bomber.LiveCount -= 1;
                    _display.ShowLive(_bomber.LiveCount);

                    _bomber.IsDead = false;
                    _map.ArrayMap[_map.FirstPositionBomber.X, _map.FirstPositionBomber.Y] = _bomber;
                    isWantDrow = true;
                }

                if (_bomber.LiveCount <= 0) //если нет жизней ,то заканчиваем игру
                {
                    Logging.WriteTrace("Конец игры");
                    _display.CleanMap();

                    isWantDrow = true;
                    _display.ShowGameOver();
                    break;
                }

                if (_bomber.IsOnBomb)
                {
                    var currentPosition = new PointInMap();
                    currentPosition = GetCurrentPosition(_map);
                    if (!_bomber.NeedChangeImage)
                    {
                        _bomber.NeedChangeImage = true;
                        _map.ArrayMap[currentPosition.X, currentPosition.Y] = new BomberOnBomb();
                    }
                    else
                    {
                        _bomber.NeedChangeImage = false;
                        _map.ArrayMap[currentPosition.X, currentPosition.Y] = _bomber;
                    }
                    isWantDrow = true;
                    System.Threading.Thread.Sleep(50);
                }
                if (now != DateTime.Now.Second)
                {
                    Logging.WriteInfo("прошла секунда, шагаю");

                    now = DateTime.Now.Second;

                    UpgradeUpTime();
                    for (int i = 0; i < ListWithMonster.Count; i++)
                    {
                        SetNewPositionMonster(ListWithMonster[i]);
                    }

                    int bombCount = 0;
                    while (bombCount != ListWithBomb.Count)
                    {
                        var bomb = ListWithBomb[bombCount];
                        bomb.CurrentTime += 1;
                        if (bomb.CurrentTime == bomb.TimeToBoom)
                        {
                            if (!_bomber.IsHaveRemoteUpgrate)
                            {
                                OnBombBoom(bomb);
                                ListWithBomb.Remove(bomb);
                                bombCount--;
                            }
                        }
                        bombCount++;
                    }
                    isSecondNow = true;
                }
                if (!isDrawNow)
                {
                    if (((isWantDrow) || (isSecondNow)) || ((isSecondNow) && (isWantDrow)))
                    {
                        isWantDrow  = false;
                        isSecondNow = false;
                        isDrawNow   = true;
                        lock (_lock)
                        {
                            System.Diagnostics.Stopwatch sw = new Stopwatch();
                            sw.Start();
                            _display.DrawMap();
                            sw.Stop();
                            Logging.WriteTrace("Время выполнения" + (sw.ElapsedMilliseconds / 100.0).ToString());
                        }
                        isDrawNow = false;
                    }
                }
            }
        }