Esempio n. 1
0
        /// <summary>
        /// Các nút bấm
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (networker._identification == 0)
            {
                if (e.KeyCode == Keys.Enter)
                {
                    if (textBox1.Visible == true)
                    {
                        textBox1.Hide();
                        button2.Hide();
                        if (textBox1.Text.Equals("") != true)
                        {
                            EventArgs E = new EventArgs();
                            button2_Click(sender, E);
                        }

                        return;
                    }
                    textBox1.Show();
                    button2.Show();
                    textBox1.Focus();
                    textBox1.TabIndex = 1;
                }
                if (networker._client2 == null)
                {
                    return;
                }
                if (e.KeyCode == Keys.Up)
                {
                    tank1.Go_Up(this, map);
                    try { networker.Send("press;1", networker._client2); }
                    catch (Exception D) { MessageBox.Show(D.ToString()); }
                }
                if (e.KeyCode == Keys.Down)
                {
                    tank1.Go_Down(this, map);
                    networker.Send("press;2", networker._client2);
                }
                if (e.KeyCode == Keys.Left)
                {
                    tank1.Go_Left(this, map);
                    networker.Send("press;3", networker._client2);
                }
                if (e.KeyCode == Keys.Right)
                {
                    tank1.Go_Right(this, map);
                    networker.Send("press;4", networker._client2);
                }

                if (e.KeyCode == Keys.Space)
                {
                    tank1.Shot(this);
                    Bullet b = new Bullet(tank1, this);
                    b.GetForm(this);
                    b.fly(this);
                    networker.Send("press;5", networker._client2);
                }
            }
            if (networker._identification == 1)
            {
                if (e.KeyCode == Keys.Enter)
                {
                    if (textBox1.Visible == true)
                    {
                        if (textBox1.Text.Equals("") == true)
                        {
                            return;
                        }
                        EventArgs E = new EventArgs();
                        textBox1.Hide();
                        button2.Hide();
                        button2_Click(sender, E);
                        return;
                    }
                    textBox1.Show();
                    button2.Show();
                    textBox1.Focus();
                    textBox1.TabIndex = 1;
                }
                if (e.KeyCode == Keys.Up)
                {
                    tank2.Go_Up(this, map);
                    networker.Send("press;1", networker._client1);
                }
                if (e.KeyCode == Keys.Down)
                {
                    tank2.Go_Down(this, map);
                    networker.Send("press;2", networker._client1);
                }
                if (e.KeyCode == Keys.Left)
                {
                    tank2.Go_Left(this, map);
                    networker.Send("press;3", networker._client1);
                }
                if (e.KeyCode == Keys.Right)
                {
                    tank2.Go_Right(this, map);
                    networker.Send("press;4", networker._client1);
                }
                if (e.KeyCode == Keys.Space)
                {
                    tank2.Shot(this);
                    Bullet b = new Bullet(tank2, this);
                    b.GetForm(this);
                    b.fly(this);
                    networker.Send("press;5", networker._client1);
                }
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Cập nhật tình trạng xe của đối thủ, hành động của đối thủ
 /// </summary>
 /// <param name="instruction"></param>
 public void Enemy_Control(int instruction)
 {
     if (instruction == 1)
     {
         if (networker._identification == 0)
         {
             tank2.Go_Up(this, map);
         }
         if (networker._identification == 1)
         {
             tank1.Go_Up(this, map);
         }
     }
     if (instruction == 2)
     {
         if (networker._identification == 0)
         {
             tank2.Go_Down(this, map);
         }
         if (networker._identification == 1)
         {
             tank1.Go_Down(this, map);
         }
     }
     if (instruction == 3)
     {
         if (networker._identification == 0)
         {
             tank2.Go_Left(this, map);
         }
         if (networker._identification == 1)
         {
             tank1.Go_Left(this, map);
         }
     }
     if (instruction == 4)
     {
         if (networker._identification == 0)
         {
             tank2.Go_Right(this, map);
         }
         if (networker._identification == 1)
         {
             tank1.Go_Right(this, map);
         }
     }
     if (instruction == 5)
     {
         if (networker._identification == 0)
         {
             this.Invoke((MethodInvoker) delegate {
                 tank2.Shot(this);
                 Bullet b = new Bullet(tank2, this);
                 b.fly(this);
                 b.GetForm(this);
             });
         }
         if (networker._identification == 1)
         {
             this.Invoke((MethodInvoker) delegate {
                 tank1.Shot(this);
                 Bullet b = new Bullet(tank1, this);
                 b.fly(this);
                 b.GetForm(this);
             });
         }
     }
 }