Exemplo n.º 1
0
        public static new SLLevel GenerateLevel(string levelname)
        {
            SLLevel creationLevel = new SLLevel();

            SLLevelBuilder builder = new SLLevelBuilder();

            Canvas levelCanvas = new Canvas();

            creationLevel.LevelCanvas = levelCanvas;

            builder.ReadLevel(creationLevel, levelname);

            return(creationLevel);
        }
Exemplo n.º 2
0
        private void _loadLevel(string levelName)
        {
            //Initialize Level and Snake
            try
            {
                if (level1SL != null)
                {
                    level1SL.ChangedScoreEvent -= ChangedScore;
                    level1SL.HighScoreEvent    -= HighScore;
                    level1SL.ChangedSpeedEvent -= ChangedSpeed;
                }
                level1SL = SLLevelBuilder.GenerateLevel(levelName);
            }
            catch (FormatException)
            {
                //This error occurs when in the Level xml file text data is set where numbers are expected
                Presenter.MessageText = "Fehler beim Lesen der Leveldaten!";
                return;
            }
            catch (IndexOutOfRangeException)
            {
                //This error occurs when in the Level xml file invalid positions are set
                //(e.g. X,Y:11,12 as snake starting position, while the level has a size of 10x10)
                Presenter.MessageText = "Ungültige Level Definition";
                return;
            }
            catch (XmlException)
            {
                //This error occurs when the Level file can't be opened
                Presenter.MessageText = "Level konnte nicht geöffnet werden";
            }
            snakeSL = new SLSnake(level1SL);

            GameField.Children.Add(level1SL.LevelCanvas);

            level1SL.ChangedScoreEvent += new Level.ChangedScoreEventHandler(ChangedScore);
            level1SL.HighScoreEvent    += new Level.HighScoreEventHandler(HighScore);
            level1SL.ChangedSpeedEvent += new SLLevel.ChangedSpeedEventHandler(ChangedSpeed);

            Presenter.MessageText = "Ziel sind " + level1SL.TargetScore + " Nüsse";
        }