Example #1
0
        private void _menu_createServer_Click(object sender, EventArgs e)
        {
            if (new CreateForm(this).ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
            {
                player = Players.Player1;
                playerNames.Player1Name = playerName;
                playerNames.Player2Name = "Player2";
                playerNames.Player3Name = "Player3";
                playerNames.Player4Name = "Player4";
                informations.Connected = 1;
                informations.PlayersTurn = Players.None;
                informations.Player1Points = informations.Player2Points = informations.Player3Points = informations.Player4Points = 0;
                appType = Minefield_Online.appType.Server;
                SetupSettingsDisplay();

                _menu_createServer.Enabled = _menu_connect.Enabled = false;

                this.Text += " [Server running at port " +settings.ServerPort + "]";

                server = new TcpListener(IPAddress.Any, (int)settings.ServerPort);
                serverThread = new Thread(new ThreadStart(LiseningForClient));
                serverThread.Start();
                EnableChat();
                DrawMinefield();
            }
        }
Example #2
0
        private void _menu_connect_Click(object sender, EventArgs e)
        {
            if (new ConnectForm(this).ShowDialog(this) == System.Windows.Forms.DialogResult.OK) {
                client = new TcpClient();
                try {
                    client.Connect(serverAddress, (int)serverPort);
                } catch (Exception ex) {
                    MessageBox.Show("Cannot connect to server \n" + ex.Message);
                    return;
                }
                _menu_createServer.Enabled = _menu_connect.Enabled = false;

                appType = Minefield_Online.appType.Client;
                clientThread = new Thread(new ThreadStart(ListeningClient));
                clientThread.Start();
                EnableChat();
            }
        }