Esempio n. 1
0
         void createMaps()
        {
            boxs = new List<Box>();
            bonuses = new List<bonusElements>();
            enemies = new List<EnemyCollection>();
            string[] lines = File.ReadAllLines(@"D:/Layer.txt");
            int en=0, bon = 0;

            levelLength = 100 * lines.Count();
            int x = 0;
            int y = 0;
            int i=lines.Count()-1, j = 0;

            for(;i >= 0;i--)
            {
                for(;j < lines[i].Length;j++)
                {
                    char c = lines[i][j];
                    switch(c)
                    {
                        case '1':
                        {
                            Rectangle boxrect = new Rectangle(0, 0, 100, 20);
                            Vector2 boxposition = GetScreenRect(new Vector2(x, y));
                            Box box = new Box(ref txtWall, boxposition, boxrect, game);
                            boxs.Add(box);
                            break;
                        }
                        case '2':
                        {

                            bon = (int)new Random().Next(0, 2);
                            switch(en)
                            {
                                case 0:
                                {
                                    Rectangle enrect = new Rectangle(0, 0, 100, 65);
                                    Vector2 enposition = GetScreenRect(new Vector2(x, y));
                                    txtEnemy = encollection[en];
                                    EnemyCollection enemy = new EnemyCollection(ref txtEnemy, enposition, enrect, game);
                                    enemies.Add(enemy);
                                    en++;
                                    break;
                                }
                                case 1:
                                {
                                    Rectangle enrect = new Rectangle(0, 0, 173, 95);
                                    Vector2 enposition = GetScreenRect(new Vector2(x, y));
                                    txtEnemy = encollection[en];
                                    EnemyCollection enemy = new EnemyCollection(ref txtEnemy, enposition, enrect, game);
                                    enemies.Add(enemy);
                                    en++;
                                    break;
                                }
                                case 2:
                                {
                                    Rectangle enrect = new Rectangle(0, 0, 120, 100);
                                    Vector2 enposition = GetScreenRect(new Vector2(x, y));
                                    txtEnemy = encollection[en];
                                    EnemyCollection enemy = new EnemyCollection(ref txtEnemy, enposition, enrect, game);
                                    enemies.Add(enemy);
                                    en++;
                                    break;
                                }
                                case 3:
                                {
                                    Rectangle enrect = new Rectangle(0, 0, 50, 100);
                                    Vector2 enposition = GetScreenRect(new Vector2(x, y));
                                    txtEnemy = encollection[en];
                                    EnemyCollection enemy = new EnemyCollection(ref txtEnemy, enposition, enrect, game);
                                    enemies.Add(enemy);
                                    en++;
                                    break;
                                }
                                case 4:
                                {
                                    Rectangle enrect = new Rectangle(0, 0, 80, 105);
                                    Vector2 enposition = GetScreenRect(new Vector2(x, y));
                                    txtEnemy = encollection[en];
                                    EnemyCollection enemy = new EnemyCollection(ref txtEnemy, enposition, enrect, game);
                                    enemies.Add(enemy);
                                    en++;
                                    break;
                                }
                                case 5:
                                {
                                    Rectangle enrect = new Rectangle(0, 0, 60, 100);
                                    Vector2 enposition = GetScreenRect(new Vector2(x, y));
                                    txtEnemy = encollection[en];
                                    EnemyCollection enemy = new EnemyCollection(ref txtEnemy, enposition, enrect, game);
                                    enemies.Add(enemy);
                                    en = 0;
                                    break;
                                }

                            }


                            break;
                        }
                        case '3':
                        {
                            bon = (int) new Random().Next(0,2);
                            switch(bon)
                            {
                                case 2:
                                {
                                    Rectangle bonrect = new Rectangle(0, 0, 63, 110);                                //max
                                    Vector2 bonposition = GetScreenRect(new Vector2(x, y));
                                    txtBonus = boncollection[0];
                                    bonusElements bonus = new bonusElements(ref txtBonus, bonposition, bonrect, game);
                                    bonuses.Add(bonus);
                                    bon=0;
                                    break;
                                }
                                case 1:
                                {
                                    Rectangle bonrect = new Rectangle(0, 0, 21, 80);                                     //midle
                                    Vector2 bonposition = GetScreenRect(new Vector2(x, y));
                                    txtBonus = boncollection[bon];
                                    bonusElements bonus = new bonusElements(ref txtBonus, bonposition, bonrect, game);
                                    bonuses.Add(bonus);
                                    bon++;
                                    break;
                                }
                                case 0:
                                {
                                    Rectangle bonrect = new Rectangle(0, 0, 80, 60);                                    //min
                                    Vector2 bonposition = GetScreenRect(new Vector2(x, y));
                                    txtBonus = boncollection[2];
                                    bonusElements bonus = new bonusElements(ref txtBonus, bonposition, bonrect, game);
                                    bonuses.Add(bonus);
                                    bon ++;
                                    break;
                                }
                            }

                            break;
                        }
                    }
                    x += 100;
                }
                j = 0;
                x = 0;
                y += 100;
            }
            recSprite = new Rectangle ( 0, 0, 80, 80 ) ;

            mine=new Me(game, this, ref txtMeleft, ref txtMeright, GetScreenRect(new Vector2(0, 100)), 
                recSprite, boxs, bonuses, enemies);
            game.Components.Add(mine);
        }
Esempio n. 2
0
        void createMaps()
        {
            boxs    = new List <Box>();
            bonuses = new List <bonusElements>();
            enemies = new List <EnemyCollection>();
            string[] lines = File.ReadAllLines(@"D:/Layer.txt");
            int      en = 0, bon = 0;

            levelLength = 100 * lines.Count();
            int x = 0;
            int y = 0;
            int i = lines.Count() - 1, j = 0;

            for (; i >= 0; i--)
            {
                for (; j < lines[i].Length; j++)
                {
                    char c = lines[i][j];
                    switch (c)
                    {
                    case '1':
                    {
                        Rectangle boxrect     = new Rectangle(0, 0, 100, 20);
                        Vector2   boxposition = GetScreenRect(new Vector2(x, y));
                        Box       box         = new Box(ref txtWall, boxposition, boxrect, game);
                        boxs.Add(box);
                        break;
                    }

                    case '2':
                    {
                        bon = (int)new Random().Next(0, 2);
                        switch (en)
                        {
                        case 0:
                        {
                            Rectangle enrect     = new Rectangle(0, 0, 100, 65);
                            Vector2   enposition = GetScreenRect(new Vector2(x, y));
                            txtEnemy = encollection[en];
                            EnemyCollection enemy = new EnemyCollection(ref txtEnemy, enposition, enrect, game);
                            enemies.Add(enemy);
                            en++;
                            break;
                        }

                        case 1:
                        {
                            Rectangle enrect     = new Rectangle(0, 0, 173, 95);
                            Vector2   enposition = GetScreenRect(new Vector2(x, y));
                            txtEnemy = encollection[en];
                            EnemyCollection enemy = new EnemyCollection(ref txtEnemy, enposition, enrect, game);
                            enemies.Add(enemy);
                            en++;
                            break;
                        }

                        case 2:
                        {
                            Rectangle enrect     = new Rectangle(0, 0, 120, 100);
                            Vector2   enposition = GetScreenRect(new Vector2(x, y));
                            txtEnemy = encollection[en];
                            EnemyCollection enemy = new EnemyCollection(ref txtEnemy, enposition, enrect, game);
                            enemies.Add(enemy);
                            en++;
                            break;
                        }

                        case 3:
                        {
                            Rectangle enrect     = new Rectangle(0, 0, 50, 100);
                            Vector2   enposition = GetScreenRect(new Vector2(x, y));
                            txtEnemy = encollection[en];
                            EnemyCollection enemy = new EnemyCollection(ref txtEnemy, enposition, enrect, game);
                            enemies.Add(enemy);
                            en++;
                            break;
                        }

                        case 4:
                        {
                            Rectangle enrect     = new Rectangle(0, 0, 80, 105);
                            Vector2   enposition = GetScreenRect(new Vector2(x, y));
                            txtEnemy = encollection[en];
                            EnemyCollection enemy = new EnemyCollection(ref txtEnemy, enposition, enrect, game);
                            enemies.Add(enemy);
                            en++;
                            break;
                        }

                        case 5:
                        {
                            Rectangle enrect     = new Rectangle(0, 0, 60, 100);
                            Vector2   enposition = GetScreenRect(new Vector2(x, y));
                            txtEnemy = encollection[en];
                            EnemyCollection enemy = new EnemyCollection(ref txtEnemy, enposition, enrect, game);
                            enemies.Add(enemy);
                            en = 0;
                            break;
                        }
                        }


                        break;
                    }

                    case '3':
                    {
                        bon = (int)new Random().Next(0, 2);
                        switch (bon)
                        {
                        case 2:
                        {
                            Rectangle bonrect     = new Rectangle(0, 0, 63, 110);                                    //max
                            Vector2   bonposition = GetScreenRect(new Vector2(x, y));
                            txtBonus = boncollection[0];
                            bonusElements bonus = new bonusElements(ref txtBonus, bonposition, bonrect, game);
                            bonuses.Add(bonus);
                            bon = 0;
                            break;
                        }

                        case 1:
                        {
                            Rectangle bonrect     = new Rectangle(0, 0, 21, 80);                                         //midle
                            Vector2   bonposition = GetScreenRect(new Vector2(x, y));
                            txtBonus = boncollection[bon];
                            bonusElements bonus = new bonusElements(ref txtBonus, bonposition, bonrect, game);
                            bonuses.Add(bonus);
                            bon++;
                            break;
                        }

                        case 0:
                        {
                            Rectangle bonrect     = new Rectangle(0, 0, 80, 60);                                        //min
                            Vector2   bonposition = GetScreenRect(new Vector2(x, y));
                            txtBonus = boncollection[2];
                            bonusElements bonus = new bonusElements(ref txtBonus, bonposition, bonrect, game);
                            bonuses.Add(bonus);
                            bon++;
                            break;
                        }
                        }

                        break;
                    }
                    }
                    x += 100;
                }
                j  = 0;
                x  = 0;
                y += 100;
            }
            recSprite = new Rectangle(0, 0, 80, 80);

            mine = new Me(game, this, ref txtMeleft, ref txtMeright, GetScreenRect(new Vector2(0, 100)),
                          recSprite, boxs, bonuses, enemies);
            game.Components.Add(mine);
        }