예제 #1
0
파일: Form1.cs 프로젝트: greSvoI/TankOnline
        private void buttonConnect_Click(object sender, EventArgs e)
        {
            this.Text = "Client";
            foreach (Control control in Controls)
            {
                control.Visible = false;
            }

            this.Size = new Size(800, 800);

            try
            {
                if (textBox1.Text == "")
                {
                    machines1 = new Machines();
                    tcpClient = new TcpClient();
                    tcpClient.Connect(iPAddress, 8000);

                    networkStream = tcpClient.GetStream();

                    Thread thread = new Thread(new ThreadStart(GetAction));
                    thread.Start();
                }
                else
                {
                    machines1 = new Machines();

                    tcpClient = new TcpClient();
                    tcpClient.Connect(IPAddress.Parse(textBox1.Text), 8000);

                    networkStream = tcpClient.GetStream();

                    Thread thread = new Thread(new ThreadStart(GetAction));
                    thread.Start();
                }

                machines1.picture.Image = Image.FromFile("red.png");
                this.Controls.Add(machines1.picture);
                machines1.Player.X         = 400;
                machines1.Player.Y         = 700;
                machines1.picture.Location = new Point(machines1.Player.X, machines1.Player.Y);

                machines2 = new Machines();
                machines2.picture.Image = Image.FromFile("green.png");
                this.Controls.Add(machines2.picture);
                machines2.Player.X         = 300;
                machines2.Player.Y         = 700;
                machines2.picture.Location = new Point(machines2.Player.X, machines2.Player.Y);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " buttonConnect");
                this.Close();
            }
        }
예제 #2
0
 public Shells(Machines machines, Keys keys)
 {
 }
예제 #3
0
        //private void Connect()
        //{
        //	tcpListener = new TcpListener(iPAddress, 8000);
        //	tcpListener.Start();
        //	tcpClient = tcpListener.AcceptTcpClient();
        //	networkStream = tcpClient.GetStream();
        //	connect = true;
        //	Thread thread = new Thread(new ThreadStart(GetAction));
        //	thread.Start();
        //}
        private async void buttonWait_Click(object sender, EventArgs e)
        {
            machines1 = new Machines(Brushes.Green);
            machines2 = new Machines(Brushes.Red);

            this.Text = "Server";
            foreach (Control control in Controls)
            {
                if (control is Button || control is TextBox || control is Label)
                {
                    control.Visible = false;
                }
            }

            this.Size = MyPictureBox.Size = new Size(800, 800);
            try
            {
                if (textBox1.Text == "")
                {
                    tcpListener = new TcpListener(iPAddress, 8000);
                    tcpListener.Start();

                    await Task.Run(new Action(() =>
                    {
                        this.tcpClient = tcpListener.AcceptTcpClient();
                        this.networkStream = tcpClient.GetStream();
                    }));
                }
                else
                {
                    tcpListener = new TcpListener(IPAddress.Parse(textBox1.Text), 8000);
                    tcpListener.Start();

                    await Task.Run(new Action(() =>
                    {
                        tcpClient = tcpListener.AcceptTcpClient();
                        networkStream = tcpClient.GetStream();
                    }));
                }
                Thread thread = new Thread(new ThreadStart(GetAction));
                thread.Start();

                machines1.picture.Image     = Image.FromFile("green.png");
                machines1.picture.BackColor = Color.Transparent;
                MyPictureBox.Controls.Add(machines1.picture);

                machines1.Player.X         = 300;
                machines1.Player.Y         = 700;
                machines1.picture.Location = new Point(machines1.Player.X, machines1.Player.Y);

                machines2.picture.Image     = Image.FromFile("red.png");
                machines2.picture.BackColor = Color.Transparent;
                MyPictureBox.Controls.Add(machines2.picture);

                machines2.Player.X         = 400;
                machines2.Player.Y         = 700;
                machines2.picture.Location = new Point(machines2.Player.X, machines2.Player.Y);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " buttonWait");
                this.Close();
            }
        }