Changeset 37539 for lang/csharp
- Timestamp:
- 05/15/10 13:19:56 (3 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
lang/csharp/DominionEngine/DominionEngine.CardInfo/Unit/Worth.cs
r37465 r37539 9 9 /// 価値 10 10 /// </summary> 11 public structWorth : IComparable<Worth>11 public class Worth : IComparable<Worth> 12 12 { 13 13 #region ビルダ … … 16 16 /// 無価値 17 17 /// </summary> 18 public static readonly Worth None = new Worth( 0x0000);18 public static readonly Worth None = new Worth(); 19 19 20 20 /// <summary> … … 25 25 public static Worth Coin(int value) 26 26 { 27 return new Worth(0x0001 * value); 27 Worth result = new Worth(); 28 result.items.Add(typeof(CoinUnit), value); 29 return result; 28 30 } 29 31 … … 35 37 public static Worth Potion(int value) 36 38 { 37 return new Worth(0x0100 * value); 39 Worth result = new Worth(); 40 result.items.Add(typeof(PotionUnit), value); 41 return result; 38 42 } 39 43 40 44 #endregion 41 45 42 #region 値とコンストラクタ46 #region コンストラクタ 43 47 44 /// <summary> 45 /// 値 46 /// </summary> 47 internal int value; 48 internal Dictionary<Type, int> items = new Dictionary<Type, int>(); 48 49 49 50 /// <summary> … … 51 52 /// </summary> 52 53 /// <param name="value">値</param> 53 internal Worth(int value) 54 { 55 this.value = value; 56 } 54 internal Worth() { } 57 55 58 56 #endregion … … 83 81 /// </summary> 84 82 /// <returns></returns> 85 public int CoinValue { get { return value & 0x00FF; } }83 public int CoinValue { get { return Value<CoinUnit>(); } } 86 84 87 85 /// <summary> … … 89 87 /// </summary> 90 88 /// <returns></returns> 91 public int PotionValue { get { return (value >> 8) & 0x00FF; } } 89 public int PotionValue { get { return Value<PotionUnit>(); } } 90 91 /// <summary> 92 /// 単位ごとの価値 93 /// </summary> 94 /// <typeparam name="T">価値の単位</typeparam> 95 /// <returns></returns> 96 public int Value<T>() 97 where T : Unit 98 { 99 return items.ContainsKey(typeof(T)) ? items[typeof(T)] : 0; 100 } 92 101 93 102 #endregion … … 111 120 public static Worth operator +(Worth cost1, Worth cost2) 112 121 { 113 return new Worth(cost1.value + cost2.value); 122 Worth worth = new Worth(); 123 worth.items = new Dictionary<Type, int>(cost1.items); 124 foreach (var item in cost2.items) 125 { 126 if (!worth.items.ContainsKey(item.Key)) worth.items[item.Key] = 0; 127 worth.items[item.Key] += item.Value; 128 } 129 return worth; 114 130 } 115 131 116 132 public static Worth operator -(Worth cost1, Worth cost2) 117 133 { 118 return new Worth(cost1.value - cost2.value); 134 Worth worth = new Worth(); 135 worth.items = new Dictionary<Type, int>(cost1.items); 136 foreach (var item in cost2.items) 137 { 138 if (!worth.items.ContainsKey(item.Key)) worth.items[item.Key] = 0; 139 worth.items[item.Key] -= item.Value; 140 } 141 return worth; 119 142 } 143 144 #endregion 145 146 #region 価値の単位 147 148 /// <summary> 149 /// 価値の単位 150 /// </summary> 151 public interface Unit { }; 152 153 /// <summary> 154 /// コイン 155 /// </summary> 156 public class CoinUnit : Unit { } 157 158 /// <summary> 159 /// ポーション 160 /// </summary> 161 public class PotionUnit : Unit { } 120 162 121 163 #endregion
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)