Ejemplo n.º 1
2
        public Arena(int width, int height)
        {
            Width = width;
            Height = height;

            Cells = new Food[width, height];

            Snake = new SnakeModel(this);
        }
Ejemplo n.º 2
0
        private void Restart()
        {
            IsGameStarted = false;

            _area.Children.Clear();
            DispatcherTimer.Stop();

            Snake = new SnakeModel();
            Food  = new List <FoodModel>();

            _pauseTextBlock.Text = "\uf04b";

            _pauseTextTextBlock.Visibility = Visibility.Hidden;
            _restartTextBlock.Visibility   = Visibility.Hidden;
            IsPaused = !IsPaused;

            QuestManager.SaveQuest();

            QuestManager.CheckQuest(User, Score, Timer);
            QuestManager.Quest.ClearCurrentValue();
            UpdateQuest();

            CheckResult();
            DisplayRecords();

            Start();
        }
Ejemplo n.º 3
0
        private void Stop()
        {
            IsGameStarted = false;

            SoundManager.PlaySound(Soundtrack.GameOver);
            SoundManager.PlayBGM(BackgroundMusic.Menu);
            SoundManager.ChangeBGMSpeed(1);

            _reasonDiedTextBlock.Text  = Snake.ReasonDied;
            _scoreResultTextBlock.Text = $"Time: {TimerToString}       Score: {Score}";

            _area.Children.Clear();
            DispatcherTimer.Stop();

            Snake = new SnakeModel();
            Food  = new List <FoodModel>();

            _pauseTextBlock.Text = "\uf04b";

            ShowAreaTextBlocks();

            QuestManager.TryStartNewGame();
            UpdateQuest();

            CheckResult();
            DisplayRecords();
        }
Ejemplo n.º 4
0
        public Arena(int width, int height)
        {
            Width  = width;
            Height = height;

            Cells = new Food[width, height];

            Snake = new SnakeModel(this);
        }
Ejemplo n.º 5
0
        public void RefreshGame()
        {
            SetDeffaultSettings();

            IsGameStarted = false;
            IsPaused      = false;

            _area.Children.Clear();
            DispatcherTimer.Stop();

            Snake = new SnakeModel();
            Food  = new List <FoodModel>();

            HideAreaTextBlocks();

            _startTextBlock.Visibility = Visibility.Visible;
            _titleTextBlock.Visibility = Visibility.Visible;

            _pauseTextTextBlock.Visibility = Visibility.Hidden;
        }
Ejemplo n.º 6
0
        private void SetDeffaultSettings()
        {
            if (FastMoveEffectTimer >= 0)
            {
                Settings.Speed /= 2;
            }
            if (SlowMoveEffectTimer >= 0)
            {
                Settings.Speed *= 2;
            }

            DispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, Settings.Speed);

            DoubleScoreEffectTimer = -1;
            FastMoveEffectTimer    = -1;
            SlowMoveEffectTimer    = -1;

            ScoreMultiplier = 1;

            FoodModel.ChangeFoodColor(Food, Brushes.Red);

            FoodModel.IsGoldenFoodShown  = false;
            FoodModel.IsSpecialFoodShown = false;

            _scoreTextBlock.Text = "0";
            _timeTextBlock.Text  = "00:00";
            _area.Background     = Settings.Background;
            _area.Opacity        = 1;

            HideAreaTextBlocks();

            score = 0;
            Timer = new DateTime();

            Snake = new SnakeModel(Settings.BodyColor, Settings.HeadColor);

            switch (Settings.Difficulty)
            {
            case Difficulties.Easy:
                Snake.CanTeleport = true;
                CanShowWalls      = false;
                break;

            case Difficulties.Normal:
                Snake.CanTeleport = false;
                CanShowWalls      = false;
                break;

            case Difficulties.Hard:
                Snake.CanTeleport = false;
                CanShowWalls      = true;
                CreateWalls();
                FoodModel.Walls = Obstacles;
                break;

            case Difficulties.Python:
                Snake.CanTeleport = false;
                CanShowWalls      = true;
                CreateWalls();
                FoodModel.Walls = Obstacles;
                Snake.Starve    = 60;
                break;
            }

            for (int i = Settings.FoodSpawnCount; i > 0; i--)
            {
                FoodModel food = new FoodModel();
                food.NewPosition(Snake);

                Food.Add(food);
            }

            _pauseTextBlock.Text = "\uf04c";
        }