Пример #1
0
        /// <summary>
        ///   Controlla se è possibile costruire un determinato edificio
        /// </summary>
        /// <param name = "b">L'edificio che si vuole controllare</param>
        /// <exception cref = "NotConnectedException">Solleva un eccezione se non si è connessi a internet</exception>
        /// <returns>Vero se è possibile crearlo, Falso se non è possibile</returns>
        public CanBuildReturnValues CanBuild(Buildings b)
        {
            BrowsePage(b.Page());
            if (Document.All.Count == 0) throw new NotConnectedException();

            foreach (HtmlElement element in Document.All)
            {
                if (element.GetAttribute("className") == "construction" && element.FirstChild != null && element.FirstChild.GetAttribute("className") == "pusher")
                    return CanBuildReturnValues.InConstruction;

                if (element.GetAttribute("ref") == "") continue;
                if (int.Parse(element.GetAttribute("ref")) != (int)b) continue;

                string @class = element.Parent.Parent.Parent.GetAttribute("className");
                switch (@class)
                {
                    case "on":
                        return CanBuildReturnValues.Yes;
                    case "off":
                        return CanBuildReturnValues.Unavaiable;
                    default:
                        return CanBuildReturnValues.NotEnoughResources;
                }
            }
            throw new NotConnectedException();
        }
Пример #2
0
        /// <summary>
        ///   Esegue la costruzione di un determinato edificio
        /// </summary>
        /// <param name = "b">L'edificio che si vuole costruire</param>
        /// <exception cref = "NotConnectedException">Solleva un eccezione se non si è connessi a internet</exception>
        public void Build(Buildings b)
        {
            BrowsePage(b.Page());

            if (Document == null) throw new NotConnectedException();
            foreach (HtmlElement element in Document.All)
            {
                if (element.GetAttribute("ref") == "") continue;
                if (int.Parse(element.GetAttribute("ref")) != (int)b) continue;
                element.Parent.FirstChild.InvokeMember("click");
                element.Parent.FirstChild.RaiseEvent("onclick");
                break;
            }
        }