public class Battle<T1,T2> where T1:Character where T2 : Character {
T1 _c1;
T2 _c2;
public Battle(T1 c1, T2 c2){
_c1 = c1;
_c2 = c2;
}
public void Do() {
_c1.Attack(_c2); //템플릿 함수지만 Character를 상속한 애들만 받을 수 있기 때문에 호출가능.
_c2.Attack(_c1);
}
}
public class Character{
public virtual void Attack(Character target){}
}
public class Hero: Character {
}
public class Enemy : Character {
}
public static class Program{
static void Main(){
var h= new Hero();
var e = new Enemy();
var b = new Battle<Hero,Enemy>(h,e);
b.Do();
}
}
Last active
March 19, 2019 09:27
-
-
Save geniikw/31ad2270e27e148e4133f18c88582850 to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment