void ShowAnswer() { GraphEdgeData[] answers = new GraphEdgeData[m_Edges.Count]; m_Edges.CopyTo(answers); for (int i = 0; i < answers.Length; i++) { m_InputFields [i].text = string.Format("{0} {1}", answers [i].v0, answers [i].v1); HighlightInput(m_InputFields [i], false); } }
public bool Equals(GraphEdgeData other) { return((v0 == other.v0) && (v1 == other.v1)); }
bool ValidateAnswer() { HashSet <GraphEdgeData> goodInputs = new HashSet <GraphEdgeData> (); HashSet <InputField> badFormats = new HashSet <InputField> (); HashSet <InputField> wrongInputs = new HashSet <InputField> (); foreach (var item in m_InputFields) { string input = item.text.Trim(); string[] vertices = input.Split(' '); if (vertices.Length != 2) { badFormats.Add(item); continue; } int v0, v1; if (!int.TryParse(vertices [0], out v0)) { badFormats.Add(item); continue; } if (!int.TryParse(vertices [1], out v1)) { badFormats.Add(item); continue; } GraphEdgeData userEdge = new GraphEdgeData(v0, v1); if (!m_Edges.Contains(userEdge)) { wrongInputs.Add(item); continue; } if (goodInputs.Contains(userEdge)) { wrongInputs.Add(item); // duplicate input continue; } goodInputs.Add(userEdge); } // reset foreach (var item in m_InputFields) { HighlightInput(item, false); } if (badFormats.Count > 0) { // highlight them foreach (var item in badFormats) { HighlightInput(item); } ShowFeedbackText("请按格式要求填写每条边,已标记错误项。"); return(false); } if (wrongInputs.Count > 0) { // highlight them foreach (var item in wrongInputs) { HighlightInput(item); } ShowFeedbackText("填写有错误,已标记错误项。"); return(false); } return(true); }