Пример #1
0
        private void Form1_Shown(object sender, EventArgs e)
        {
            txbIP.Text = sck.GetLocalIPv4(NetworkInterfaceType.Wireless80211);

            if (string.IsNullOrEmpty(txbIP.Text))
            {
                txbIP.Text = sck.GetLocalIPv4(NetworkInterfaceType.Ethernet);
            }
            sck = null;
        }
Пример #2
0
        private void Connect()
        {
            if (sck != null)
            {
                sck.Close();
            }
            sck                 = new SocketMangaer();
            sck.IP              = txbIP.Text;
            sck.PORT            = (int)txtPort.Value;
            this.statusBar.Text = "processing....";
            Thread thread = new Thread(() =>
            {
                btnLan.Enabled       = false;
                btnDiconnect.Enabled = true;
                if (!sck.ConnectServer())
                {
                    bool kq = true;
                    sck.CreateServer(out kq);

                    if (kq == true)
                    {
                        if (!otherPlayQuit)
                        {
                            this.statusBar.Text = "you are server";
                        }
                        else
                        {
                            this.statusBar.Text = "other player is quit ";
                        }
                        this.FirstPlay = true;
                        otherPlayQuit  = false;


                        Thread listenThread = new Thread(() =>
                        {
                            while (true)
                            {
                                try
                                {
                                    SocketData data = (SocketData)sck.ReceiveData();
                                    ProcessData(data);

                                    if (btnServerFirst.Checked)
                                    {
                                        sck.SendData(new SocketData((int)SocketCommand.FIRSTPLAY, "1", null));

                                        this.FirstPlay = true;
                                    }
                                    else
                                    {
                                        sck.SendData(new SocketData((int)SocketCommand.FIRSTPLAY, "2", null));

                                        this.FirstPlay = false;
                                    }
                                    break;
                                }
                                catch
                                {
                                }
                            }
                        });
                        listenThread.IsBackground = true;
                        listenThread.Start();
                    }
                    else
                    {
                        this.statusBar.Text = "cant connect pls check your port";
                    }
                }
                else
                {
                    this.Invoke(new control(clientUI));
                    Listen();

                    sck.SendData(new SocketData((int)SocketCommand.PLAYER_NAME, txbPlayerName.Text, null));
                }
            });

            thread.IsBackground = true;
            thread.Start();
        }
Пример #3
0
        public Form1()
        {
            using (StreamWriter sw = new StreamWriter("E:\\test.txt", true))
            {
                sw.Flush();

                sw.Close();
            }

            Control.CheckForIllegalCrossThreadCalls = false;

            using (Form form = new Form())
            {
                form.StartPosition = FormStartPosition.CenterScreen;
                form.Text          = "Login";
                TextBox text1 = new TextBox();

                text1.Width    = 200;
                text1.Location = new Point(form.Width / 2 - text1.Size.Width / 2, form.Height / 2 - text1.Size.Height / 2 - 50);

                Label label2 = new Label();
                label2.Text     = "WELCOME TO CARO GAME \n \n please enter player name";
                label2.Width    = 200;
                label2.Height   = 100;
                label2.Location = new Point(text1.Location.X, text1.Location.Y - 70);

                Button acceptBtn = new Button();
                acceptBtn.Text = "Accept";

                acceptBtn.Location = new Point(text1.Location.X, text1.Location.Y + 50);

                acceptBtn.Click += (o, e) =>
                {
                    if (string.IsNullOrEmpty(text1.Text))
                    {
                        MessageBox.Show("pls enter ur name", "player name is empty", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        form.Close();
                    }
                };
                // form.Controls.Add(...);
                form.Controls.Add(text1);

                form.Controls.Add(label2);

                form.Controls.Add(acceptBtn);

                form.FormClosing += (o, e) =>
                {
                    playerName = text1.Text;
                };

                form.ShowDialog();
            }



            if (string.IsNullOrEmpty(playerName))
            {
                Environment.Exit(1);
            }

            InitializeComponent();

            ChatBoard.Multiline  = true;
            ChatBoard.ScrollBars = RichTextBoxScrollBars.Both;

            sck = new SocketMangaer();

            txbPlayerName.Text = playerName;
            chessBroad         = new chessBroadManager(panelChessBroad, txbPlayerName, ptcMark);

            chessBroad.PlayerMarked += ChessBroad_PlayerMarked;
            chessBroad.EndedGame    += ChessBroad_EndedGame;
            chessBroad.WonGame      += ChessBroad_WonGame;

            pcbCoolDown.Step    = constant.coolDownStep;
            pcbCoolDown.Maximum = constant.coolDownTime;
            pcbCoolDown.Value   = 0;

            timerCoolDown.Interval = constant.coolDownInterver;
            chessBroad.DrawChessBroad();

            panelChessBroad.Enabled = false;
            btnReady.Visible        = false;
            btnPause.Enabled        = false;
        }