views:

114

answers:

2

Im trying to make something like an Rpg game atm but im really stuck on something i really dont know what to do anymore i really need help it might look like a noob question but please try to answer me >.< this is the parent class

namespace ConsoleApplication1
{
    class Personaje
    {
        public Rango Damage;
        public int Defensa;

        public int HP;

        public int MP;
        public bool Evade;
        public bool Counter;
        public string Nombre;
        public Personaje() { }
        public Personaje(Rango Damage, int Defensa, int HP, bool Evade, bool Counter, string Nombre)
        {
            this.Damage = Damage;
            this.Defensa = Defensa;
            this.HP = HP;
            this.Evade = Evade;
            this.Counter = Counter;
            this.Nombre = Nombre;
        }
    }
}

this is one of the childs

namespace ConsoleApplication1
{
    class Enemigo:Personaje
    {

    }
}

this is one of the childs and the one im having trouble with i dont know how to put the status on it

namespace ConsoleApplication1
{
    class Poring:Enemigo
    {
        int HP = 30;
        int MP = 10;
        int Def = 0;
        public bool Evade()
        {
            return false;
        }
        public bool Counter()
        {
            return false;
        }
        public Rango Damage()
        {
            Rango r = new Rango();
            r.min = 10;
            r.max = 15;
            return r;
        }
        string Nombre = "Poring";

        //Personaje Propiedades = new Personaje(Damage,Def, HP, Evade, Counter, Nombre);
        Personaje omg = new Personaje();


    }
}
+1  A: 

In your base class, you have declared Evade and Counter as public fields. To override them, you need to make these properties or methods (methods in this case), and mark them virtual or abstract in the base class, and override in the derived class. If you want them to be abstract (i.e. the base class has no "default" implementation, and derived classes must override them to provide an implementation), you must make the base class abstract too:

public abstract class Personaje
{
  public abstract bool Evade();
}

public class Poring : Enemigo
{
  public override bool Evade()
  {
    return false;
  }
}
itowlson
+2  A: 

If I understand your question correctly, I think you are wanting to be able to call the constructor on the parent to pass in the state of the object. You have to overload the constructor at each level of the class heirarchy.

class Enemigo : Personaje
{
    public Enemigo(Rango Damage, int Defensa, int HP, bool Evade, bool Counter, string Nombre)
       : base(Damage, Defensa, HP, Evade, Counter, Nombre)
    {
    }
}

class Poring:Enemigo
{
       public Poring(Rango Damage, int Defensa, int HP, bool Evade, bool Counter, string Nombre)
          : base(Damage, Defensa, HP, Evade, Counter, Nombre)
          {
          }
}
lfoust
Thank you very much ,yeah im sorry if i wasnt precise but yeah i meant the starting values for each character,thank you very much that was really fast btw xD
Makenshi