示例#1
0
        private void GameOver()
        {
            SoundsManager.PlayGameOverSound();

            gameTimer.Stop();
            timer.Stop();
            stopwatch.Stop();
            scoreHighTextBlock.Text = score.ToString();
            scoreOverTextBlock.Text = score.ToString();

            if (score > HighScore.Default.Top)
            {
                highScoreMessage.Visibility = Visibility.Visible;
                HighScore.Default.Top       = score;
                HighScore.Default.Save();
            }
            else
            {
                gameOverMessage.Visibility = Visibility.Visible;
            }
        }
示例#2
0
        private void EatFood()
        {
            SoundsManager.PlayPointSound();

            snakeLength++;
            score += snakeLength * 10;
            curScoreTextBlock.Text = $"Score:\n {score}";

            gameSpeed         -= 5;
            gameTimer.Interval = TimeSpan.FromMilliseconds(gameSpeed < gameSpeedMax ? gameSpeedMax : gameSpeed);

            gameArea.Children.Remove(curFood.Element);
            curFood = FindNewFoodPlace();

            if (curFood == null) //Game won
            {
                GameOver();
            }

            CreateSnake();
            CreateFood();
        }