Example #1
0
        private void setupNames()
        {
            while (true)
            {
                if (socketManagement.getConnectionType() == SocketManagement.SERVER)
                {
                    myTurn        = true;
                    playModel     = new Human(1, -1);
                    lbluser1.Text = me + " - X";
                    socketManagement.sendMessage(me);
                    while (true)
                    {
                        String name = socketManagement.getMessage();
                        name = name.Replace("\0", String.Empty);
                        if (Regex.Matches(name, "[a-zA-Z]").Count > 2)
                        {
                            //Then the name arrived.
                            opponent      = name;
                            lbluser2.Text = (opponent + " - O");
                            break;
                        }
                    }
                    break;
                }
                else if (socketManagement.getConnectionType() == SocketManagement.CLIENT)
                {
                    myTurn            = false;
                    playModel         = new Human(-1, 1);
                    lbluser1.Text     = me + " - O";
                    lblReplay.Visible = false;

                    while (true)
                    {
                        String name = socketManagement.getMessage();
                        name = name.Replace("\0", String.Empty);
                        if (Regex.Matches(name, "[a-zA-Z]").Count > 2)
                        {
                            //Then the name arrived.
                            opponent      = name;
                            lbluser2.Text = name + " - X";
                            socketManagement.sendMessage(me);
                            break;
                        }
                    }
                    break;
                }
            }
            //lbluser2.Text = opponent;
        }
Example #2
0
        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();

            }
        }
Example #3
0
        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();
            }
        }