-
-
Save stanb/f52aa46390b9c3b6c682 to your computer and use it in GitHub Desktop.
Game model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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