Exemple #1
0
        /*_____________Maldiciones_______________*/
        public void ObtenMaldicion()
        {
            bool maldito = true;

            for (int i = 0; i < mal.Length; i++)
            {
                if (mal[i] == null)
                {
                    maldito = false;
                }
            }
            if (maldito == false)
            {
                Maldicion temp = new Maldicion(CustomMath.RandomIntNumber(Maldicion.cantidadMaldiciones - 1));
                for (int i = 0; i < mal.Length; i++)
                {
                    if (mal[i] != null && temp.GetId() == mal[i].GetId())
                    {
                        temp = new Maldicion(CustomMath.RandomIntNumber(Maldicion.cantidadMaldiciones - 1));
                        i    = -1;
                    }
                }
                ConsoleBuffer.ObteBuffer().InsertText("Has obtenido la " + temp.GetName());
                for (int i = 0; i < mal.Length; i++)
                {
                    if (mal[i] == null)
                    {
                        mal[i] = temp;
                        i      = mal.Length;
                    }
                }
            }
            else
            {
                ConsoleBuffer.ObteBuffer().InsertText("Tienes tantas maldiciones que tu cuerpo no es capaz de aguantar más");
                int temp = ((400 * level / 100 + 20) / 10);
                ExcesoMaldito++;
                ConsoleBuffer.ObteBuffer().InsertText("Has perdido " + temp + " de vida maxima");
                if (hpM <= 0)
                {
                    ConsoleBuffer.ObteBuffer().InsertText("El peso de las maldiciones exprime tu ultima gota de tu alma");
                    ConsoleBuffer.ObteBuffer().InsertText("Caes muerto en el suelo");
                    ConsoleBuffer.ObteBuffer().InsertText("Pulsa cualquier boton para continuar");
                    Console.ReadKey();
                }
            }
        }
 public static string RandomDescr(string path)
 {
     string[] frases = ReadFile(path);
     return(frases[CustomMath.RandomIntNumber(frases.Length - 1)]);
 }
        public static void StartLevel(int cantidad)
        {
            actualRooms = new List <Room>();
            List <Vector2> actualVectors;

            if (Program.ObteJuego().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.ObteJuego().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);
            }

            /*Tesoro____________*/

            int          limit    = (Program.ObteJuego().level > 5)? 3 : (Program.ObteJuego().level + 1) / 2;
            RoomTreasure treasure = null;

            while (limit > 0)
            {
                num = CustomMath.RandomIntNumber(actualRooms.Count - 1, 1);//num se esta reutilizando de salida
                if (actualRooms[num].GetType() == typeof(Room))
                {
                    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);
                    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);
                actualRooms.Add(bless);
            }
            /*Miscelaneous*/

            if (existsClosedRoom)
            {
                bool control = true;
                do
                {
                    num = CustomMath.RandomIntNumber(actualRooms.Count - 1, 1);
                    if (actualRooms[num].GetType() == typeof(Room))
                    {
                        actualRooms[num].GetItem(new Item("Llave vieja"));
                        control = false;
                    }
                } while (control);
            }
        }
        public static List <Vector2> GenerateLevelVersion4(int cantidad)
        {
            List <Vector2> actualVectors = new List <Vector2>();
            List <Vector2> posibilidades = new List <Vector2>()
            {
                new Vector2(0, 0)
            };


            while (actualVectors.Count < cantidad)
            {
                //Paso 3.1
                Vector2 vv, vv1, vv2, vh1, vh2;

                //Paso 1 -- Añade sala aleatoria de lista de posibilidades
                int index = CustomMath.RandomIntNumber(posibilidades.Count - 1);
                actualVectors.Add(posibilidades[index]);

                //paso 3.2
                vv  = posibilidades[index];
                vv1 = new Vector2(vv.x, vv.y - 1);
                vv2 = new Vector2(vv.x, vv.y + 1);
                vh1 = new Vector2(vv.x - 1, vv.y);
                vh2 = new Vector2(vv.x + 1, vv.y);

                //Paso 2 -- Borra la sala añadida de la lista de posibilidades
                posibilidades.RemoveAt(index);

                //Paso 3 -- quita las no posibles de la lista
                for (int i = 0; i < posibilidades.Count; i++)
                {
                    if (posibilidades[i].Equals(vv1) || posibilidades[i].Equals(vv2) || posibilidades[i].Equals(vh1) || posibilidades[i].Equals(vh2))
                    {
                        posibilidades.RemoveAt(i);
                    }
                }

                bool up = true, down = true, left = true, right = true;
                for (int i = 0; i < actualVectors.Count; i++)
                {
                    if (up)
                    {
                        if (actualVectors[i].Equals(vv2))
                        {
                            up = false;
                        }
                    }

                    if (down)
                    {
                        if (actualVectors[i].Equals(vv1))
                        {
                            down = false;
                        }
                    }

                    if (right)
                    {
                        if (actualVectors[i].Equals(vh2))
                        {
                            right = false;
                        }
                    }

                    if (left)
                    {
                        if (actualVectors[i].Equals(vh1))
                        {
                            left = false;
                        }
                    }
                }


                if (up)
                {
                    posibilidades.Add(vv2);
                }
                if (right)
                {
                    posibilidades.Add(vh2);
                }
                if (down)
                {
                    posibilidades.Add(vv1);
                }
                if (left)
                {
                    posibilidades.Add(vh1);
                }
            }

            return(actualVectors);
        }
Exemple #5
0
        public void InsertText(string newText)
        {
            if (juego.pl.GetMaldicion(0))
            {
                string   prohibido = "\"<>-|[]0987654321¿?!¡,.:'";
                string[] mald      = newText.Split(' ');
                newText = "";
                for (int i = 0; i < mald.Length; i++)
                {
                    if (mald[i].Length >= 3)
                    {
                        int numeroCoin = 0;
                        for (int j = 0; j < mald[i].Length; j++)
                        {
                            for (int k = 0; k < prohibido.Length; k++)
                            {
                                if (prohibido[k] == mald[i][j])
                                {
                                    numeroCoin++;
                                    k = prohibido.Length;
                                }
                            }
                        }
                        if (numeroCoin != mald[i].Length)
                        {
                            int  r1, r2;
                            bool check;
                            do
                            {
                                check = false;
                                r1    = CustomMath.RandomIntNumber(mald[i].Length - 1);
                                for (int j = 0; j < prohibido.Length; j++)
                                {
                                    if (mald[i][r1] == prohibido[j])
                                    {
                                        check = true;
                                    }
                                }
                            } while (check);
                            do
                            {
                                check = false;
                                r2    = CustomMath.RandomIntNumber(mald[i].Length - 1);
                                for (int j = 0; j < prohibido.Length; j++)
                                {
                                    if (mald[i][r2] == prohibido[j])
                                    {
                                        check = true;
                                    }
                                }
                            } while (check);

                            char temp = mald[i][r1];
                            if (r1 + 1 < mald[i].Length)
                            {
                                mald[i] = mald[i].Substring(0, r1) + mald[i][r2] + mald[i].Substring(r1 + 1);
                            }
                            else
                            {
                                mald[i] = mald[i].Substring(0, r1) + mald[i][r2];
                            }
                            if (r2 + 1 < mald[i].Length)
                            {
                                mald[i] = mald[i].Substring(0, r2) + temp + mald[i].Substring(r2 + 1);
                            }
                            else
                            {
                                mald[i] = mald[i].Substring(0, r2) + temp;
                            }
                        }
                    }
                    newText += mald[i];
                    if (i + 1 < mald.Length)
                    {
                        newText += " ";
                    }
                }
            }

            if (newText.Length > width - 22)
            {
                for (int i = textBox.Length - 1; i >= 1; i--)
                {
                    textBox[i] = textBox[i - 1];
                }

                int limit = newText.Length - 1;
                while (limit >= 0 && (limit > width - 22 || !newText[limit].Equals(' ')))
                {
                    limit--;
                }
                if (limit == -1 || limit == 0)
                {
                    textBox[0] = newText.Substring(limit + 1, width - 22);
                    InsertText(newText.Substring(width - 22));
                }
                else
                {
                    textBox[0] = newText.Substring(0, limit);
                    InsertText(newText.Substring(limit));
                }
            }
            else
            {
                for (int i = textBox.Length - 1; i >= 1; i--)
                {
                    textBox[i] = textBox[i - 1];
                }

                textBox[0] = newText;
            }
        }