Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Game model
public interface IWeapon
{
void Hit(string target);
}
public class Sword : IWeapon
{
public void Hit(string target)
{
Console.WriteLine("Chopped {0}", target);
}
}
public class ShortSword : IWeapon
{
public void Hit(string target)
{
Console.WriteLine("Cut {0}", target);
}
}
public class Knife : IWeapon
{
public void Hit(string target)
{
Console.WriteLine("Pierced {0}", target);
}
}
public interface ICharacter
{
void Attack(string target);
}
public class Warrior : ICharacter
{
public IWeapon Weapon { get; protected set; }
public Warrior(IWeapon weapon)
{
Weapon = weapon;
}
public void Attack(string target)
{
Weapon.Hit(target);
}
}
public class Thief : ICharacter
{
public IWeapon LeftWeapon { get; protected set; }
public IWeapon RightWeapon { get; protected set; }
public Thief(IWeapon leftWeapon, IWeapon rightWeapon)
{
LeftWeapon = leftWeapon;
RightWeapon = rightWeapon;
}
public void Attack(string target)
{
LeftWeapon.Hit(target);
RightWeapon.Hit(target);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment