Example #1
0
        protected override void ReadAppleTag(Level creationLevel_DC, XmlReader reader, Apple apple_DC)
        {
            SLLevel creationLevel = creationLevel_DC as SLLevel;
            SLApple apple         = apple_DC as SLApple;

            base.ReadAppleTag(creationLevel, reader, apple);

            reader.MoveToAttribute("img");
            string appleFilename = reader.Value;

            reader.MoveToAttribute("offsetY");
            apple.AppleOffsetY = Double.Parse(reader.Value);

            apple.AppleImage = SnakeUtils.LoadImage(appleFilename);
            creationLevel.LevelCanvas.Children.Add(apple.AppleImage);
        }
Example #2
0
        public static double CalcAnimationOffsetY(SLLevel curLevel, SnakeUtils.Directions direction)
        {
            double animationOffsetY = 0.0;

            switch (direction)
            {
            case SnakeUtils.Directions.Down: animationOffsetY = 0.0; break;

            case SnakeUtils.Directions.Left: animationOffsetY = (double)(curLevel.TileSize - curLevel.SnakeOffsetY); break;

            case SnakeUtils.Directions.Right: animationOffsetY = (double)2 * (curLevel.TileSize - curLevel.SnakeOffsetY); break;

            case SnakeUtils.Directions.Up: animationOffsetY = (double)3 * (curLevel.TileSize - curLevel.SnakeOffsetY); break;
            }
            return(animationOffsetY);
        }
Example #3
0
        protected override void ReadLevelTag(Level creationLevel_DC, XmlReader reader)
        {
            SLLevel creationLevel = creationLevel_DC as SLLevel;

            base.ReadLevelTag(creationLevel, reader);

            reader.MoveToAttribute("tileSize");
            creationLevel.TileSize = Int32.Parse(reader.Value);

            creationLevel.LevelCanvas.Width  = (double)(creationLevel.LevelWidth * creationLevel.TileSize);
            creationLevel.LevelCanvas.Height = (double)(creationLevel.LevelHeight * creationLevel.TileSize);

            reader.MoveToAttribute("background");
            creationLevel.LevelCanvas.Background = SnakeUtils.LoadBackgroundImage(reader.Value);

            reader.MoveToAttribute("borderBackground");
            creationLevel.BorderBackground = SnakeUtils.LoadBackgroundImage(reader.Value);
        }
Example #4
0
        protected override void ReadObjectTag(Level creationLevel_DC, XmlReader reader, LevelObject levObject_DC)
        {
            SLLevelObject levObject     = levObject_DC as SLLevelObject;
            SLLevel       creationLevel = creationLevel_DC as SLLevel;

            base.ReadObjectTag(creationLevel_DC, reader, levObject_DC);

            levObject.Pos = new Point((double)levObject.ObjectPosX * creationLevel.TileSize, (double)levObject.ObjectPosY * creationLevel.TileSize);

            reader.MoveToAttribute("offsetY");
            levObject.OffsetY = Double.Parse(reader.Value);

            reader.MoveToAttribute("filename");
            levObject.ObjectImage = SnakeUtils.LoadImage(reader.Value);

            levObject.ObjectImage.SetValue(Canvas.LeftProperty, levObject.Pos.X);
            levObject.ObjectImage.SetValue(Canvas.TopProperty, levObject.Pos.Y + levObject.OffsetY);
            creationLevel.LevelCanvas.Children.Add(levObject.ObjectImage);
        }
Example #5
0
        /// <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);
                    }
                }
            }
        }
Example #6
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";
        }
Example #7
0
        public SLTail(SnakeUtils.Directions direction, int tailPosX, int tailPosY, SLLevel curLevel)
            : base(direction, tailPosX, tailPosY, curLevel)
        {
            CurLevel = curLevel;
            _pos.X   = (double)(tailPosX * CurLevel.TileSize);
            _pos.Y   = (double)(tailPosY * CurLevel.TileSize);

            switch (direction)
            {
            case SnakeUtils.Directions.Up: _pos.Y += CurLevel.TileSize;
                break;

            case SnakeUtils.Directions.Right: _pos.X -= CurLevel.TileSize;
                break;

            case SnakeUtils.Directions.Down: _pos.Y -= CurLevel.TileSize;
                break;

            case SnakeUtils.Directions.Left: _pos.X += CurLevel.TileSize;
                break;
            }


            if (CurLevel.AnimatedSnake)
            {
                _initAnimation();
                SnakeUtils.InitAnimationInDict(AnimationsDict, "win", CurLevel.Animation.FilenameWin, CurLevel.Animation.WinFrames, CurLevel.LevelCanvas);
                SnakeUtils.InitAnimationInDict(AnimationsDict, "grow", CurLevel.Animation.FilenameGrow, CurLevel.Animation.GrowFrames, CurLevel.LevelCanvas);
                SnakeUtils.InitAnimationInDict(AnimationsDict, "shrink", CurLevel.Animation.FilenameShrink, CurLevel.Animation.ShrinkFrames, CurLevel.LevelCanvas);
            }
            else
            {
                TailImage = SnakeUtils.LoadImage(curLevel.Animation.FilenameTail);
                CurLevel.LevelCanvas.Children.Add(TailImage);
            }

            TailImage.SetValue(Canvas.LeftProperty, Pos.X);
            TailImage.SetValue(Canvas.TopProperty, Pos.Y + CurLevel.SnakeOffsetY);
        }