Example #1
0
        public void EstablishConnection()
        {
            ConnectionForm        InitForm1;
            WaitForConnectionForm InitForm2;
            ActionForm            InitForm3;
            JoinCreateForm        InitForm4;

init:
            InitForm1 = new ConnectionForm();
            InitForm1.ShowDialog();

            try
            {
                Connection = new Connector(InitForm1.Host);
                Connection.Socket.MessageReceived += delegate(object sender, MessageReceivedEventArgs e) { HandleMessageWrapper(e); };
            }
            catch (ArgumentException)
            {
                goto init;
            }

            InitForm2 = new WaitForConnectionForm(Connection);
            InitForm2.ShowDialog();

            if (Connection.Socket.State != WebSocketState.Open)
            {
                goto init;
            }

startgame:
            InitForm3 = new ActionForm();
            InitForm3.ShowDialog();
            if (InitForm3.Action == "")
            {
                goto startgame;
            }
            if (InitForm3.Action == "join")
            {
                Connection.GameID = InitForm3.GameID;
            }

            InitForm4 = new JoinCreateForm(Connection, InitForm3.Action);
            InitForm4.ShowDialog();
            if (InitForm4.myIDs.Length == 0)
            {
                goto startgame;
            }

            Connection.ClientIDs = InitForm4.myIDs;
            Players = new Player[InitForm4.PlayerNames.Length];
            for (int i = 0; i < InitForm4.PlayerNames.Length; i++)
            {
                if (InitForm4.PlayerNames[i] == null)                 //DEBUG??
                {
                    InitForm4.PlayerNames[i] = "Player" + i.ToString();
                }
                Players[i] = new Player(i, InitForm4.PlayerNames[i]);
            }
        }
Example #2
0
        public void EstablishConnection()
        {
            ConnectionForm InitForm1;
            WaitForConnectionForm InitForm2;
            ActionForm InitForm3;
            JoinCreateForm InitForm4;
            init:
            InitForm1 = new ConnectionForm();
            InitForm1.ShowDialog();

            try
            {
                Connection = new Connector(InitForm1.Host);
                Connection.Socket.MessageReceived += delegate (object sender, MessageReceivedEventArgs e) {HandleMessageWrapper(e);};
            }
            catch (ArgumentException)
            {
                goto init;
            }

            InitForm2 = new WaitForConnectionForm(Connection);
            InitForm2.ShowDialog();

            if (Connection.Socket.State != WebSocketState.Open)
                goto init;

            startgame:
            InitForm3 = new ActionForm();
            InitForm3.ShowDialog();
            if (InitForm3.Action == "")
                goto startgame;
            if (InitForm3.Action == "join")
                Connection.GameID = InitForm3.GameID;

            InitForm4 = new JoinCreateForm(Connection, InitForm3.Action);
            InitForm4.ShowDialog();
            if (InitForm4.myIDs.Length == 0)
                goto startgame;

            Connection.ClientIDs = InitForm4.myIDs;
            Players = new Player[InitForm4.PlayerNames.Length];
            for (int i = 0; i<InitForm4.PlayerNames.Length; i++)
            {
                if (InitForm4.PlayerNames[i] == null) //DEBUG??
                    InitForm4.PlayerNames[i] = "Player"+i.ToString();
                Players[i] = new Player(i, InitForm4.PlayerNames[i]);
            }
        }