private void OkButtonClick(object sender, EventArgs e)
        {
            // Check the length of the name.
            if (nameTextBox.Text.Length >= 3 && nameTextBox.Text.Length <= 12 && passwordTextBox.Text.Length >= 3 &&
                passwordTextBox.Text.Length <= 12)
            {
                // Set player's name and password.
                if (Game.playerSwitch)
                {
                    Game.player1.Name     = nameTextBox.Text;
                    Game.player1.Password = passwordTextBox.Text;
                }
                else
                {
                    Game.player2.Name     = nameTextBox.Text;
                    Game.player2.Password = passwordTextBox.Text;
                }

                ShipDeploymentForm shipDeploymentForm = new ShipDeploymentForm();
                shipDeploymentForm.Location = Location;
                shipDeploymentForm.Show();

                // Dispose does not trigger FormClosing event.
                Dispose();
            }
            else
            {
                // Show a warning message box.
                MessageBox.Show("Your name and password must be from 3 to 12 characters long, try again please.", "Battleships: Try another name or password!");
                nameTextBox.Text = "";
            }
        }
示例#2
0
        private void buttonHard_Click(object sender, EventArgs e)
        {
            Game.Initialize();
            Game.AICleverness = 10;
            // Initialize players.
            Game.player1 = new Player();
            Game.player2 = new Player();

            ShipDeploymentForm shipDeploymentForm = new ShipDeploymentForm();

            shipDeploymentForm.Location = Location;
            shipDeploymentForm.Show();

            Hide();
        }
        private void OkButtonClick(object sender, EventArgs e)
        {
            // Check the length of the name.
            if (nameTextBox.Text.Length >= 3 && nameTextBox.Text.Length <= 12)
            {
                // Set player's name.
                Game.player1.Name = nameTextBox.Text;
                // Other player's name is assigned automatically.
                Game.player2.Name = "Computer";

                ShipDeploymentForm shipDeploymentForm = new ShipDeploymentForm();
                shipDeploymentForm.Location = Location;
                shipDeploymentForm.Show();

                // Dispose does not trigger FormClosing event.
                Dispose();
            }
            else
            {
                // Show a warning message box.
                MessageBox.Show("Your name must be from 3 to 12 characters long, try again please.", "Battleships: Try another name!");
                nameTextBox.Text = "";
            }
        }