Example #1
0
        /// <summary>
        /// Here every gameObject is initialized
        /// for the snake game
        /// creating the snakeObject
        /// creating the map
        /// creating the food
        ///
        /// </summary>
        private void initGameData()
        {
            // Initializze our gameobject list
            gameTime      = new ShowTimeObject(new Rectangle(new Point(300, 0), new Size(10, 10)));
            gameObstacles = new List <IGameObject> ();
            snakeFood     = new List <IGameObject> ();
            // Creates our implemented snake
            snake      = new Snake();
            background = GameUtils.getBlockObject(0, 0, 600, 600);
            background.passData(new GameData(GameState.None));
            snakeFood.Add(GameUtils.getRandomSnakeFoodObject());
            ShowScoreObject gameScore = new ShowScoreObject(new Rectangle(new Point(0, 200), new Size(20, 20)));

            if (realHighScore < highScore)
            {
                realHighScore = highScore;
            }

            gameScore.highScore = realHighScore;
            highScore           = 0;
            score          = 0;
            this.gameScore = gameScore;
            // Create the obstacles in the map
            createPlayingField();
        }
Example #2
0
        /// <summary>
        /// Creates the playing field.
        /// </summary>
        private void createPlayingField()
        {
            int fieldWidth  = 500;
            int fieldHeigth = 500;
            int blockHeight = 20;
            int blockWidth  = 20;

            for (int i = 0; i <= fieldWidth; i += blockWidth)
            {
                gameObstacles.Add(GameUtils.getBlockObject(0, i, blockWidth, blockHeight));
                gameObstacles.Add(GameUtils.getBlockObject(fieldWidth, i, blockWidth, blockHeight));
            }
            for (int i = 0; i <= fieldHeigth; i += blockWidth)
            {
                gameObstacles.Add(GameUtils.getBlockObject(i, 0, blockWidth, blockHeight));
                gameObstacles.Add(GameUtils.getBlockObject(i, fieldHeigth, blockWidth, blockHeight));
            }
        }