Changeset 37539 for lang/csharp

Show
Ignore:
Timestamp:
05/15/10 13:19:56 (3 years ago)
Author:
isaisstillalive
Message:
  • Worthを、セットで拡張可能な形に変更
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/csharp/DominionEngine/DominionEngine.CardInfo/Unit/Worth.cs

    r37465 r37539  
    99    /// 価値 
    1010    /// </summary> 
    11     public struct Worth : IComparable<Worth> 
     11    public class Worth : IComparable<Worth> 
    1212    { 
    1313        #region ビルダ 
     
    1616        /// 無価値 
    1717        /// </summary> 
    18         public static readonly Worth None = new Worth(0x0000); 
     18        public static readonly Worth None = new Worth(); 
    1919 
    2020        /// <summary> 
     
    2525        public static Worth Coin(int value) 
    2626        { 
    27             return new Worth(0x0001 * value); 
     27            Worth result = new Worth(); 
     28            result.items.Add(typeof(CoinUnit), value); 
     29            return result; 
    2830        } 
    2931 
     
    3537        public static Worth Potion(int value) 
    3638        { 
    37             return new Worth(0x0100 * value); 
     39            Worth result = new Worth(); 
     40            result.items.Add(typeof(PotionUnit), value); 
     41            return result; 
    3842        } 
    3943 
    4044        #endregion 
    4145 
    42         #region 値とコンストラクタ 
     46        #region コンストラクタ 
    4347 
    44         /// <summary> 
    45         /// 値 
    46         /// </summary> 
    47         internal int value; 
     48        internal Dictionary<Type, int> items = new Dictionary<Type, int>(); 
    4849 
    4950        /// <summary> 
     
    5152        /// </summary> 
    5253        /// <param name="value">値</param> 
    53         internal Worth(int value) 
    54         { 
    55             this.value = value; 
    56         } 
     54        internal Worth() { } 
    5755 
    5856        #endregion 
     
    8381        /// </summary> 
    8482        /// <returns></returns> 
    85         public int CoinValue { get { return value & 0x00FF; } } 
     83        public int CoinValue { get { return Value<CoinUnit>(); } } 
    8684 
    8785        /// <summary> 
     
    8987        /// </summary> 
    9088        /// <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        } 
    92101 
    93102        #endregion 
     
    111120        public static Worth operator +(Worth cost1, Worth cost2) 
    112121        { 
    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; 
    114130        } 
    115131 
    116132        public static Worth operator -(Worth cost1, Worth cost2) 
    117133        { 
    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; 
    119142        } 
     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 { } 
    120162 
    121163        #endregion