namespace Strategy
{
interface IWeaponbehavior
{
void UseWeapon();
}
}
namespace Strategy
{
class Knife : IWeaponbehavior
{
public void UseWeapon()
{
Console.WriteLine("You used the knife to slash the enemy! SLASH SLASH!");
}
}
}
namespace Strategy
{
class Pan : IWeaponbehavior
{
public void UseWeapon()
{
Console.WriteLine("You use the pan! 100% Adamantium power! BONG!");
}
}
}
Now if I have a Character.cs superclass. how can that superclass implement a weaponbehavior so that children classes can be more specific.
namespace Strategy
{
class Character
{
public IWeaponbehavior weapon;
public Character(IWeaponbehavior specificWeapon)
{
weapon = specificWeapon;
}
}
}
namespace Strategy
{
class Thief : Character
{
}
}
How can I implement this? I'm very confused on what the actual code needs to be.
I know this might be asking too much, but if you could write the actual code so I could study it, that would be very nice of you guys. I learn by seeing code.

New Topic/Question
Reply



MultiQuote




|