/// <summary> /// TODO: VM Hard Achievement /// Convert a String like "400g 34c" into a Money object. /// You should be able to Enter large numbers, but not negative numbers. /// (after all, these properties are "unsigned integers") /// /// So, "2841924c" is a valid string /// but, "-24p" is not. /// /// "10p 249g 24s 842c" is valid but not in simplest terms, so it is /// up to you how you will handle the difference. /// /// </summary> /// <param name="displayString"></param> public Money(string displayString) { if (!displayString.Contains('-')) { //we split the string entered as a parameter into multiple parts (if any) //these splitparts then are added to create an array string[] moneyParts = displayString.Split(' '); //then we run a loop that goes through each part //each time we loop, we check whether the monetary amount in in units of c, s, g, or p //player will recieve separate warnings for having mixed units (ex: 25 cg), having no units (ex: 25), or negative money amounts (ex: -25c) for (int i = 0; i == moneyParts.Length - 1; i++) { if (moneyParts[i].Contains('c')) { moneyParts[i] = moneyParts[i].Remove('c'); if (!moneyParts[i].Contains('s') && !moneyParts[i].Contains('g') && !moneyParts[i].Contains('p')) { Copper = Convert.ToUInt16(moneyParts[i], 16); } else { TextFormatter.PrintLineWarning("Hmm...mixed units of money...? Only one unit per number please."); } } else if (moneyParts[i].Contains('s')) { moneyParts[i] = moneyParts[i].Remove('s'); if (!moneyParts[i].Contains('c') && !moneyParts[i].Contains('g') && !moneyParts[i].Contains('p')) { Silver = Convert.ToUInt16(moneyParts[i], 16); } else { TextFormatter.PrintLineWarning("Hmm...mixed units of money...? Only one unit per number please."); } } else if (moneyParts[i].Contains('g')) { moneyParts[i] = moneyParts[i].Remove('g'); if (!moneyParts[i].Contains('c') && !moneyParts[i].Contains('s') && !moneyParts[i].Contains('p')) { Gold = Convert.ToUInt16(moneyParts[i], 16); } else { TextFormatter.PrintLineWarning("Hmm...mixed units of money...? Only one unit per number please."); } } else if (moneyParts[i].Contains('p')) { moneyParts[i] = moneyParts[i].Remove('p'); if (!moneyParts[i].Contains('c') && !moneyParts[i].Contains('s') && !moneyParts[i].Contains('g')) { Platinum = Convert.ToUInt16(moneyParts[i], 16); } else { TextFormatter.PrintLineWarning("Hmm...mixed units of money...? Only one unit per number please."); } } else { TextFormatter.PrintLineWarning("Remember to add monetary units at the end of your money amounts (ex: Make sure to write 5p and not just 5)."); } } } else { TextFormatter.PrintLineWarning("Negative money is bad! Don't even think about typing negative signs!!!"); } }
//since we can't use a book ON something, we'll just laugh at the player for a sec and then just make them read the book's contents public void Use(ref object target) { TextFormatter.PrintWarning("You try to use the book on the {0}... So you fling your book at the {0}...", target); TextFormatter.PrintWarning("It doesn't work, of course, and you, growing red in the face, walk over and pick up your book and finally read it.", target); Use(); }