Esempio n. 1
0
    public IEstadoGallina Update(Gallina g)
    {
        Collider closestEnemy = null;

        //Recorre los objetivos en su vision y se queda con el mas cercano
        foreach (Collider col in g.visionList)
        {
            if (col != null)
            {
                if (closestEnemy == null)
                {
                    closestEnemy = col;
                }
                else
                {
                    if (Vector3.Distance(col.transform.position, g.transform.position) < Vector3.Distance(closestEnemy.transform.position, g.transform.position))
                    {
                        closestEnemy = col;
                    }
                }
            }
        }

        //Si ha encontrado un enemigo lo ataca
        if (closestEnemy != null)
        {
            g.ePerseguir.target = closestEnemy.transform;
            return(g.ePerseguir);
        }
        else
        {
            return(g.eRandom);
        }
    }
Esempio n. 2
0
    //Atacar solo si ha pasado 1s desde el anterior ataque
    public IEstadoHormiga Update(Hormiga h)
    {
        //Si el objetivo esta muerto vamos al estado de muerte, ya que la hormiga ya ha comenzado su ataque suicida aunque no haga daño a ningun enemigo
        if (target == null)
        {
            return(h.eMuerta);
        }

        //Comprobamos que tipo de enemigo es para hacerle daño correctamente
        if (target.gameObject.CompareTag("Gallina"))
        {
            Gallina g = target.gameObject.GetComponent <Gallina>();
            g.GetHit(h.fuerza);
        }

        if (target.gameObject.CompareTag("Pulpo"))
        {
            Octopus o = target.gameObject.GetComponent <Octopus>();
            o.GetHit(h.fuerza);
        }

        if (target.gameObject.CompareTag("TRex"))
        {
            TRex t = target.gameObject.GetComponent <TRex>();
            t.GetHit(h.fuerza);
        }

        return(h.eMuerta);
    }
Esempio n. 3
0
        public void Menu()
        {
            Animal especie = new Animal("", 0, ' ');
            char   opc     = 'S';

            do
            {
                Console.WriteLine("                     BIENVENIDO                              ");
                Console.WriteLine("         1)Humano");
                Console.WriteLine("         2)Gallina");
                Console.Write("Escoja La especie de la cual desea saber mas informacion:  ");
                opc = Convert.ToChar(Console.ReadLine());
                switch (opc)
                {
                case '1':
                    especie = new Humano("Jose", 22, 'M');
                    break;

                case '2':
                    especie = new Gallina("Pepe", 1, 'F');
                    break;
                }
                MostrarSubMenu(ref opc, ref especie);
                Console.Write("Desea continuar? :   ");
                opc = Convert.ToChar(Console.ReadLine());
            } while (opc == 'S' || opc == 's');
        }
    //Atacar solo si ha pasado 1s desde el anterior ataque
    public IEstadoGallina Update(Gallina g)
    {
        if (Time.time - time > 1)
        {
            time = Time.time;

            //Si el objetivo esta muerto volvemos a buscar
            if (target == null)
            {
                return(g.eBuscar);
            }

            //Comprobamos que tipo de enemigo es para hacerle daño correctamente
            if (target.gameObject.CompareTag("Hormiga"))
            {
                Hormiga h = target.gameObject.GetComponent <Hormiga>();
                if (h == null)
                {
                    HormigaReina hr = target.gameObject.GetComponent <HormigaReina>();
                    hr.GetHit(g.berserk ? g.fuerza * 3 : g.fuerza);
                }
                else
                {
                    h.GetHit();
                }
            }

            if (target.gameObject.CompareTag("Pulpo"))
            {
                Octopus o = target.gameObject.GetComponent <Octopus>();
                o.GetHit(g.berserk ? g.fuerza * 3 : g.fuerza);
            }

            if (target.gameObject.CompareTag("TRex"))
            {
                TRex t = target.gameObject.GetComponent <TRex>();
                t.GetHit(g.berserk ? g.fuerza * 3 : g.fuerza);
            }

            //Cada ataque reduce un poco la fuerza de la gallina
            if (g.fuerza > 10)
            {
                g.fuerza -= 1;
            }

            //Si el ataque acabo con su objetivo, la gallina se lo come para restaurar sus estadisticas
            if (target == null)
            {
                g.vida      = g.vidaInicial;
                g.fuerza    = g.fuerzaInicial;
                g.velocidad = g.velocidadInicial;
                g.berserk   = false;
            }
        }

        return(g.eAtacar);
    }
    public IEstadoGallina Update(Gallina g)
    {
        //Si ha muerto el objetivo, volver a buscar
        if (target == null)
        {
            return(g.eBuscar);
        }

        //Mientras no estamos cerca mantener el objetivo
        if (!colision)
        {
            g.nma.destination = target.position;
            return(g.ePerseguir);
        }
        else
        {
            //Si se alcanza al objetivo se mira si se pueden agrupar 3 o mas gallinas. Si se puede se ataca, si no, se huye
            colision = false;

            int numGrupo = 0;
            int gLibres  = 0;

            foreach (Gallina og in Settings.gallinas)
            {
                if (og.ePerseguir.target == target)
                {
                    numGrupo++;
                }

                if (og.ePerseguir.target == null)
                {
                    gLibres++;
                }
            }

            if (numGrupo + gLibres > 2)
            {
                foreach (Gallina og in Settings.gallinas)
                {
                    if (og.ePerseguir.target == null)
                    {
                        og.ePerseguir.target = target;
                        og.estado            = og.ePerseguir;
                    }
                }
                g.eAtacar.target = target;
                target           = null;
                return(g.eAtacar);
            }
            else
            {
                g.eHuir.target = target;
                target         = null;
                return(g.eHuir);
            }
        }
    }
    public IEstadoGallina Update(Gallina g)
    {
        //Si ha muerto el objetivo, volver a buscar
        if (target == null)
        {
            return(g.eBuscar);
        }

        float distance = Vector3.Distance(g.transform.position, target.position);

        //Si nos alejamos lo suficiente dejamos de huir
        if (distance > 10)
        {
            target = null;
            return(g.eBuscar);
        }

        //Se reducen las estadisticas durante la huida
        if (g.fuerza > 10 && Time.time - time > 1f)
        {
            g.fuerza -= 1;
        }

        if (g.velocidad > 1f && Time.time - time > 1f)
        {
            g.velocidad -= 0.5f;
            g.nma.speed  = g.velocidad;
            time         = Time.time;
        }

        //Mientras no estamos cerca mantener el objetivo
        if (!colision)
        {
            Vector3 dir = (g.transform.position - target.position).normalized;

            g.nma.destination = g.transform.position + (dir * 2);
            return(g.eHuir);
        }
        else
        {
            //Si te alcanza el objetivo se le ataca
            colision = false;

            g.eAtacar.target = target;
            target           = null;
            return(g.eAtacar);
        }
    }
Esempio n. 7
0
        public static clsAbsAnimal validarTipoAnimal(String nombre)
        {
            clsAbsAnimal animal = null;

            if (nombre.Equals("caballo"))
            {
                animal = new Caballo();
            }
            else if (nombre.Equals("gallina"))
            {
                animal = new Gallina();
            }
            else if (nombre.Equals("vaca"))
            {
                animal = new Vaca();
            }

            return(animal);
        }
Esempio n. 8
0
    public IEstadoGallina Update(Gallina g)
    {
        //Espera hasta que pasan 2 segundos. Despues realiza un movimiento aleatorio
        if (isWaiting)
        {
            if (Time.time - time > 2)
            {
                isWaiting = false;
            }
        }
        else
        {
            g.nma.destination = g.transform.position + new Vector3((Random.value - 0.5f) * 4, (Random.value - 0.5f) * 4, (Random.value - 0.5f) * 4);

            time      = Time.time;
            isWaiting = true;
        }

        return(g.eBuscar);
    }
Esempio n. 9
0
    public IStatesTRex Update(TRex t)
    {
        //Si el enemigo desaparece, el TRex vaga.
        if (t.enemy == null)
        {
            return(t.wanderState);
        }

        t.agent.speed = attackSpeed;
        force         = Settings.tamTrex * 20;

        //Si no hay colisión, sigue persiguiendo.
        if (!colision)
        {
            t.agent.isStopped = false;
            if (t.enemy == null)
            {
                return(t.wanderState);
            }
            else
            {
                t.agent.destination = t.enemy.transform.position;
                return(t.attackState);
            }

            //Si hay colisión, ataca.
        }
        else
        {
            colision = false;

            if (Time.time - time > 1f)
            {
                time = Time.time;

                //Se para.
                t.agent.isStopped = true;

                //Si es un pulpo, ataca hasta morir o matar, si lo mata puede comer.
                if (t.enemy.gameObject.CompareTag("Pulpo"))
                {
                    Octopus rival = t.enemy.GetComponent <Octopus>();
                    rival.GetHit((int)force);
                    if (t.enemy == null)
                    {
                        t.health += 20;
                    }

                    //Si es una hormiga, ataca hasta matar o morir.
                }
                else if (t.enemy.gameObject.CompareTag("Hormiga"))
                {
                    Hormiga rival = t.enemy.GetComponent <Hormiga>();
                    if (rival == null)
                    {
                        HormigaReina rivalHR = t.enemy.GetComponent <HormigaReina>();
                        rivalHR.GetHit((int)force);
                    }
                    else
                    {
                        rival.GetHit();
                    }

                    //Si es una gallina, ataca hasta morir o matar, si lo mata puede comer.
                }
                else if (t.enemy.gameObject.CompareTag("Gallina"))
                {
                    Gallina rival = t.enemy.GetComponent <Gallina>();
                    rival.GetHit((int)force);
                    if (t.enemy == null)
                    {
                        t.health += 20;
                    }
                }
            }
        }

        return(t.attackState);
    }
Esempio n. 10
0
        static void Main(string[] args)
        {
            Utilidades.EnviarCorreo();

            Perro p = new Perro();

            p.Nombre      = "Perro";
            p.Patas       = 4;
            p.EsDomestico = true;
            if (p.EsDomestico == true)
            {
                Console.WriteLine("Es un animal domestico");
            }
            else
            {
                Console.WriteLine("No es un animal domestico");
            }
            p.Comer();
            p.Caminar();
            p.Ladrar();
            p.Tamano();
            Console.WriteLine(p.Nombre);
            Console.WriteLine(p.Patas);
            Console.WriteLine("--------------------------------------");

            Gallina a = new Gallina();

            a.Nombre      = "Gallina";
            a.Alas        = 2;
            a.EsDomestico = true;
            if (a.EsDomestico == true)
            {
                Console.WriteLine("Es un animal domestico");
            }
            else
            {
                Console.WriteLine("No es un animal domestico");
            }
            a.Comer();
            a.Volar();
            a.Kikikear();
            a.Tamano();
            Console.WriteLine(a.Nombre);
            Console.WriteLine(a.Alas);
            Console.WriteLine("--------------------------------------");

            Gato g = new Gato();

            g.Nombre = "Gato";
            g.Patas  = 4;
            g.Pelaje = "Peludo";
            g.Comer();
            g.Caminar();
            g.Maullar();
            Console.WriteLine("Es un animal domestico");
            Console.WriteLine(g.Nombre);
            Console.WriteLine(g.Patas);
            Console.WriteLine("--------------------------------------");

            Rana r = new Rana();

            r.Nombre      = "Rana";
            r.Patas       = 4;
            r.EsDomestico = false;
            if (r.EsDomestico == true)
            {
                Console.WriteLine("Es un animal domestico");
            }
            else
            {
                Console.WriteLine("No es un animal domestico");
            }
            r.Comer();
            r.Atrapar();
            r.Croac();
            r.Tamano();
            Console.WriteLine(r.Nombre);
            Console.WriteLine(r.Patas);
            Console.WriteLine("--------------------------------------");

            Zancudo z = new Zancudo();

            z.Nombre      = "Aedes Aegipty";
            z.Alas        = 2;
            z.EsDomestico = false;
            if (z.EsDomestico == true)
            {
                Console.WriteLine("Es un animal domestico");
            }
            else
            {
                Console.WriteLine("No es un animal domestico");
            }
            z.Inquieto();
            z.Alimento();
            z.Zumbido();
            z.Tamano();
            Console.WriteLine(z.Nombre);
            Console.WriteLine(z.Alas);
            Console.WriteLine("--------------------------------------");

            PezPayaso pp = new PezPayaso();

            pp.Nombre      = "Pez Payaso";
            pp.Aletas      = 2;
            pp.EsDomestico = false;
            if (pp.EsDomestico == true)
            {
                Console.WriteLine("Es un animal domestico");
            }
            else
            {
                Console.WriteLine("No es un animal domestico");
            }
            pp.Banar();
            pp.Agallas();
            pp.Burbujas();
            pp.Tamano();
            Console.WriteLine(pp.Nombre);
            Console.WriteLine(pp.Aletas);
            Console.WriteLine("--------------------------------------");

            Cocodrilo c = new Cocodrilo();

            c.Nombre      = "Cocodrilo de pantano";
            c.Patas       = 4;
            c.EsDomestico = false;
            if (r.EsDomestico == true)
            {
                Console.WriteLine("Es un animal domestico");
            }
            else
            {
                Console.WriteLine("No es un animal domestico");
            }
            c.Comer();
            c.Defensa();
            c.Gruñir();
            c.Tamano();
            Console.WriteLine(c.Nombre);
            Console.WriteLine(c.Patas);
            Console.WriteLine("--------------------------------------");
        }
Esempio n. 11
0
    private void cargarGallinas()
    {
        Gallina gallina1 = new Gallina("Ponedora", "Negro y cafe", "Corto", "Margarita", 2);

        ListaGallina.Add(gallina1);
    }
Esempio n. 12
0
    public IStatesOctopus Update(Octopus o)
    {
        //Si no hay enemigo, vaga.
        if (o.enemy == null)
        {
            return(o.wanderState);
        }

        //Si está en el agua, es más rápido y más fuerte.
        if (o.water)
        {
            force         = Settings.tamPulpos * 15f;
            o.agent.speed = speed * 2;
        }
        else
        {
            //Si su vida es baja, huye.
            if (o.health < Settings.tamPulpos * 15)
            {
                return(o.runState);
            }

            force         = Settings.tamPulpos * 5f;
            o.agent.speed = speed;
        }

        //Si no hay colisión, sigue persiguiendo.
        if (!colision)
        {
            o.agent.isStopped = false;
            if (o.enemy == null)
            {
                return(o.wanderState);
            }
            else
            {
                o.agent.destination = o.enemy.transform.position;
                return(o.attackState);
            }

            //Si la hay, ataca.
        }
        else
        {
            colision = false;
            if (Time.time - time > 1f)
            {
                time = Time.time;

                //Se para.
                o.agent.isStopped = true;

                //Llama a las funciones de recibir daño del rival.
                if (o.enemy.gameObject.CompareTag("TRex"))
                {
                    TRex rival = o.enemy.GetComponent <TRex>();
                    rival.GetHit((int)force);
                }
                else if (o.enemy.gameObject.CompareTag("Hormiga"))
                {
                    Hormiga rival = o.enemy.GetComponent <Hormiga>();
                    if (rival == null)
                    {
                        HormigaReina rivalHR = o.enemy.GetComponent <HormigaReina>();
                        rivalHR.GetHit((int)force);
                    }
                    else
                    {
                        rival.GetHit();
                    }
                }
                else if (o.enemy.gameObject.CompareTag("Gallina"))
                {
                    Gallina rival = o.enemy.GetComponent <Gallina>();
                    rival.GetHit((int)force);
                }
            }
        }

        return(o.attackState);
    }