Changeset 37540 for lang/csharp

Show
Ignore:
Timestamp:
05/15/10 13:37:55 (4 years ago)
Author:
isaisstillalive
Message:
  • PotionをCardInfoクラスから削除
  • 現在、比較と出力と部分がテスト未通過
Location:
lang/csharp/DominionEngine
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • lang/csharp/DominionEngine/DominionEngine.CardInfo.Test/Base/WorkshopTest.cs

    r37504 r37540  
    5353            Assert.That(choosingArgs.Filter(new MutableCostCard(Worth.Coin(4))), Is.True); 
    5454            Assert.That(choosingArgs.Filter(new MutableCostCard(Worth.Coin(5))), Is.False); 
    55             Assert.That(choosingArgs.Filter(new MutableCostCard(Worth.Potion(1))), Is.False); 
    56             Assert.That(choosingArgs.Filter(new MutableCostCard(Worth.Coin(1) + Worth.Potion(1))), Is.False); 
     55            Assert.That(choosingArgs.Filter(new MutableCostCard(Worth.Create<PotionUnit>(1))), Is.False); 
     56            Assert.That(choosingArgs.Filter(new MutableCostCard(Worth.Coin(1) + Worth.Create<PotionUnit>(1))), Is.False); 
    5757 
    5858            Assert.That(movingArgs.From, Is.SameAs(supplyCard)); 
    5959            Assert.That(movingArgs.ToPosition, Is.EqualTo(CardPosition.Discard(0))); 
    6060        } 
     61 
     62        public class PotionUnit : Worth.Unit { } 
    6163    } 
    6264} 
  • lang/csharp/DominionEngine/DominionEngine.CardInfo.Test/DDL/CardInfoTest.cs

    r37526 r37540  
    9090            Func<ICardInfo, bool> costingUpTo = card.CostingUpTo(Worth.Coin(3)); 
    9191 
    92             card.cost = Worth.Potion(potion); 
     92            card.cost = Worth.Create<PotionUnit>(potion); 
    9393            Assert.That(costingUpTo(card), Is.False); 
    9494        } 
    9595 
    9696        #endregion 
     97 
     98        public class PotionUnit : Worth.Unit { } 
    9799    } 
    98100} 
  • lang/csharp/DominionEngine/DominionEngine.CardInfo.Test/Unit/WorthTest.cs

    r37465 r37540  
    1515        public void IsAfford(Worth cost, bool expected) 
    1616        { 
    17             Worth money = Worth.Coin(3) + Worth.Potion(1); 
     17            Worth money = Worth.Coin(3) + Worth.Create<PotionUnit>(1); 
    1818            Assert.That(money.IsAfford(cost), Is.EqualTo(expected)); 
    1919        } 
     
    2323            new object[]{Worth.Coin(3), true}, 
    2424            new object[]{Worth.Coin(4), false}, 
    25             new object[]{Worth.Potion(1), true}, 
    26             new object[]{Worth.Potion(2), false}, 
    27             new object[]{Worth.Coin(1) + Worth.Potion(1), true}, 
    28             new object[]{Worth.Coin(2) + Worth.Potion(1), true}, 
    29             new object[]{Worth.Coin(3) + Worth.Potion(1), true}, 
    30             new object[]{Worth.Coin(4) + Worth.Potion(1), false}, 
    31             new object[]{Worth.Coin(2) + Worth.Potion(2), false}, 
     25            new object[]{Worth.Create<PotionUnit>(1), true}, 
     26            new object[]{Worth.Create<PotionUnit>(2), false}, 
     27            new object[]{Worth.Coin(1) + Worth.Create<PotionUnit>(1), true}, 
     28            new object[]{Worth.Coin(2) + Worth.Create<PotionUnit>(1), true}, 
     29            new object[]{Worth.Coin(3) + Worth.Create<PotionUnit>(1), true}, 
     30            new object[]{Worth.Coin(4) + Worth.Create<PotionUnit>(1), false}, 
     31            new object[]{Worth.Coin(2) + Worth.Create<PotionUnit>(2), false}, 
    3232        }; 
    3333 
     
    4343        public static object[][] ToStringTestSource = new object[][]{ 
    4444            new object[]{Worth.Coin(1), "1C 0P"}, 
    45             new object[]{Worth.Potion(1), "0C 1P"}, 
    46             new object[]{Worth.Coin(1) + Worth.Potion(2), "1C 2P"}, 
     45            new object[]{Worth.Create<PotionUnit>(1), "0C 1P"}, 
     46            new object[]{Worth.Coin(1) + Worth.Create<PotionUnit>(2), "1C 2P"}, 
    4747        }; 
    4848 
     
    6464            new object[]{Worth.Coin(1), Worth.Coin(4)}, 
    6565            new object[]{Worth.Coin(2), Worth.Coin(3)}, 
    66             new object[]{Worth.Coin(1), Worth.Coin(1) + Worth.Potion(1)}, 
    67             new object[]{Worth.Potion(1), Worth.Coin(1)}, 
    68             new object[]{Worth.Potion(1), Worth.Coin(1) + Worth.Potion(1)}, 
    69             new object[]{Worth.Potion(1), Worth.Potion(2)}, 
    70             new object[]{Worth.Coin(1) + Worth.Potion(1), Worth.Coin(1) + Worth.Potion(2)}, 
    71             new object[]{Worth.Coin(1) + Worth.Potion(1), Worth.Coin(2) + Worth.Potion(1)}, 
    72             new object[]{Worth.Coin(1) + Worth.Potion(2), Worth.Coin(2) + Worth.Potion(1)}, 
     66            new object[]{Worth.Coin(1), Worth.Coin(1) + Worth.Create<PotionUnit>(1)}, 
     67            new object[]{Worth.Create<PotionUnit>(1), Worth.Coin(1)}, 
     68            new object[]{Worth.Create<PotionUnit>(1), Worth.Coin(1) + Worth.Create<PotionUnit>(1)}, 
     69            new object[]{Worth.Create<PotionUnit>(1), Worth.Create<PotionUnit>(2)}, 
     70            new object[]{Worth.Coin(1) + Worth.Create<PotionUnit>(1), Worth.Coin(1) + Worth.Create<PotionUnit>(2)}, 
     71            new object[]{Worth.Coin(1) + Worth.Create<PotionUnit>(1), Worth.Coin(2) + Worth.Create<PotionUnit>(1)}, 
     72            new object[]{Worth.Coin(1) + Worth.Create<PotionUnit>(2), Worth.Coin(2) + Worth.Create<PotionUnit>(1)}, 
    7373        }; 
    7474 
     
    8080        public void CoinValue() 
    8181        { 
    82             Worth cost = Worth.Coin(3) + Worth.Potion(2); 
     82            Worth cost = Worth.Coin(3) + Worth.Create<PotionUnit>(2); 
    8383            Assert.That(cost.CoinValue, Is.EqualTo(3)); 
    8484        } 
     
    8787        public void PotionValue() 
    8888        { 
    89             Worth cost = Worth.Coin(3) + Worth.Potion(2); 
    90             Assert.That(cost.PotionValue, Is.EqualTo(2)); 
     89            Worth cost = Worth.Coin(3) + Worth.Create<PotionUnit>(2); 
     90            Assert.That(cost.Value<PotionUnit>(), Is.EqualTo(2)); 
    9191        } 
    9292 
     
    9898        public void Add() 
    9999        { 
    100             Worth cost = Worth.Coin(1) + Worth.Coin(1) + Worth.Potion(1); 
     100            Worth cost = Worth.Coin(1) + Worth.Coin(1) + Worth.Create<PotionUnit>(1); 
    101101            Assert.That(cost.CoinValue, Is.EqualTo(2)); 
    102             Assert.That(cost.PotionValue, Is.EqualTo(1)); 
     102            Assert.That(cost.Value<PotionUnit>(), Is.EqualTo(1)); 
    103103        } 
    104104 
     
    106106        public void Sub() 
    107107        { 
    108             Worth cost1 = Worth.Coin(3) + Worth.Potion(5); 
    109             Worth cost2 = Worth.Coin(1) + Worth.Potion(4); 
     108            Worth cost1 = Worth.Coin(3) + Worth.Create<PotionUnit>(5); 
     109            Worth cost2 = Worth.Coin(1) + Worth.Create<PotionUnit>(4); 
    110110 
    111111            Worth cost = cost1 - cost2; 
    112112 
    113113            Assert.That(cost.CoinValue, Is.EqualTo(2)); 
    114             Assert.That(cost.PotionValue, Is.EqualTo(1)); 
     114            Assert.That(cost.Value<PotionUnit>(), Is.EqualTo(1)); 
    115115        } 
    116116 
    117117        #endregion 
     118 
     119        public class PotionUnit : Worth.Unit { } 
    118120    } 
    119121} 
  • lang/csharp/DominionEngine/DominionEngine.CardInfo/Unit/Worth.cs

    r37539 r37540  
    1919 
    2020        /// <summary> 
     21        /// 新たな価値 
     22        /// </summary> 
     23        /// <typeparam name="T">価値の種類</typeparam> 
     24        /// <param name="value">個数</param> 
     25        /// <returns></returns> 
     26        public static Worth Create<T>(int value) 
     27            where T : Unit 
     28        { 
     29            Worth worth = new Worth(); 
     30            worth.items.Add(typeof(T), value); 
     31            return worth; 
     32        } 
     33 
     34        /// <summary> 
    2135        /// コイン 
    2236        /// </summary> 
    2337        /// <param name="value">個数</param> 
    2438        /// <returns>価値</returns> 
    25         public static Worth Coin(int value) 
    26         { 
    27             Worth result = new Worth(); 
    28             result.items.Add(typeof(CoinUnit), value); 
    29             return result; 
    30         } 
    31  
    32         /// <summary> 
    33         /// ポーション 
    34         /// </summary> 
    35         /// <param name="value">個数</param> 
    36         /// <returns>価値</returns> 
    37         public static Worth Potion(int value) 
    38         { 
    39             Worth result = new Worth(); 
    40             result.items.Add(typeof(PotionUnit), value); 
    41             return result; 
    42         } 
     39        public static Worth Coin(int value) { return Create<CoinUnit>(value); } 
    4340 
    4441        #endregion 
     
    6360        public bool IsAfford(Worth cost) 
    6461        { 
    65             return CoinValue >= cost.CoinValue && PotionValue >= cost.PotionValue; 
     62            foreach (var item in cost.items) 
     63            { 
     64                if (this[item.Key] < item.Value) return false; 
     65            } 
     66 
     67            return true; 
    6668        } 
    6769 
     
    7274        public override string ToString() 
    7375        { 
    74             return String.Format("{0}C {1}P", CoinValue, PotionValue); 
     76            //StringBuilder format = new StringBuilder(); 
     77 
     78 
     79 
     80            return String.Format("{0}C {1}P", CoinValue, 0); 
    7581        } 
    7682 
     
    7884 
    7985        /// <summary> 
    80         /// コインの数 
     86        /// 単位ごとの価値 
    8187        /// </summary> 
     88        /// <param name="key"></param> 
    8289        /// <returns></returns> 
    83         public int CoinValue { get { return Value<CoinUnit>(); } } 
    84  
    85         /// <summary> 
    86         /// ポーションの数 
    87         /// </summary> 
    88         /// <returns></returns> 
    89         public int PotionValue { get { return Value<PotionUnit>(); } } 
     90        internal int this[Type key] 
     91        { 
     92            get { return items.ContainsKey(key) ? items[key] : 0; } 
     93        } 
    9094 
    9195        /// <summary> 
     
    97101            where T : Unit 
    98102        { 
    99             return items.ContainsKey(typeof(T)) ? items[typeof(T)] : 0; 
     103            return this[typeof(T)]; 
    100104        } 
     105 
     106        /// <summary> 
     107        /// コインの数 
     108        /// </summary> 
     109        /// <returns></returns> 
     110        public int CoinValue { get { return Value<CoinUnit>(); } } 
    101111 
    102112        #endregion 
     
    109119            if (CoinValue != other.CoinValue) return CoinValue.CompareTo(other.CoinValue); 
    110120            // ポーションが低い順 
    111             if (PotionValue != other.PotionValue) return PotionValue.CompareTo(other.PotionValue); 
     121            //if (PotionValue != other.PotionValue) return PotionValue.CompareTo(other.PotionValue); 
    112122 
    113123            return 0; 
     
    156166        public class CoinUnit : Unit { } 
    157167 
    158         /// <summary> 
    159         /// ポーション 
    160         /// </summary> 
    161         public class PotionUnit : Unit { } 
    162  
    163168        #endregion 
    164169    }