Example #1
0
        /// <summary>
        /// Checks to see if there is a CardGame server running at the address currently in the search bar.
        /// </summary>
        /// <returns>True if a valid server is found.</returns>
        private bool SearchForServer()
        {
            //JoinButton.Disabled = false;

            /*
             *
             * client.ConnectToServer(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8088));
             * System.Diagnostics.Debug.WriteLine("Connected to server. Listening.");
             * return false;
             */

            // TODO use ip provided by the constructor if searchbar doesn't pan out

            IPAddress CheckIP;

            SearchInfobox.Text.Clear(); // Clear the info box

            /*
             * if (!IPAddress.TryParse(SearchBar.Text, out CheckIP))
             * {
             *  SearchInfobox.Text.Add("Enter a valid IP address");
             *  JoinButton.Disabled = true;
             *  return false;
             * }
             */

            if (!SearchBar.Disabled) // if the SearchBar is available, its contents override ServerIP
            {
                if (IPAddress.TryParse(SearchBar.Text, out CheckIP))
                {
                    ServerIP = CheckIP;
                }
            }

            System.Diagnostics.Debug.WriteLine("Trying to connect to server.");
            SearchInfobox.Text.Add("Searching for server at " + ServerIP.ToString());

            try
            {
                client.ConnectToServer(new IPEndPoint(ServerIP, Cards.Structs.GameConstants.SERVER_PORT));
            }
            catch (ArgumentException e)
            {
                SearchInfobox.Text.Add(e.Message);
            }

            if (client.Connected)
            {
                SearchInfobox.Text.Add("Found a server!");
                JoinButton.Disabled = false;
                return(true);
            }

            SearchInfobox.Text.Add("No server was found.");
            JoinButton.Disabled = true;
            return(false);
        }
Example #2
0
        public override void Initialize()
        {
            interfaceSpriteBatch = new SpriteBatch(currentGame.GraphicsDevice);
            finalSpriteBatch     = new SpriteBatch(currentGame.GraphicsDevice);
            OnScreenElements     = new List <IClickable>();

            OnScreenElements.Add(TestButton);
            LayoutManager.AddElement(TestButton);

            currentInputEvent = InputEvent.None;
            keyboardHandler   = new KeyboardHandler(currentGame);

            intermediary.ConnectToServer(serverEndpoint);
        }