public Chains() { var chainsData = ReadFromXml.GetChains(); _chains = new List <IChain>(); _chains = chainsData.Select(chain => new Chain(chain.Id, chain.Name) as IChain).ToList(); }
void Judge(GameObject button) //judge the button that user have just selected { if (Time.time - lastTime < 5) { return; } rightAnswers = ReadFromXml.ReadRightAnswers(id); if (rightAnswers.Count == 1) { string myAns = button.GetComponentInChildren <Text>().text; if (myAns == rightAnswers[0]) //if the answer is right { score.text = "That's right!"; Destroy("Button"); id++; ShowQuestion.Show(); //show the next question and options rightAnswers = ReadFromXml.ReadRightAnswers(id); //update the right answer Init(); } else { score.text = "Try Again"; //if not right then print try again } lastTime = Time.time; updateOn = true; } }
void Judge(GameObject[] toggles) { if (Time.time - lastTime < 5) { return; } rightAnswers = ReadFromXml.ReadRightAnswers(id); if (toggles.Length == rightAnswers.Count) { foreach (GameObject toggle in toggles) { if (!rightAnswers.Contains(toggle.GetComponent <Text>().text)) { score.text = "Try again"; return; } } score.text = "That's right!"; Destroy("Toggle"); id++; ShowQuestion.Show(); //show the next question and options rightAnswers = ReadFromXml.ReadRightAnswers(id); //update the right answer Init(); return; } score.text = "Try again"; lastTime = Time.time; updateOn = true; }
public List <string> GetGroceries(string typeName) { if (!_groceriesByCategory.ContainsKey(typeName)) { _groceriesByCategory.Add(typeName, ReadFromXml.GetGroceriesFromAdb(typeName)); } return(_groceriesByCategory[typeName]); }
public void AddItem(string itemName) { if (!_chains[0].CheckIfThereIsAnItem(itemName)) { _chains.ForEach( chain => chain.AddItem(itemName, ReadFromXml.GetPrice(chain.Name, ReadFromXml.GetItemId(itemName, chain.Name)))); } }
private void ReadFromXML(object sender, System.EventArgs e) { TravelAgencyDbContext dbContext = new TravelAgencyDbContext(); ReadFromXml xmlReader = new ReadFromXml(); this.guides = xmlReader.ImportFromXmlIntoSql("../../../Data files/Guides.xml"); this.HideLoadDataButtons(); importFormXmlToSqlButton.Show(); loadFromXmlToMongoDbButton.Show(); this.backButton.Visible = true; }
public List <string> GetGroceries(string typeName) { /* * Consider that call chaining ( passing the result of some call as a parameter to another is not such a good practice * If such code throws an exception, you will have a hard time understanding what happened. */ if (!_groceriesByCategory.ContainsKey(typeName)) { _groceriesByCategory.Add(typeName, ReadFromXml.GetGroceriesFromAdb(typeName)); } return(_groceriesByCategory[typeName]); }
public void AddItem(string itemName) { /*It is unclear why you're so certain that the first index will hold a value * Why you're sure that value will not be null * And why you only do this for the first index's value. * * Also, consider that call chaining ( passing the result of some call as a parameter to another is not such a good practice * If such code throws an exception, you will have a hard time understanding what happened. */ if (!_chains[0].CheckIfThereIsAnItem(itemName)) { _chains.ForEach( chain => chain.AddItem(itemName, ReadFromXml.GetPrice(chain.Name, ReadFromXml.GetItemId(itemName, chain.Name)))); } }
void Start() { rightAnswers = ReadFromXml.ReadRightAnswers(id); scoreBoard = GameObject.Find("ScoreBoard"); //get scoreboard object score = scoreBoard.GetComponentInChildren <Text>(); //get text componnet of scoreboard if (rightAnswers == null) { return; } confirmButton = GameObject.Find("ConfirmButton").GetComponent <Button>(); //get confirm button toggles = GameObject.FindGameObjectsWithTag("Toggle"); //find toggles confirmButton.onClick.AddListener(() => Judge(toggles)); //add listener to confirm button buttons = GameObject.FindGameObjectsWithTag("Button"); //find buttons for (int i = 0; i < buttons.Length; i++) { GameObject button = buttons[i]; button.GetComponent <Button>().onClick.AddListener(() => Judge(button)); //add listener to buttons } }
public static void Show() { questionText.text = ReadFromXml.ReadQuestion(id); //show question isMultiType = ReadFromXml.IsMulti(id); //get question type List <string> optionList = ReadFromXml.ReadAnswers(id); //read options int optionNum = optionList.Count; if (isMultiType) //if type_multiple { Vector3 originalTogglePosition = oriToggle.transform.position; toggles = new GameObject[optionNum]; for (int i = 0; i < optionNum; i++) { toggles[i] = GameObject.Instantiate(oriToggle, answerSheet); Text optionText = toggles[i].GetComponentInChildren <Text>(); optionText.text = optionList[i]; toggles[i].tag = "Toggle"; toggles[i].transform.position = originalTogglePosition; originalTogglePosition += Vector3.down * 0.12f; } return; } Vector3 originalPosition = oriButton.transform.position; buttons = new GameObject[optionNum]; for (int i = 0; i < optionNum; i++) { buttons[i] = GameObject.Instantiate(oriButton, answerSheet); Text optionText = buttons[i].GetComponentInChildren <Text>(); optionText.text = optionList[i]; buttons[i].tag = "Button"; buttons[i].transform.position = originalPosition; originalPosition += Vector3.down * 0.2f; } id++; }
public string[] GetCategories() { return(ReadFromXml.GetCategories()); }