Пример #1
0
        /// <summary>
        /// This method will connect to the game server when the connect button is clicked
        /// There are flags so that user cannot have empty name or server name
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void connectButton_Click(object sender, EventArgs e)
        {
            //Make sure user enters a name
            if (playerName.Text == "")
            {
                DisplayErrorMessage("Please enter player name");
                return;
            }

            //Make sure server name is entered
            if (hostText.Text == "")
            {
                DisplayErrorMessage("Please enter server name");
                return;
            }

            //disable buttons after connecting
            playerName.Enabled    = false;
            connectButton.Enabled = false;
            IPName.Enabled        = false;
            //Enable the global form to capture key presses
            KeyPreview = true;

            //Connect with Server
            theController.Connect(IPName.Text, playerName.Text);
        }
Пример #2
0
        private void connectButton_Click(object sender, EventArgs e)
        {
            if (serverTextbox.Text == "")
            {
                MessageBox.Show("Please enter a server address");
                return;
            }

            if (nameTextbox.Text == "")
            {
                MessageBox.Show("Please enter a player name");
                return;
            }

            if (nameTextbox.Text.Length > 16)
            {
                MessageBox.Show("Player name should be less than 16 characters");
                return;
            }

            // Disable the controls and try to connect
            connectButton.Enabled = false;
            serverTextbox.Enabled = false;
            nameTextbox.Enabled   = false;

            controller.Connect(serverTextbox.Text, nameTextbox.Text);
        }
Пример #3
0
        private void ConnectButton_Click(object sender, EventArgs e)
        {
            //If the server box is empty, then it asks the user to enter a valid server address
            if (serverTextBox.Text == "")
            {
                MessageBox.Show("Please enter a Server Address");
                return;
            }

            //If the name box is empty, then it asks the user to enter a valid name
            if (nameBox.Text == "")
            {
                MessageBox.Show("Please enter a name");
                return;
            }

            // Disables the controls and try to connect
            connectButton.Enabled = false;
            serverTextBox.Enabled = false;
            nameBox.Enabled       = false;

            //Sets keyPreview to true in order for the user
            KeyPreview = true;

            //Calls the controller's connect method
            controller.Connect(serverTextBox.Text, nameBox.Text);
        }
Пример #4
0
        /// <summary>
        /// When we try to connect, we first check our player name,
        /// Then disable buttons to try and connect.  If the connection fails
        /// we enable the buttons to try and reconnect. Player name
        /// must be nonempty and at least 16 characters.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ConnectButton_Click(object sender, EventArgs e)
        {
            if (NameTextBox.Text.Length == 0 || NameTextBox.Text.Length > 16)
            {
                MessageBox.Show("Player Name Cannot Exceed 16 Characters Or Be Empty");
                return;
            }

            // Disable controls to try to connect to Server
            ConnectButton.Enabled = false;
            NameTextBox.Enabled   = false;
            ServerTextBox.Enabled = false;

            // Try to connect to Server
            try
            {
                theController.Connect(ServerTextBox.Text, NameTextBox.Text);
                ConnectButton.Text = "Connected!";
            }

            // Couldn't connect
            catch
            {
                MessageBox.Show("Connecting to server failed.");
                ConnectButton.Enabled = true;
                NameTextBox.Enabled   = true;
                ServerTextBox.Enabled = true;

                return;
            }
        }
Пример #5
0
 /// <summary>
 /// Called when Start is clicked. Disables form components and calls controller's connect method
 /// </summary>
 private void StartClick(object sender, EventArgs e)
 {
     //If host and name are nonempty
     if (hostText.TextLength > 0 && nameText.TextLength > 0)
     {
         // Disable the form controls
         startButton.Enabled = false;
         startButton.TabStop = false;
         nameText.Enabled    = false;
         hostText.Enabled    = false;
         //Set focus to drawing panel
         this.Focus();
         // "connect" to the "server"
         controller.Connect(hostText.Text, nameText.Text);
     }
 }
Пример #6
0
        /// <summary>
        /// Method for handling when clicking Connect button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ConnectBtn_Click(object sender, EventArgs e)
        {
            // if the ipaddress is empty, ask users to enter it
            if (ipAddrText.Text == "")
            {
                MessageBox.Show("Please enter a server address");
                return;
            }
            if (playerNameBox.Text == "")
            {
                MessageBox.Show("Please enter your name");
                return;
            }
            // disable the textboxes and the button after connected
            ipAddrText.Enabled    = false;
            playerNameBox.Enabled = false;
            connectBtn.Enabled    = false;
            drawingPanel.Focus();

            // get controller connect to the server
            theController.Connect(ipAddrText.Text, playerNameBox.Text);
        }