/// <summary> /// Stores the current resources into resource array /// </summary> /// <returns> The resources array </returns> public int[] GetResources() { // Instruct to get the current resources _action = ENUM.BuildingActions.GetResources; NavigateThroughTread(_url.GetUrl(ENUM.Screens.Headquarters)); return(_resources); }
/// <summary> /// This function is used to get overall information about the buildings /// </summary> /// <returns> A list of buildings </returns> public Buildings[] GetBuildings() { // instruct to get building information _action = ENUM.BuildingActions.SetBuildingLevels; NavigateThroughTread(_url.GetUrl(ENUM.Screens.Headquarters)); return(_myBuildings); }
/// <summary> /// This function is used to upgrade a specific building /// </summary> /// <param name="building"> The building that is to be built </param> /// <returns> True if successfull, else false </returns> public bool UpgradeBuilding(ENUM.Buildings building) { // get the key word that is on DOM (depended on the level of the building) _upgReference = _myBuildings[(int)building].Reference + (_myBuildings[(int)building].Level + 1); // instruct to upgrade the building _action = ENUM.BuildingActions.UpgLevel; NavigateThroughTread(_url.GetUrl(ENUM.Screens.Headquarters)); return(_actionFlag); }
/// <summary> /// This event fires when the navigation inside theread is complete. The main actions are performed /// in this function. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void PageLoaded(object sender, WebBrowserDocumentCompletedEventArgs e) { _actionFlag = false; // reset the action flag switch (_action) { case ENUM.BuildingActions.SetBuildingLevels: if (!_wb.Url.ToString().Equals(_url.GetUrl(ENUM.Screens.Headquarters))) { return; // keep searching the page until the buttons are all loaded } _queue = Parser.QueueNumber(_wb); GetLevels(); _actionFlag = true; break; case ENUM.BuildingActions.UpgLevel: if (!_wb.Url.ToString().Equals(_url.GetUrl(ENUM.Screens.Headquarters))) { return; // keep searching the page until the buttons are all loaded } _queue = Parser.QueueNumber(_wb); // get the number of queues // queue value can not be more than 2, if there is already 2 buildings on queue // upgrade command fails if (_wb.Document != null && _queue != 2) { var button = _wb.Document.GetElementById(_upgReference); if (button != null) { button.InvokeMember("click"); } } else { _actionFlag = false; return; } _action = ENUM.BuildingActions.ControlUpg; return; case ENUM.BuildingActions.ControlUpg: if (!_wb.Url.ToString().Equals(_url.GetUrl(ENUM.Screens.Headquarters))) { return; // keep searching the page until the buttons are all loaded } if (Parser.QueueNumber(_wb) != _queue + 1) { _wb.Refresh(); return; } _queue++; _actionFlag = true; break; case ENUM.BuildingActions.GetResources: if (!_wb.Url.ToString().Equals(_url.GetUrl(ENUM.Screens.Headquarters))) { return; // keep searching the page until the buttons are all loaded } _resources[(int)ENUM.Resources.Wood] = int.Parse(Parser.FindNode(_wb, "id", "wood").InnerText); _resources[(int)ENUM.Resources.Clay] = int.Parse(Parser.FindNode(_wb, "id", "stone").InnerText); _resources[(int)ENUM.Resources.Iron] = int.Parse(Parser.FindNode(_wb, "id", "iron").InnerText); _actionFlag = true; break; case ENUM.BuildingActions.Idle: // Do nothing return; } _action = ENUM.BuildingActions.Idle; Application.ExitThread(); // Stops the thread }