samedi 21 août 2021

C# Change class type of child object

My code is written like this.

public class Client {
    public Character Chr { get; set; }

    public CreateCharacter() {
        Chr = new Warrior();
    }
    ...
}

public class Character {
    public void ChangeJobToMagician() {
        // this = new Magician(); ?
    }
    ...
}

public class Warrior : Character {
    ...
}

public class Magician : Character {
    ...
}

public class Inventory {
    public Character Owner { get; set; }
    public List<Item> Items = new List<Item>();
    ...
}

public class Item {
    public Character Owner { get; set; }
    ...
}

If i reference Character class in Client class only, it'll be easy but, many things reference Character (like Inventory, Item, many classes) so i can't change everything of that.

there is easy way to make change job(child object's class type)?





Aucun commentaire:

Enregistrer un commentaire