public WaitForConnectionForm(Connector c)
        {
            this.StartPosition = FormStartPosition.Manual;
            this.Location = MainForm.StartPos;

            Controls.AddRange(new Control[1] {AbortButton});

            AbortButton.Text = "Abort";

            AbortButton.Location = new Point(10, 10);
            AbortButton.Width = 250;
            AbortButton.Click += delegate
            {
                Close();
            };

            WaitTimer.Interval = 10;
            WaitTimer.Enabled = true;

            WaitTimer.Tick += delegate
            {
                if (c.Socket.State == WebSocketState.Open)
                {
                    this.Close();
                }
            };

            Size = new Size(290,80);
        }
Exemple #2
0
        public JoinCreateForm(Connector c, string action)
        {
            this.StartPosition = FormStartPosition.Manual;
            this.Location = MainForm.StartPos;

            Size = new Size(290,105);

            PleaseCloseForm = false;
            CloseTimer.Interval = 10;
            CloseTimer.Enabled = true;
            CloseTimer.Tick += delegate
            {
                if (PleaseCloseForm)
                {
                    PleaseCloseForm = false;
                    c.Socket.MessageReceived -= Connection_Socket_MessageReceived;
                    Close();
                }
            };

            Connection = c;
            Connection.Socket.MessageReceived += new EventHandler<MessageReceivedEventArgs>(Connection_Socket_MessageReceived);

            Controls.AddRange(new Control[2] {StatLabel, AddPlayerButton});

            StatLabel.Text = "Waiting for registration";
            StatLabel.Location = new Point(10, 10);
            StatLabel.Size = new Size(250,20);

            AddPlayerButton.Text = "Add Player";
            AddPlayerButton.Location = new Point(10,35);
            AddPlayerButton.Click += delegate(object sender, EventArgs e)
            {
                SubInitForm = new AddPlayerForm();
                SubInitForm.ShowDialog();
                PlayerName = (SubInitForm as AddPlayerForm).Playername;

                JsonObject Message = new JsonObject();

                Message.Add("type","join");
                Message.Add("name",PlayerName);
                Connection.Send(Message);

            };

            JsonObject message = new JsonObject();
            if (action == "join")
            {
                AddPlayerButton.Width = 250;
            }
            if (action == "create_new")
            {
                message.Add("type","request_pack_list");
                Connection.Send(message);

                AddPlayerButton.Width = 120;

                Controls.Add(StartButton);
                StartButton.Width = 120;
                StartButton.Location = new Point(140,35);
                StartButton.Text = "Start";
                StartButton.Enabled = false;

                StartButton.Click += delegate(object button, EventArgs e)
                {
                    if (Connection.Socket.State == WebSocketState.Open)
                    {
                        JsonObject Message = new JsonObject();
                        Message.Add("type","start");
                        Connection.Send(Message);
                    }
                };

            }
        }
Exemple #3
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]);
            }
        }
Exemple #4
0
 private void Build()
 {
     this.connector = new Connector(server_TextBox.Text);
     this.menu = new MainMenu();
     this.play = new Play();
 }