Skip to content

Instantly share code, notes, and snippets.

@stanb
Created December 1, 2012 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stanb/f52aa46390b9c3b6c682 to your computer and use it in GitHub Desktop.
Save stanb/f52aa46390b9c3b6c682 to your computer and use it in GitHub Desktop.
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