Exemple #1
0
 private void Ohno_FormClosing(object sender, FormClosingEventArgs e)
 {
     for (int i = 0; i < 4; i++)
     {
         Ohno connectForm = new Ohno
         {
             StartPosition = FormStartPosition.Manual,
             Location      = this.Location
         };
         connectForm.Show();
     }
 }
Exemple #2
0
        public Client(string username, string ip)
        {
            this.username = username;
            this.ip       = ip;
            Label waiting = new Label
            {
                Text     = "Waiting for the game to start...\nConnected players:",
                Font     = new Font("Arial", 24),
                Location = new Point(20, 20),
                Size     = new Size(500, 75)
            };

            Controls.Add(waiting);
            Label you = new Label
            {
                Text      = "YOU - " + username,
                ForeColor = Color.Red,
                Font      = new Font("Arial", 20),
                Location  = new Point(20, 100),
                Size      = new Size(500, 35)
            };

            Controls.Add(you);

            connectedPlayers = new Label
            {
                Font     = new Font("Arial", 16),
                Location = new Point(20, 140),
                Size     = new Size(500, 600)
            };
            Controls.Add(connectedPlayers);

            try
            {
                client = new TcpClient(ip, One_Night_Ultimate_Werewolf.Menu.port);
            }
            catch
            {
                DialogResult response = MessageBox.Show("Invalid IP", "Error", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Error);
                if (response.ToString() == "No")
                {
                    DialogResult response2 = MessageBox.Show("The IP is invalid, don't no me.", "What do you mean no?", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Exclamation);
                    if (response2.ToString() == "Ignore")
                    {
                        Ohno OhnoForm = new Ohno
                        {
                            StartPosition = FormStartPosition.Manual,
                            Location      = this.Location
                        };
                        this.Hide();
                        this.WindowState   = FormWindowState.Minimized;
                        this.ShowInTaskbar = false;
                        Controls.Clear();
                        OhnoForm.Show();
                        return;
                    }
                }

                Connect connectForm = new Connect
                {
                    StartPosition = FormStartPosition.Manual,
                    Location      = this.Location,
                    Size          = new Size(500, 500),
                    Text          = One_Night_Ultimate_Werewolf.Menu.game + " - Connect to server"
                };
                connectForm.FormClosing += One_Night_Ultimate_Werewolf.Menu.OnClose;
                this.Hide();
                this.WindowState   = FormWindowState.Minimized;
                this.ShowInTaskbar = false;
                Controls.Clear();
                connectForm.Show();
                return;
            }
            stream = client.GetStream();
            WriteString(username);

            string str = ReadString(1024);

            str     = str.Substring(1);
            players = str == "" ? new List <string>() : str.Split('\0').ToList <string>();
            for (int i = 0; i < players.Count; i++)
            {
                Host.AddText(connectedPlayers, players[i]);
            }

            Thread waitUntilGameStarts = new Thread(WaitUntilGameStarts);

            waitUntilGameStarts.Start();
        }