//constructort 1 public ShGame() { Questions = new List <ShQuestion>(); Players = new List <ShPlayer>(); Method = ShMethod.Sheep; Rounding = ShRoundingType.None; }
public static bool IsScoreDescending(ShMethod method) { if (method == ShMethod.PeehsDM || method == ShMethod.PeehsFB || method == ShMethod.PeehsHybrid) { return(false); } else { return(true); } }
public static string GetCorrectText(ShMethod method, bool correct) { if (method == ShMethod.Sheep || method == ShMethod.Heep || method == ShMethod.Heep15 || method == ShMethod.Heep2 || method == ShMethod.Manual) { return(correct ? "Valid" : "Invalid"); } else { return(correct ? "Correct" : "Incorrect"); } }
//read data from xmlreader public void ReadFromXML(XmlReader xr) { Questions.Clear(); Players.Clear(); Method = ShMethod.Sheep; Rounding = ShRoundingType.None; #region xrread while (xr.Read()) { if (xr.IsStartElement()) { switch (xr.Name) { case "ScoringMethod": Method = (ShMethod)Enum.Parse(typeof(ShMethod), xr.ReadElementString()); break; case "Rounding": Rounding = (ShRoundingType)Enum.Parse(typeof(ShRoundingType), xr.ReadElementString()); break; case "Question": int qindex = Convert.ToInt32(xr["GameIndex"]); while (Questions.Count < qindex + 1) { Questions.Add(new ShQuestion(this, "(blank)")); } Questions[qindex].Text = xr.ReadElementString(); break; case "Player": int pindex = Convert.ToInt32(xr["GameIndex"]); decimal start_score = Convert.ToDecimal(xr["StartScore"]); while (Players.Count < pindex + 1) { Players.Add(new ShPlayer(this, "(blank)", start_score)); } Players[pindex].Name = xr.ReadElementString(); break; case "Group": //assuming that question and player have already been //completely read in as they should be at the start //of the xml file int group_q_index = Convert.ToInt32(xr["QuestionIndex"]); bool tempcorrect = Convert.ToBoolean(xr["Correct"]); decimal tempgroupbonus = Convert.ToDecimal(xr["GroupBonus"]); var tempgroupbonustype = (ShBonusType)Enum.Parse(typeof(ShBonusType), xr["BonusType"]); ShGroup newGroup = new ShGroup(this.Questions[group_q_index], ""); newGroup.Correct = tempcorrect; newGroup.GroupBonus = tempgroupbonus; newGroup.BonusType = tempgroupbonustype; Questions[group_q_index].Groups.Add(newGroup); XmlReader subxr = xr.ReadSubtree(); while (subxr.Read()) { if (subxr.IsStartElement()) { switch (subxr.Name) { case "Text": newGroup.Text = subxr.ReadElementString(); break; case "Answer": int ans_p_index = Convert.ToInt32(subxr["PlayerIndex"]); decimal tempansbonus = Convert.ToDecimal(subxr["AnswerBonus"]); var tempansbonustype = (ShBonusType)Enum.Parse(typeof(ShBonusType), xr["BonusType"]); string anstext = xr.ReadElementString(); ShAnswer newAns = new ShAnswer(newGroup, Players[ans_p_index], anstext); newAns.AnswerBonus = tempansbonus; newAns.BonusType = tempansbonustype; newGroup.Answers.Add(newAns); Players[ans_p_index].Answers.Add(newAns); break; } } } break; } } } #endregion }