コード例 #1
0
ファイル: IPAddressForm.cs プロジェクト: IMS94/Tic-Tac-Toe
        /*
         * To connect as the client
         */
        private void clientButton_Click(object sender, EventArgs e)
        {
            if (!verifyIPAddress(connectIpBox.Text))
            {
                System.Windows.Forms.MessageBox.Show("Entered IP Adress is not valid !");
                return;
            }

            if(nameBox.Text.Length<2){
                System.Windows.Forms.MessageBox.Show("Please enter a valid name !");
                return;
            }

            //start host.
            Console.WriteLine("Connected!");
            SocketManagement sm = new SocketManagement(connectIpBox.Text, 8000);
            bool hasStarted = sm.startAsClient();

            if (hasStarted) {
                waitLabel.Visible = true;
                hostButton.Enabled = false;
                clientButton.Enabled = false;

                 // Then open the playing window and assign names and signs.

                NetworkPlayForm networkForm = new NetworkPlayForm(setting,sm,nameBox.Text);
                networkForm.Visible = true;
                this.Visible = false;

            }
        }
コード例 #2
0
        /*
         * To connect as the client
         */
        private void clientButton_Click(object sender, EventArgs e)
        {
            if (!verifyIPAddress(connectIpBox.Text))
            {
                System.Windows.Forms.MessageBox.Show("Entered IP Adress is not valid !");
                return;
            }

            if (nameBox.Text.Length < 2)
            {
                System.Windows.Forms.MessageBox.Show("Please enter a valid name !");
                return;
            }

            //start host.
            Console.WriteLine("Connected!");
            SocketManagement sm         = new SocketManagement(connectIpBox.Text, 8000);
            bool             hasStarted = sm.startAsClient();

            if (hasStarted)
            {
                waitLabel.Visible    = true;
                hostButton.Enabled   = false;
                clientButton.Enabled = false;

                // Then open the playing window and assign names and signs.


                NetworkPlayForm networkForm = new NetworkPlayForm(setting, sm, nameBox.Text);
                networkForm.Visible = true;
                this.Visible        = false;
            }
        }
コード例 #3
0
ファイル: NetworkPlayForm.cs プロジェクト: IMS94/Tic-Tac-Toe
        public NetworkPlayForm(Setting settingE,SocketManagement socketManagement,String me)
        {
            InitializeComponent();
            this.me = me;
            this.socketManagement = socketManagement;
            lbluser1.Text = me;
            grid = new int[3, 3];
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    grid[i, j] = 0;
                }
            }

            setting = settingE;

            myTurn = true;
            setupNames();   //set the names of the users.
            refreshVal();
            lblReplay.Visible = false;

            if(!myTurn){
                threadMain = new Thread(() =>
                {
                    refreshVal();
                    //grid = socketManagement.getBoard();
                    String message = socketManagement.getMessage();
                    message = message.Replace("\0", String.Empty);
                    if (String.Compare(message, "-1") == 0)
                    {
                        //then replay
                        replay();
                        return;
                    }
                    else
                    {
                        grid = getBoard(message);
                    }
                    myTurn = true;
                    refreshVal();

                });
                threadMain.Start();

            }
        }
コード例 #4
0
ファイル: NetworkPlayForm.cs プロジェクト: IMS94/Tic-Tac-Toe
        public NetworkPlayForm(Setting settingE, SocketManagement socketManagement, String me)
        {
            InitializeComponent();
            this.me = me;
            this.socketManagement = socketManagement;
            lbluser1.Text         = me;
            grid = new int[3, 3];
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    grid[i, j] = 0;
                }
            }

            setting = settingE;

            myTurn = true;
            setupNames();   //set the names of the users.
            refreshVal();
            lblReplay.Visible = false;

            if (!myTurn)
            {
                threadMain = new Thread(() =>
                {
                    refreshVal();
                    //grid = socketManagement.getBoard();
                    String message = socketManagement.getMessage();
                    message        = message.Replace("\0", String.Empty);
                    if (String.Compare(message, "-1") == 0)
                    {
                        //then replay
                        replay();
                        return;
                    }
                    else
                    {
                        grid = getBoard(message);
                    }
                    myTurn = true;
                    refreshVal();
                });
                threadMain.Start();
            }
        }
コード例 #5
0
        private void hostButton_Click(object sender, EventArgs e)
        {
            if (nameBox.Text.Length < 2)
            {
                System.Windows.Forms.MessageBox.Show("Please enter a valid name !");
                return;
            }

            if (ipListBox.SelectedItem == null)
            {
                System.Windows.Forms.MessageBox.Show("Please select an IP Address !");
                return;
            }
            String ip = ipListBox.SelectedItem.ToString();

            if (!verifyIPAddress(ip))
            {
                System.Windows.Forms.MessageBox.Show("Entered IP Adress is not valid !");
                return;
            }

            Console.WriteLine("Hosted!");
            SocketManagement sm         = new SocketManagement(ip, 8000);
            bool             hasStarted = sm.startAsServer();

            if (hasStarted)
            {
                waitLabel.Visible    = true;
                hostButton.Enabled   = false;
                clientButton.Enabled = false;

                NetworkPlayForm networkForm = new NetworkPlayForm(setting, sm, nameBox.Text);
                networkForm.Visible = true;
                this.Visible        = false;
            }
        }
コード例 #6
0
ファイル: IPAddressForm.cs プロジェクト: IMS94/Tic-Tac-Toe
        private void hostButton_Click(object sender, EventArgs e)
        {
            if (nameBox.Text.Length < 2)
            {
                System.Windows.Forms.MessageBox.Show("Please enter a valid name !");
                return;
            }

            if (ipListBox.SelectedItem==null)
            {
                System.Windows.Forms.MessageBox.Show("Please select an IP Address !");
                return;
            }
            String ip=ipListBox.SelectedItem.ToString();

            if (!verifyIPAddress(ip))
            {
                System.Windows.Forms.MessageBox.Show("Entered IP Adress is not valid !");
                return;
            }

            Console.WriteLine("Hosted!");
            SocketManagement sm = new SocketManagement(ip, 8000);
            bool hasStarted = sm.startAsServer();

            if(hasStarted){
                waitLabel.Visible = true;
                hostButton.Enabled = false;
                clientButton.Enabled = false;

                NetworkPlayForm networkForm = new NetworkPlayForm(setting,sm,nameBox.Text);
                networkForm.Visible = true;
                this.Visible = false;
            }
        }