/// <summary> /// /// Set z-Level to let Snake and Tail-Objects appear "behind objects" /// </summary> /// <param name="curLevel">The current Level object</param> /// <param name="snake">Snake object</param> /// <param name="tailList">Linked List containing all tail objects</param> public static void SetZIndex(SLLevel curLevel, SLSnake snake, LinkedList <Tail> tailList) { //Check for all apples foreach (SLApple apple in curLevel.AppleObjects) { apple.AppleImage.SetValue(Canvas.ZIndexProperty, apple.ApplePosY); } //Check for all Objects in Level foreach (SLLevelObject levelObject in curLevel.LevelObjects) { levelObject.ObjectImage.SetValue(Canvas.ZIndexProperty, levelObject.ObjectPosY); } //Check for the tail of snake foreach (SLTail tail in tailList) { tail.TailImage.SetValue(Canvas.ZIndexProperty, tail.TailPosY); if (curLevel.AnimatedSnake) { for (int y = 0; y < 4; y++) { for (int x = 0; x < curLevel.Animation.AnimationFrames; x++) { tail.BufferedImage[x, y].SetValue(Canvas.ZIndexProperty, tail.TailPosY); } } } } snake.SnakeImage.SetValue(Canvas.ZIndexProperty, snake.SnakePosY); if (curLevel.AnimatedSnake) { for (int y = 0; y < 4; y++) { for (int x = 0; x < curLevel.Animation.AnimationFrames; x++) { snake.BufferedImage[x, y].SetValue(Canvas.ZIndexProperty, snake.SnakePosY); } } } }
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"; }