public void btn_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                if (vertical)
                {
                    vertical = false;
                }
                else
                {
                    vertical = true;
                }
            }

            Button btn    = (Button)sender;
            int    number = int.Parse(btn.Name.Substring(btn.Name.IndexOf("_") + 1));

            int[]     Positions = tabuleiro.getMineFieldPosition(number);
            MineField mine      = tabuleiro.getMineFields()[Positions[0], Positions[1]];

            if (mine.isShip())
            {
                string data = mine.getShipName().ToString() + ";";
                data += Positions[0].ToString() + ";" + Positions[1].ToString();

                this.DoDragDrop(data, DragDropEffects.Copy);
            }
        }
        public void btn_Mina_Click(object sender, EventArgs e)
        {
            if (yourTurn)
            {
                Button    btn        = (Button)sender;
                int       Position   = int.Parse(btn.Name.Substring(btn.Name.IndexOf("n") + 1));
                int[]     cordenates = opponentBoard.getMineFieldPosition(Position);
                MineField mine       = opponentBoard.getMineFields()[cordenates[0], cordenates[1]];

                if (!mine.getJogada())
                {
                    mine.setJogada(opponentBoard);
                    if (opponentBoard.getQtdAcertos() == qtdAcertos)
                    {
                        youWin();
                    }

                    string message = cordenates[0].ToString() + ";" +
                                     cordenates[1].ToString() + ";";

                    protocol.sendMessage(clientIP, message);

                    // Se o tiro acertou a água, passa a vez para o adversário
                    if (!mine.isShip())
                    {
                        yourTurn      = false;
                        lbl_Turn.Text = "Espere a jogada do jogador adversário...";
                    }
                }
            }
        }
        public PartidaForm(TCPIP protocol, string ClientIP, Tabuleiro myBoard)
        {
            InitializeComponent();

            clientIP      = ClientIP;
            this.protocol = protocol;
            this.myBoard  = new Tabuleiro(10, 10);

            if (clientIP != null)   // first player is server side
            {
                yourTurn      = true;
                lbl_Turn.Text = "Sua vez";
            }

            try {
                protocol.setEventsForm2(this);

                this.myBoard.setMineFields(this, false);

                opponentBoard = new Tabuleiro(10, 10);
                opponentBoard.setMineFields(this, true);

                string message = ""; // loop para envio dos navios escolhidos
                for (int y = 0; y < myBoard.getNumberRows(); y++)
                {
                    for (int x = 0; x < myBoard.getNumberColumns(); x++)
                    {
                        MineField mine = myBoard.getMineFields()[y, x];

                        if (mine.isShip())
                        {
                            message += mine.getShipName().ToString();

                            this.myBoard.getMineFields()[y, x].setShip(true, mine.getShip(), mine.isVertical());

                            qtdAcertos++;
                        }
                        else
                        {
                            message += "0";
                        }
                    }
                }

                protocol.sendMessage(clientIP, message);

                if (clientIP == null)
                {
                    MessageBox.Show("Conexão feita com o host.", "Conexão",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("Conexão feita com sucesso. Você é o host", "Conexão",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            } catch (Exception ex) {
                MessageBox.Show(ex.Message, ex.GetType().Name,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }