示例#1
0
    void Start()
    {
        StrategyHuman h1 = new StrategyHuman("Yamada", 170, 60, 20);
        StrategyHuman h2 = new StrategyHuman("Sato", 175, 55, 20);

        comparator = new AgeComparator();
        resultAge  = Compare(h1, h2);

        comparator   = new HeightComparator();
        resultHeight = Compare(h1, h2);

        print("age :" + resultAge);
        print("height :" + resultHeight);
    }
示例#2
0
 public int compare(StrategyHuman h1, StrategyHuman h2)
 {
     if (h1.age > h2.age)
     {
         return(1);
     }
     else if (h1.age == h2.age)
     {
         return(0);
     }
     else
     {
         return(-1);
     }
 }
示例#3
0
 public int compare(StrategyHuman h1, StrategyHuman h2)
 {
     if (h1.height > h2.height)
     {
         return(1);
     }
     else if (h1.height == h2.height)
     {
         return(0);
     }
     else
     {
         return(-1);
     }
 }
示例#4
0
 public int Compare(StrategyHuman h1, StrategyHuman h2)
 {
     return(comparator.compare(h1, h2));
 }