Changeset 37540 for lang/csharp
- Timestamp:
- 05/15/10 13:37:55 (3 years ago)
- Location:
- lang/csharp/DominionEngine
- Files:
-
- 4 modified
-
DominionEngine.CardInfo.Test/Base/WorkshopTest.cs (modified) (1 diff)
-
DominionEngine.CardInfo.Test/DDL/CardInfoTest.cs (modified) (1 diff)
-
DominionEngine.CardInfo.Test/Unit/WorthTest.cs (modified) (8 diffs)
-
DominionEngine.CardInfo/Unit/Worth.cs (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/csharp/DominionEngine/DominionEngine.CardInfo.Test/Base/WorkshopTest.cs
r37504 r37540 53 53 Assert.That(choosingArgs.Filter(new MutableCostCard(Worth.Coin(4))), Is.True); 54 54 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); 57 57 58 58 Assert.That(movingArgs.From, Is.SameAs(supplyCard)); 59 59 Assert.That(movingArgs.ToPosition, Is.EqualTo(CardPosition.Discard(0))); 60 60 } 61 62 public class PotionUnit : Worth.Unit { } 61 63 } 62 64 } -
lang/csharp/DominionEngine/DominionEngine.CardInfo.Test/DDL/CardInfoTest.cs
r37526 r37540 90 90 Func<ICardInfo, bool> costingUpTo = card.CostingUpTo(Worth.Coin(3)); 91 91 92 card.cost = Worth. Potion(potion);92 card.cost = Worth.Create<PotionUnit>(potion); 93 93 Assert.That(costingUpTo(card), Is.False); 94 94 } 95 95 96 96 #endregion 97 98 public class PotionUnit : Worth.Unit { } 97 99 } 98 100 } -
lang/csharp/DominionEngine/DominionEngine.CardInfo.Test/Unit/WorthTest.cs
r37465 r37540 15 15 public void IsAfford(Worth cost, bool expected) 16 16 { 17 Worth money = Worth.Coin(3) + Worth. Potion(1);17 Worth money = Worth.Coin(3) + Worth.Create<PotionUnit>(1); 18 18 Assert.That(money.IsAfford(cost), Is.EqualTo(expected)); 19 19 } … … 23 23 new object[]{Worth.Coin(3), true}, 24 24 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}, 32 32 }; 33 33 … … 43 43 public static object[][] ToStringTestSource = new object[][]{ 44 44 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"}, 47 47 }; 48 48 … … 64 64 new object[]{Worth.Coin(1), Worth.Coin(4)}, 65 65 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)}, 73 73 }; 74 74 … … 80 80 public void CoinValue() 81 81 { 82 Worth cost = Worth.Coin(3) + Worth. Potion(2);82 Worth cost = Worth.Coin(3) + Worth.Create<PotionUnit>(2); 83 83 Assert.That(cost.CoinValue, Is.EqualTo(3)); 84 84 } … … 87 87 public void PotionValue() 88 88 { 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)); 91 91 } 92 92 … … 98 98 public void Add() 99 99 { 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); 101 101 Assert.That(cost.CoinValue, Is.EqualTo(2)); 102 Assert.That(cost. PotionValue, Is.EqualTo(1));102 Assert.That(cost.Value<PotionUnit>(), Is.EqualTo(1)); 103 103 } 104 104 … … 106 106 public void Sub() 107 107 { 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); 110 110 111 111 Worth cost = cost1 - cost2; 112 112 113 113 Assert.That(cost.CoinValue, Is.EqualTo(2)); 114 Assert.That(cost. PotionValue, Is.EqualTo(1));114 Assert.That(cost.Value<PotionUnit>(), Is.EqualTo(1)); 115 115 } 116 116 117 117 #endregion 118 119 public class PotionUnit : Worth.Unit { } 118 120 } 119 121 } -
lang/csharp/DominionEngine/DominionEngine.CardInfo/Unit/Worth.cs
r37539 r37540 19 19 20 20 /// <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> 21 35 /// コイン 22 36 /// </summary> 23 37 /// <param name="value">個数</param> 24 38 /// <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); } 43 40 44 41 #endregion … … 63 60 public bool IsAfford(Worth cost) 64 61 { 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; 66 68 } 67 69 … … 72 74 public override string ToString() 73 75 { 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); 75 81 } 76 82 … … 78 84 79 85 /// <summary> 80 /// コインの数86 /// 単位ごとの価値 81 87 /// </summary> 88 /// <param name="key"></param> 82 89 /// <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 } 90 94 91 95 /// <summary> … … 97 101 where T : Unit 98 102 { 99 return items.ContainsKey(typeof(T)) ? items[typeof(T)] : 0;103 return this[typeof(T)]; 100 104 } 105 106 /// <summary> 107 /// コインの数 108 /// </summary> 109 /// <returns></returns> 110 public int CoinValue { get { return Value<CoinUnit>(); } } 101 111 102 112 #endregion … … 109 119 if (CoinValue != other.CoinValue) return CoinValue.CompareTo(other.CoinValue); 110 120 // ポーションが低い順 111 if (PotionValue != other.PotionValue) return PotionValue.CompareTo(other.PotionValue);121 //if (PotionValue != other.PotionValue) return PotionValue.CompareTo(other.PotionValue); 112 122 113 123 return 0; … … 156 166 public class CoinUnit : Unit { } 157 167 158 /// <summary>159 /// ポーション160 /// </summary>161 public class PotionUnit : Unit { }162 163 168 #endregion 164 169 }
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)