コード例 #1
0
ファイル: CompareSample.cs プロジェクト: hellomyzn/hogehogeC-
    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
ファイル: AgeComparator.cs プロジェクト: hellomyzn/hogehogeC-
 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
ファイル: CompareSample.cs プロジェクト: hellomyzn/hogehogeC-
 public int Compare(StrategyHuman h1, StrategyHuman h2)
 {
     return(comparator.compare(h1, h2));
 }