| 1 | using System;
|
|---|
| 2 | using System.Collections.Generic;
|
|---|
| 3 | using System.Linq;
|
|---|
| 4 | using System.Text;
|
|---|
| 5 |
|
|---|
| 6 | namespace DominionEngine.CardInfo
|
|---|
| 7 | {
|
|---|
| 8 | /// <summary>
|
|---|
| 9 | /// 価値
|
|---|
| 10 | /// </summary>
|
|---|
| 11 | public struct Worth : IComparable<Worth>
|
|---|
| 12 | {
|
|---|
| 13 | #region ビルダ
|
|---|
| 14 |
|
|---|
| 15 | /// <summary>
|
|---|
| 16 | /// 無価値
|
|---|
| 17 | /// </summary>
|
|---|
| 18 | public static readonly Worth None = new Worth(0x0000);
|
|---|
| 19 |
|
|---|
| 20 | /// <summary>
|
|---|
| 21 | /// コイン
|
|---|
| 22 | /// </summary>
|
|---|
| 23 | /// <param name="value">個数</param>
|
|---|
| 24 | /// <returns>価値</returns>
|
|---|
| 25 | public static Worth Coin(int value)
|
|---|
| 26 | {
|
|---|
| 27 | return new Worth(0x0001 * value);
|
|---|
| 28 | }
|
|---|
| 29 |
|
|---|
| 30 | /// <summary>
|
|---|
| 31 | /// ポーション
|
|---|
| 32 | /// </summary>
|
|---|
| 33 | /// <param name="value">個数</param>
|
|---|
| 34 | /// <returns>価値</returns>
|
|---|
| 35 | public static Worth Potion(int value)
|
|---|
| 36 | {
|
|---|
| 37 | return new Worth(0x0100 * value);
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 | #endregion
|
|---|
| 41 |
|
|---|
| 42 | #region 値とコンストラクタ
|
|---|
| 43 |
|
|---|
| 44 | /// <summary>
|
|---|
| 45 | /// 値
|
|---|
| 46 | /// </summary>
|
|---|
| 47 | internal int value;
|
|---|
| 48 |
|
|---|
| 49 | /// <summary>
|
|---|
| 50 | /// 価値を作成
|
|---|
| 51 | /// </summary>
|
|---|
| 52 | /// <param name="value">値</param>
|
|---|
| 53 | internal Worth(int value)
|
|---|
| 54 | {
|
|---|
| 55 | this.value = value;
|
|---|
| 56 | }
|
|---|
| 57 |
|
|---|
| 58 | #endregion
|
|---|
| 59 |
|
|---|
| 60 | /// <summary>
|
|---|
| 61 | /// コストが支払えるかどうか
|
|---|
| 62 | /// </summary>
|
|---|
| 63 | /// <param name="cost">対象のコスト</param>
|
|---|
| 64 | /// <returns></returns>
|
|---|
| 65 | public bool IsAfford(Worth cost)
|
|---|
| 66 | {
|
|---|
| 67 | return CoinValue >= cost.CoinValue && PotionValue >= cost.PotionValue;
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | /// <summary>
|
|---|
| 71 | /// ToString
|
|---|
| 72 | /// </summary>
|
|---|
| 73 | /// <returns></returns>
|
|---|
| 74 | public override string ToString()
|
|---|
| 75 | {
|
|---|
| 76 | return String.Format("{0}C {1}P", CoinValue, PotionValue);
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | #region 個別の価値
|
|---|
| 80 |
|
|---|
| 81 | /// <summary>
|
|---|
| 82 | /// コインの数
|
|---|
| 83 | /// </summary>
|
|---|
| 84 | /// <returns></returns>
|
|---|
| 85 | public int CoinValue { get { return value & 0x00FF; } }
|
|---|
| 86 |
|
|---|
| 87 | /// <summary>
|
|---|
| 88 | /// ポーションの数
|
|---|
| 89 | /// </summary>
|
|---|
| 90 | /// <returns></returns>
|
|---|
| 91 | public int PotionValue { get { return (value >> 8) & 0x00FF; } }
|
|---|
| 92 |
|
|---|
| 93 | #endregion
|
|---|
| 94 |
|
|---|
| 95 | #region 比較
|
|---|
| 96 |
|
|---|
| 97 | public int CompareTo(Worth other)
|
|---|
| 98 | {
|
|---|
| 99 | // コインが低い順
|
|---|
| 100 | if (CoinValue != other.CoinValue) return CoinValue.CompareTo(other.CoinValue);
|
|---|
| 101 | // ポーションが低い順
|
|---|
| 102 | if (PotionValue != other.PotionValue) return PotionValue.CompareTo(other.PotionValue);
|
|---|
| 103 |
|
|---|
| 104 | return 0;
|
|---|
| 105 | }
|
|---|
| 106 |
|
|---|
| 107 | #endregion
|
|---|
| 108 |
|
|---|
| 109 | #region 算術演算子
|
|---|
| 110 |
|
|---|
| 111 | public static Worth operator +(Worth cost1, Worth cost2)
|
|---|
| 112 | {
|
|---|
| 113 | return new Worth(cost1.value + cost2.value);
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | public static Worth operator -(Worth cost1, Worth cost2)
|
|---|
| 117 | {
|
|---|
| 118 | return new Worth(cost1.value - cost2.value);
|
|---|
| 119 | }
|
|---|
| 120 |
|
|---|
| 121 | #endregion
|
|---|
| 122 | }
|
|---|
| 123 | }
|
|---|