예제 #1
0
        public static void StartLevel(int cantidad)
        {
            actualRooms = new List <Room>();
            List <Vector2> actualVectors;

            if (Program.level > 5)
            {
                double prob = CustomMath.RandomUnit();
                if (prob < 95d / 300d)
                {
                    actualVectors = GenerateLevelVersion2(cantidad);
                }
                else if (prob < 190d / 300d)
                {
                    actualVectors = GenerateLevel(cantidad);
                }
                else if (prob < 285d / 300d)
                {
                    actualVectors = GenerateLevelVersion3(cantidad);
                }
                else
                {
                    actualVectors = GenerateLevelVersion4(cantidad);
                }
            }
            else
            {
                actualVectors = GenerateLevel(cantidad);
            }
            for (int i = 0; i < actualVectors.Count; i++)
            {
                actualRooms.Add(new Room(actualVectors[i].x, actualVectors[i].y));
            }
            //First Room is visible
            actualRooms[0].SetVisible(2);

            //SET DOORS
            for (int i = 0; i < actualRooms.Count; i++)
            {
                if (!(actualRooms[i].GetNorthRoom() != null && actualRooms[i].GetWestRoom() != null && actualRooms[i].GetSouthRoom() != null && actualRooms[i].GetEastRoom() != null))
                {
                    for (int j = i + 1; j < actualRooms.Count; j++)
                    {
                        if (actualRooms[i].GetNorthRoom() == null)
                        {
                            if (actualRooms[i].GetPosX() == actualRooms[j].GetPosX() && actualRooms[i].GetPosY() + 1 == actualRooms[j].GetPosY())
                            {
                                actualRooms[i].SetNorth(actualRooms[j]);
                                actualRooms[j].SetSouth(actualRooms[i]);
                            }
                        }
                        if (actualRooms[i].GetWestRoom() == null)
                        {
                            if (actualRooms[i].GetPosX() - 1 == actualRooms[j].GetPosX() && actualRooms[i].GetPosY() == actualRooms[j].GetPosY())
                            {
                                actualRooms[i].SetWest(actualRooms[j]);
                                actualRooms[j].SetEast(actualRooms[i]);
                            }
                        }
                        if (actualRooms[i].GetSouthRoom() == null)
                        {
                            if (actualRooms[i].GetPosX() == actualRooms[j].GetPosX() && actualRooms[i].GetPosY() - 1 == actualRooms[j].GetPosY())
                            {
                                actualRooms[i].SetSouth(actualRooms[j]);
                                actualRooms[j].SetNorth(actualRooms[i]);
                            }
                        }
                        if (actualRooms[i].GetEastRoom() == null)
                        {
                            if (actualRooms[i].GetPosX() + 1 == actualRooms[j].GetPosX() && actualRooms[i].GetPosY() == actualRooms[j].GetPosY())
                            {
                                actualRooms[i].SetEast(actualRooms[j]);
                                actualRooms[j].SetWest(actualRooms[i]);
                            }
                        }
                        if (actualRooms[i].GetNorthRoom() != null && actualRooms[i].GetWestRoom() != null && actualRooms[i].GetSouthRoom() != null && actualRooms[i].GetEastRoom() != null)
                        {
                            j = actualRooms.Count;
                        }
                    }
                }
            }

            /*--------------------------------------Crear salas especiales------------------------------------------*/
            List <Room> exitRooms = new List <Room>();
            /*se usa para la cantidad de puertas que debe tener una sala*/
            int temp = 3;

            do
            {
                for (int i = 1; i < actualRooms.Count; i++)
                {
                    int noDoors = 0;
                    if (actualRooms[i].GetEastRoom() == null)
                    {
                        noDoors++;
                    }

                    if (actualRooms[i].GetWestRoom() == null)
                    {
                        noDoors++;
                    }

                    if (actualRooms[i].GetNorthRoom() == null)
                    {
                        noDoors++;
                    }

                    if (actualRooms[i].GetSouthRoom() == null)
                    {
                        noDoors++;
                    }
                    if (noDoors == temp)
                    {
                        /*solo habitaciones con 3 salidas*/
                        exitRooms.Add(actualRooms[i]);
                    }
                }
                if (exitRooms.Count == 0)
                {
                    temp--;
                }
            } while (exitRooms.Count == 0);

            /*Salida_____________*/
            int  num  = CustomMath.RandomIntNumber(exitRooms.Count - 1);
            Room exit = exitRooms[num];

            exitRooms.RemoveAt(num);//Elimina la sala de las posibilidades de salida
            RoomExit texit = new RoomExit(exit.GetPosX(), exit.GetPosY());

            texit.SetEast(exit.GetEastRoom());
            texit.SetWest(exit.GetWestRoom());
            texit.SetNorth(exit.GetNorthRoom());
            texit.SetSouth(exit.GetSouthRoom());
            if (texit.GetNorthRoom() != null)
            {
                texit.GetNorthRoom().SetSouth(texit);
            }
            if (texit.GetSouthRoom() != null)
            {
                texit.GetSouthRoom().SetNorth(texit);
            }
            if (texit.GetWestRoom() != null)
            {
                texit.GetWestRoom().SetEast(texit);
            }
            if (texit.GetEastRoom() != null)
            {
                texit.GetEastRoom().SetWest(texit);
            }
            actualRooms.Remove(exit);
            actualRooms.Add(texit);

            /*Habitacion cerrada__________*/
            bool existsClosedRoom = false;

            if (temp == 3 && CustomMath.RandomUnit() < (Program.level - 1) / 3f && exitRooms.Count > 0)
            {
                existsClosedRoom = true;
                num = CustomMath.RandomIntNumber(exitRooms.Count - 1); //num se esta reutilizando de salida
                Room tempRoom = exitRooms[num];
                exitRooms.RemoveAt(num);                               //Elimina la sala cerrada de las posibilidades
                Room newRoom;
                newRoom = new RoomClosed(tempRoom.GetPosX(), tempRoom.GetPosY());
                newRoom.SetEast(tempRoom.GetEastRoom());
                newRoom.SetWest(tempRoom.GetWestRoom());
                newRoom.SetNorth(tempRoom.GetNorthRoom());
                newRoom.SetSouth(tempRoom.GetSouthRoom());
                if (newRoom.GetNorthRoom() != null)
                {
                    newRoom.GetNorthRoom().SetSouth(newRoom);
                }
                if (newRoom.GetSouthRoom() != null)
                {
                    newRoom.GetSouthRoom().SetNorth(newRoom);
                }
                if (newRoom.GetWestRoom() != null)
                {
                    newRoom.GetWestRoom().SetEast(newRoom);
                }
                if (newRoom.GetEastRoom() != null)
                {
                    newRoom.GetEastRoom().SetWest(newRoom);
                }
                actualRooms.Remove(tempRoom);
                actualRooms.Add(newRoom);
            }

            List <Room> normalRooms = new List <Room>();

            foreach (Room n in actualRooms)
            {
                if (n.GetType() == typeof(Room))
                {
                    normalRooms.Add(n);
                }
            }
            /*Tesoro____________*/

            int      limit = (Program.level > 5) ? 3 : (Program.level + 1) / 2;
            RoomGema gema  = null;

            while (limit > 0 && normalRooms.Count > 0)
            {
                num = CustomMath.RandomIntNumber(actualRooms.Count - 1, 1);//num se esta reutilizando de salida
                if (normalRooms.Contains(actualRooms[num]))
                {
                    Room r = actualRooms[num];
                    gema = new RoomGema(r.GetPosX(), r.GetPosY());
                    gema.SetEast(r.GetEastRoom());
                    gema.SetWest(r.GetWestRoom());
                    gema.SetNorth(r.GetNorthRoom());
                    gema.SetSouth(r.GetSouthRoom());
                    if (gema.GetNorthRoom() != null)
                    {
                        gema.GetNorthRoom().SetSouth(gema);
                    }
                    if (gema.GetSouthRoom() != null)
                    {
                        gema.GetSouthRoom().SetNorth(gema);
                    }
                    if (gema.GetWestRoom() != null)
                    {
                        gema.GetWestRoom().SetEast(gema);
                    }
                    if (gema.GetEastRoom() != null)
                    {
                        gema.GetEastRoom().SetWest(gema);
                    }
                    actualRooms.Remove(r);
                    normalRooms.Remove(r);//Eliminalo de las posibles posiciones
                    actualRooms.Add(gema);
                    limit--;
                }
            }

            limit = (Program.level > 9) ? 3 : (Program.level) / 3;
            RoomTreasure treasure = null;

            while (limit > 0 && normalRooms.Count > 0)
            {
                num = CustomMath.RandomIntNumber(actualRooms.Count - 1, 1);//num se esta reutilizando de salida
                if (normalRooms.Contains(actualRooms[num]))
                {
                    Room r = actualRooms[num];
                    treasure = new RoomTreasure(r.GetPosX(), r.GetPosY());
                    treasure.SetEast(r.GetEastRoom());
                    treasure.SetWest(r.GetWestRoom());
                    treasure.SetNorth(r.GetNorthRoom());
                    treasure.SetSouth(r.GetSouthRoom());
                    if (treasure.GetNorthRoom() != null)
                    {
                        treasure.GetNorthRoom().SetSouth(treasure);
                    }
                    if (treasure.GetSouthRoom() != null)
                    {
                        treasure.GetSouthRoom().SetNorth(treasure);
                    }
                    if (treasure.GetWestRoom() != null)
                    {
                        treasure.GetWestRoom().SetEast(treasure);
                    }
                    if (treasure.GetEastRoom() != null)
                    {
                        treasure.GetEastRoom().SetWest(treasure);
                    }
                    actualRooms.Remove(r);
                    normalRooms.Remove(r);//Eliminalo de las posibles posiciones
                    actualRooms.Add(treasure);
                    limit--;
                }
            }

            if (CustomMath.RandomUnit() < 0.5)
            {
                RoomBless bless;
                Room      r;
                do
                {
                    r = actualRooms[CustomMath.RandomIntNumber(actualRooms.Count - 1, 1)];
                } while (r.GetType() != typeof(Room));

                bless = new RoomBless(r.GetPosX(), r.GetPosY());
                bless.SetEast(r.GetEastRoom());
                bless.SetWest(r.GetWestRoom());
                bless.SetNorth(r.GetNorthRoom());
                bless.SetSouth(r.GetSouthRoom());
                if (bless.GetNorthRoom() != null)
                {
                    bless.GetNorthRoom().SetSouth(bless);
                }
                if (bless.GetSouthRoom() != null)
                {
                    bless.GetSouthRoom().SetNorth(bless);
                }
                if (bless.GetWestRoom() != null)
                {
                    bless.GetWestRoom().SetEast(bless);
                }
                if (bless.GetEastRoom() != null)
                {
                    bless.GetEastRoom().SetWest(bless);
                }
                actualRooms.Remove(r);
                normalRooms.Remove(r);
                actualRooms.Add(bless);
            }

            /*Miscelaneous*/
            if (existsClosedRoom)
            {
                bool control = true;
                do
                {
                    num = CustomMath.RandomIntNumber(normalRooms.Count - 1, 1);
                    if (actualRooms[num].GetType() != typeof(RoomClosed))
                    {
                        control = !actualRooms[num].GetItem(new Item("Llave vieja"));
                    }
                } while (control);
            }

            int maxEnemies = (int)(Program.level + 0.16 * Program.level * Program.level);

            for (int i = 0; i < maxEnemies; i++)
            {
                int x = CustomMath.RandomIntNumber(normalRooms.Count - 1, 1);
                normalRooms[x].ene = new Enemigo(Enemigo.eneList[CustomMath.RandomIntNumber(Enemigo.eneList.Length - 1)], Program.level);
                normalRooms.RemoveAt(x);
            }
        }