Exemple #1
0
        /// <summary>
        /// Note, the different symbols in the .txt files correspond to various levels.
        /// We have: 0-Nothing/Sky,1-Ground,2-Hero,3-Enemy,4-StoneRed,5-StoneBlue, 6-StoneYellow, 7-Treasure, 8-Ladder
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            foodCount = 0;
            TheMatrix = MatrixInit();

            level = LevelRead("level" + levelCounter + ".txt");
            
            player = new hero(this, new Vector2(525, 525), new Vector2(525, 525));
            for (int i = 0; i < TheMatrix.Length; i++)
            {
                switch (level[i])
                {
                    case 0: // Sky
                        Components.Add(
                            myWorld[i] = new Ground(this, TheMatrix[i], level[i])
                            );
                        break;
                    case 1: // Ground
                        Components.Add(
                            myWorld[i] = new Ground(this, TheMatrix[i], level[i])
                            );
                        break;
                    case 2: // Player

                        Components.Add(myWorld[i] = player);
                        break;
                    case 3: // Enemy
                        Components.Add(myWorld[i] = new Enemy(this, TheMatrix[i], player, random.Next(0, 3), 100));
                        break;
                    case 4: // Ladder
                        Components.Add(myWorld[i] = new Ground(this, TheMatrix[i], level[i]));
                        break;

                    case 5: //Red Stone
                        Components.Add(myWorld[i] = new stone(1, 1, this, TheMatrix[i]));
                        break;

                    case 6: // Blue Stone
                        Components.Add(myWorld[i] = new stone(2, 1, this, TheMatrix[i]));
                        break;

                    case 7: // Yellow Stone
                        Components.Add(myWorld[i] = new stone(3, 1, this, TheMatrix[i]));
                        break;

                    case 8: // Treasure/Food
                        Components.Add(myWorld[i] = new treasure(1, random.Next(0, 27), this, TheMatrix[i]));
                        foodCount++;
                        break;
                    case 9:
                        // Add portal
                        Components.Add(myWorld[i] = new Portal(this, player, TheMatrix[i]));
                        break;
                }

            }


            base.Initialize();
        }