public Insert_Ships(string IPConection, int porta, bool serverSide) { InitializeComponent(); setPort(porta); comboBoxConection.SelectedIndex = 0; foreach (string LocalIP in TCPIP.GetLocalIPAddress()) { comboBox_LocalIPs.Items.Add(LocalIP); } if (serverSide) { for (int x = 0; x < comboBox_LocalIPs.Items.Count; x++) { if (IPConection == comboBox_LocalIPs.Items[x].ToString()) { comboBox_LocalIPs.SelectedIndex = x; } } } else { radioBtnClient.Checked = true; mskTxt_HostIP.Text = IPConection; } createShips(); }
private void btn_RefreshIPs_Click(object sender, EventArgs e) { comboBox_LocalIPs.Items.Clear(); foreach (string IP in TCPIP.GetLocalIPAddress()) { comboBox_LocalIPs.Items.Add(IP); } comboBox_LocalIPs.SelectedIndex = 0; }
private void btn_Play_Click(object sender, EventArgs e) { try { if (radioBtnClient.Checked) { if (!mskTxt_HostIP.MaskCompleted) { MessageBox.Show("IP inválido!", "ERRO", MessageBoxButtons.OK, MessageBoxIcon.Error); mskTxt_HostIP.Focus(); } else { protocol = new TCPIP(getIP(), getPort(), this, isServer); protocol.client.Connect(); } } else { protocol = new TCPIP(getIP(), getPort(), this, isServer); } } catch (OverflowException) { MessageBox.Show("IP inválido!", "ERRO", MessageBoxButtons.OK, MessageBoxIcon.Error); mskTxt_HostIP.Focus(); } catch (TimeoutException) { MessageBox.Show("Host não encontrado na rede", "Erro de conexão", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (SocketException) { string message = "Host já estabelecido"; if (radioBtnClient.Checked) { message = "Host não estabelecido ainda"; } MessageBox.Show(message, "Erro de conexão", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().FullName, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public Insert_Ships() { InitializeComponent(); comboBoxConection.SelectedIndex = 0; foreach (string IP in TCPIP.GetLocalIPAddress()) { comboBox_LocalIPs.Items.Add(IP); } comboBox_LocalIPs.SelectedIndex = 0; tabuleiro = new Tabuleiro(10, 10); tabuleiro.setMineFields(this); createShips(); }
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); } }