Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [Serializable]
- public class Mana
- {
- // Fields
- protected int black;
- protected int blackwhite;
- protected int blue;
- protected int blueblack;
- protected int bluewhite;
- protected int colorless;
- protected int green;
- protected int greenblack;
- protected int greenblue;
- protected int greenred;
- protected int greenwhite;
- protected bool hasX;
- protected int red;
- protected int redblack;
- protected int redblue;
- protected int redwhite;
- protected int white;
- // Methods
- public static Mana Parse(string spec)
- {
- StringBuilder sb = new StringBuilder();
- StringBuilder cb = new StringBuilder();
- bool inHybrid = false;
- Mana m = new Mana();
- int $1 = 0;
- int $2 = spec.Length;
- if ($2 < 0)
- {
- throw new ArgumentOutOfRangeException("max");
- }
- while ($1 < $2)
- {
- int i = $1;
- $1++;
- if (inHybrid)
- {
- cb.Append(spec[i]);
- }
- else
- {
- if (char.IsDigit(spec[i]))
- {
- sb.Append(spec[i]);
- continue;
- }
- if (spec[i] == '{')
- {
- inHybrid = true;
- continue;
- }
- if (spec[i] == '}')
- {
- if (!inHybrid)
- {
- throw new ArgumentException("Closing } without opening");
- }
- inHybrid = false;
- string s = cb.ToString().ToUpper();
- if (s.Length != 2)
- {
- throw new ArgumentException("Only two-element hybrids supported");
- }
- if ((s == "GR") || (s == "RG"))
- {
- m.GreenRed++;
- }
- else if ((s == "GU") || (s == "UG"))
- {
- m.GreenBlue++;
- }
- else if ((s == "GB") || (s == "BG"))
- {
- m.GreenBlack++;
- }
- else if ((s == "GW") || (s == "WG"))
- {
- m.GreenWhite++;
- }
- else if ((s == "RU") || (s == "UR"))
- {
- m.RedBlue++;
- }
- else if ((s == "RB") || (s == "BR"))
- {
- m.RedBlack++;
- }
- else if ((s == "RW") || (s == "WR"))
- {
- m.RedWhite++;
- }
- else if ((s == "UB") || (s == "BU"))
- {
- m.BlueBlack++;
- }
- else if ((s == "UW") || (s == "WU"))
- {
- m.BlueWhite++;
- }
- else
- {
- if (!(s == "BW") && !(s == "WB"))
- {
- throw new ArgumentException(("Hybrid mana " + s) + " is not supported");
- }
- m.BlackWhite++;
- }
- continue;
- }
- if (char.ToUpper(spec[i]) == 'G')
- {
- m.Green++;
- }
- else
- {
- if (char.ToUpper(spec[i]) == 'R')
- {
- m.Red++;
- continue;
- }
- if (char.ToUpper(spec[i]) == 'U')
- {
- m.Blue++;
- continue;
- }
- if (char.ToUpper(spec[i]) == 'B')
- {
- m.Black++;
- continue;
- }
- if (char.ToUpper(spec[i]) == 'W')
- {
- m.White++;
- continue;
- }
- if (char.ToUpper(spec[i]) == 'X')
- {
- m.HasX = true;
- }
- }
- }
- }
- return null;
- }
- public override string ToString()
- {
- StringBuilder sb = new StringBuilder();
- if (this.colorless > 0)
- {
- sb.Append(this.colorless);
- }
- if (this.green > 0)
- {
- sb.Append("G");
- }
- if (this.red > 0)
- {
- sb.Append("R");
- }
- if (this.blue > 0)
- {
- sb.Append("U");
- }
- if (this.black > 0)
- {
- sb.Append("B");
- }
- if (this.white > 0)
- {
- sb.Append("W");
- }
- if (this.greenred > 0)
- {
- sb.Append("{GR}");
- }
- if (this.greenblue > 0)
- {
- sb.Append("{GU}");
- }
- if (this.greenblack > 0)
- {
- sb.Append("{GB}");
- }
- if (this.greenwhite > 0)
- {
- sb.Append("{GW}");
- }
- if (this.redblue > 0)
- {
- sb.Append("{RU}");
- }
- if (this.redblack > 0)
- {
- sb.Append("{RB}");
- }
- if (this.redwhite > 0)
- {
- sb.Append("{RW}");
- }
- if (this.blueblack > 0)
- {
- sb.Append("{UB}");
- }
- if (this.bluewhite > 0)
- {
- sb.Append("{UW}");
- }
- if (this.blackwhite > 0)
- {
- sb.Append("{BW}");
- }
- if (this.hasX)
- {
- sb.Append("X");
- }
- return sb.ToString();
- }
- // Properties
- public int Black
- {
- get
- {
- return this.black;
- }
- set
- {
- this.black = value;
- }
- }
- public int BlackWhite
- {
- get
- {
- return this.blackwhite;
- }
- set
- {
- this.blackwhite = value;
- }
- }
- public int Blue
- {
- get
- {
- return this.blue;
- }
- set
- {
- this.blue = value;
- }
- }
- public int BlueBlack
- {
- get
- {
- return this.blueblack;
- }
- set
- {
- this.blueblack = value;
- }
- }
- public int BlueWhite
- {
- get
- {
- return this.bluewhite;
- }
- set
- {
- this.bluewhite = value;
- }
- }
- public int Colorless
- {
- get
- {
- return this.colorless;
- }
- set
- {
- this.colorless = value;
- }
- }
- public int ConvertedManaCost
- {
- get
- {
- return (((((this.Colorless + this.Green) + this.Red) + this.Blue) + this.Black) + this.White);
- }
- }
- public int Green
- {
- get
- {
- return this.green;
- }
- set
- {
- this.green = value;
- }
- }
- public int GreenBlack
- {
- get
- {
- return this.greenblack;
- }
- set
- {
- this.greenblack = value;
- }
- }
- public int GreenBlue
- {
- get
- {
- return this.greenblue;
- }
- set
- {
- this.greenblue = value;
- }
- }
- public int GreenRed
- {
- get
- {
- return this.greenred;
- }
- set
- {
- this.greenred = value;
- }
- }
- public int GreenWhite
- {
- get
- {
- return this.greenwhite;
- }
- set
- {
- this.greenwhite = value;
- }
- }
- public bool HasX
- {
- get
- {
- return this.hasX;
- }
- set
- {
- this.hasX = value;
- }
- }
- public bool IsBlack
- {
- get
- {
- return ((this.black <= 0) ? ((this.greenblack <= 0) ? ((this.redblack <= 0) ? ((this.blueblack <= 0) ? (this.blackwhite > 0) : true) : true) : true) : true);
- }
- }
- public bool IsBlue
- {
- get
- {
- return ((this.blue <= 0) ? ((this.greenblue <= 0) ? ((this.redblue <= 0) ? ((this.blueblack <= 0) ? (this.bluewhite > 0) : true) : true) : true) : true);
- }
- }
- public bool IsGreen
- {
- get
- {
- return ((this.green <= 0) ? ((this.greenred <= 0) ? ((this.greenblue <= 0) ? ((this.greenblack <= 0) ? (this.greenwhite > 0) : true) : true) : true) : true);
- }
- }
- public bool IsRed
- {
- get
- {
- return ((this.red <= 0) ? ((this.greenred <= 0) ? ((this.redblue <= 0) ? ((this.redblack <= 0) ? (this.redwhite > 0) : true) : true) : true) : true);
- }
- }
- public bool IsWhite
- {
- get
- {
- return ((this.white <= 0) ? ((this.greenwhite <= 0) ? ((this.redwhite <= 0) ? ((this.bluewhite <= 0) ? (this.blackwhite > 0) : true) : true) : true) : true);
- }
- }
- public int Red
- {
- get
- {
- return this.red;
- }
- set
- {
- this.red = value;
- }
- }
- public int RedBlack
- {
- get
- {
- return this.redblack;
- }
- set
- {
- this.redblack = value;
- }
- }
- public int RedBlue
- {
- get
- {
- return this.redblue;
- }
- set
- {
- this.redblue = value;
- }
- }
- public int RedWhite
- {
- get
- {
- return this.redwhite;
- }
- set
- {
- this.redwhite = value;
- }
- }
- public int White
- {
- get
- {
- return this.white;
- }
- set
- {
- this.white = value;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement