Beispiel #1
0
 // Hindernisse setzen, anzahl je nach schwierigkeitsgrad
 private void PlaceBarriers(int barrierPic)
 {
     for (int i = 0; i < difficulty; i++)
     {
         myBarrier = new Barrier(barrierSize);
         myBarrier.ShowBarrier(playground, pillarWidth, barrierPic);
         //tempPosition = myBarrier.GetPosition();
         if (gameStarted)
         {
             Apples.SetBarrierPosition(myBarrier.GetPosition());
         }
     }
 }
Beispiel #2
0
 private void ThirdLevel(int barrierPic)
 {
     System.Threading.Thread.Sleep(1000);
     // Listen leeren
     snake.Clear();
     Apples.ClearBarrierList();
     Apples.ClearSnakePartsList();
     playground.Children.Clear();
     AddSnake();
     myGrid.Background = new SolidColorBrush(Color.FromRgb(231, 220, 124));
     BorderColor       = Color.FromRgb(119, 162, 215);
     DrawPlayground();
     GameBreak();
     PlaceBarriers(barrierPic);
     myApple.ShowApple(playground, pillarWidth);
 }
Beispiel #3
0
        // Methode fuer den Start des Spiels
        private void Start()
        {
            // Geschwindigkeit setzen
            speedSnake          = 1000;
            timerSnake.Interval = TimeSpan.FromMilliseconds(speedSnake);
            gamePoints.LoeschePunkte();
            ProgressBarSpeed.Value = 0;
            ProgressBarLife.Value  = 0;
            // Listen leeren
            snake.Clear();
            if (gameStarted)
            {
                Apples.ClearBarrierList();
                Apples.ClearSnakePartsList();
            }

            // Spielfeld leeren
            playground.Children.Clear();

            points             = 0;
            time               = 0;
            direction          = 0;
            showPoints.Content = points;
            showTime.Content   = time;

            gameStarted   = true;
            _counterLevel = 1;
            NextLevel();

            // Einstellungen deaktivieren
            MenuEasy.IsEnabled    = false;
            MenuAvarage.IsEnabled = false;
            MenuHeavy.IsEnabled   = false;

            // ersten Apfel setzen
            myApple = new Apples(appleSize);
            myApple.ShowApple(playground, pillarWidth);

            ProgressBarLife.Value = 3;
            levelPoints           = 400;
        }
Beispiel #4
0
        // zum pruefen einer kollision mit dem Schlangenkopf
        private void ProofCollision()
        {
            //HitTestResult collAplle = VisualTreeHelper.HitTest(playground, myApple.GetPosition());
            HitTestResult hitted = VisualTreeHelper.HitTest(playground, snake[0].GetPosition());

            if (hitted != null)
            {
                string name = ((Shape)hitted.VisualHit).Name;
                // was haben wir getroffen?
                if (name == "Border")
                {
                    sound = new SoundPlayer(Properties.Resources.gameOver);
                    sound.Play();
                    EndGame();
                }

                if (name == "Hitbox" || name == "Snake")
                {
                    ProgressBarLife.Value -= 1;
                    if (ProgressBarLife.Value <= 0)
                    {
                        sound = new SoundPlayer(Properties.Resources.gameOver);
                        sound.Play();
                        EndGame();
                    }
                    damageCount = 0;
                    damageDone  = false;
                    timerLoseLife.Start();
                    sound = new SoundPlayer(Properties.Resources.damage);
                    sound.Play();
                    return;
                }
                if (name == "Apple")
                {
                    Apples.ClearSnakePartsList();
                    for (int index = 1; index < snake.Count; index++)
                    {
                        Apples.SetSnakePartsPosition(snake[index].GetPosition());
                    }
                    points                 = gamePoints.VeraenderePunkte(addPoints);
                    showPoints.Content     = points;
                    ProgressBarLife.Value += 0.1;
                    sound = new SoundPlayer(Properties.Resources.bite);
                    sound.Play();
                    // Geschwindigkeit der Schlange erhoehen, wenn nicht das Maximum schon erreicht ist
                    if (points % 50 == 0 && speedSnake > 100)
                    {
                        speedSnake         -= 100;
                        timerSnake.Interval = TimeSpan.FromMilliseconds(speedSnake);
                        if (speedUp)
                        {
                            oldSpeedSnake -= 100;
                        }
                    }
                    if (points % 100 == 0)
                    {
                        sound = new SoundPlayer(Properties.Resources.speedPlusOne);
                        sound.Play();
                        ProgressBarSpeed.Value += 1;
                    }
                    // einen teil hinten in der Schlange anhaengen
                    SnakeParts sPart = new SnakeParts(new Point(snake[snake.Count - 1].GetOldPosition().X, snake[snake.Count - 1].GetOldPosition().Y + snake[snake.Count - 1].GetSize()), Colors.Black);
                    snake.Add(sPart);
                    // den alten Apfel loeschen
                    myApple.RemoveApple(playground);
                    // einen neuen Apfel erzeugen
                    myApple = new Apples(appleSize);
                    myApple.ShowApple(playground, pillarWidth);
                    if (points == levelPoints && _counterLevel < 3)
                    {
                        levelPoints *= 2;
                        GameBreak();
                        sound = new SoundPlayer(Properties.Resources.nextLevel);
                        sound.Play();
                        _counterLevel++;
                        MessageBox.Show($"Glückwunsch! \nDu hast Level { _counterLevel } erreicht!", "Next Level!", MessageBoxButton.OK, MessageBoxImage.Information);
                        NextLevel();
                    }
                }
            }
        }