示例#1
0
文件: Form1.cs 项目: bigbanggk01/Tank
        /// <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);
                }
            }
        }
示例#2
0
        public void Execute(object _currentData)
        {
            string s = _currentData as string;

            int[] b = s.Split(';').Select(int.Parse).ToArray();
            if (b[0] == 7)
            {
                networker.Send("8;" + _player[0].x[0].ToString() + ";" + _player[0].y[0].ToString()
                               + ";" + _player[0].Tank_Current_Status.ToString() + ";" + _player.IndexOf(_player[0]));
            }
            if (b[1] == 0)
            {
                if (b[0] == 0)
                {
                    _player[b[2]] = tank;
                    if (b[2] != 2)
                    {
                        _player[2] = null;
                    }
                }

                if (b[0] == 6)
                {
                    Tank otherTank = new Tank();
                    Draw_Tank(otherTank);

                    foreach (Tank item in _player)
                    {
                        if (item == null)
                        {
                            _player[_player.IndexOf(item)] = otherTank;
                            return;
                        }
                    }
                }
                if (b[0] == 1)
                {
                    _player[0].Go_Up(this, map);
                }
                if (b[0] == 2)
                {
                    _player[0].Go_Down(this, map);
                }
                if (b[0] == 3)
                {
                    _player[0].Go_Left(this, map);
                }
                if (b[0] == 4)
                {
                    _player[0].Go_Right(this, map);
                }
                if (b[0] == 5)
                {
                    this.Invoke((MethodInvoker) delegate
                    {
                        _player[0].Shot(this);
                        Bullet bull = new Bullet(_player[0], this);
                        bull.X_Map(map);
                        map.Wall_damged(bull);
                        bull.fly(this);
                    });
                }
            }
            if (b[1] == 1)
            {
                if (b[0] == 0)
                {
                    _player[b[2]] = tank;
                    _player[2]    = null;
                }
                if (b[0] == 6)
                {
                    Tank otherTank = new Tank();
                    Draw_Tank(otherTank);
                    foreach (Tank item in _player)
                    {
                        if (item == null)
                        {
                            _player.Add(otherTank);
                            return;
                        }
                    }
                }
                if (b[0] == 1)
                {
                    _player[1].Go_Up(this, map);
                }
                if (b[0] == 2)
                {
                    _player[1].Go_Down(this, map);
                }
                if (b[0] == 3)
                {
                    _player[1].Go_Left(this, map);
                }
                if (b[0] == 4)
                {
                    _player[1].Go_Right(this, map);
                }
                if (b[0] == 5)
                {
                    this.Invoke((MethodInvoker) delegate
                    {
                        _player[1].Shot(this);
                        Bullet bull = new Bullet(_player[1], this);
                        bull.X_Map(map);
                        map.Wall_damged(bull);
                        bull.fly(this);
                    });
                }
                if (b[0] == 8)
                {
                    _player[0]      = new Tank();
                    _player[0].x[0] = b[2];
                    _player[0].y[0] = b[3];
                    if (b[4] == 1)
                    {
                        _player[0].Tank_Current_Status = 1;
                        _player[0].x[1] = b[2] - 1;
                        _player[0].y[1] = b[3] + 1;
                        _player[0].x[2] = b[2];
                        _player[0].y[2] = b[3] + 1;
                        _player[0].x[3] = b[2] + 1;
                        _player[0].y[3] = b[3] + 1;
                        _player[0].x[4] = b[2] - 1;
                        _player[0].y[4] = b[3] + 2;
                        _player[0].x[5] = b[2] + 1;
                        _player[0].y[5] = b[3] + 2;
                    }
                    if (b[4] == 2)
                    {
                        _player[0].Tank_Current_Status = 2;
                        _player[0].x[1] = b[2] + 1;
                        _player[0].y[1] = b[3] - 1;
                        _player[0].x[2] = b[2];
                        _player[0].y[2] = b[3] - 1;
                        _player[0].x[3] = b[2] - 1;
                        _player[0].y[3] = b[3] - 1;
                        _player[0].x[4] = b[2] + 1;
                        _player[0].y[4] = b[3] - 2;
                        _player[0].x[5] = b[2] - 1;
                        _player[0].y[5] = b[3] - 2;
                    }
                    if (b[4] == 3)
                    {
                        _player[0].Tank_Current_Status = 3;
                        _player[0].x[1] = b[2] + 1;
                        _player[0].y[1] = b[3] + 1;
                        _player[0].x[2] = b[2] + 1;
                        _player[0].y[2] = b[3];
                        _player[0].x[3] = b[2] + 1;
                        _player[0].y[3] = b[3] - 1;
                        _player[0].x[4] = b[2] + 2;
                        _player[0].y[4] = b[3] + 1;
                        _player[0].x[5] = b[2] + 2;
                        _player[0].y[5] = b[3] - 1;
                    }
                    if (b[4] == 4)
                    {
                        _player[0].Tank_Current_Status = 4;
                        _player[0].x[1] = b[2] - 1;
                        _player[0].y[1] = b[3] - 1;
                        _player[0].x[2] = b[2] - 1;
                        _player[0].y[2] = b[3];
                        _player[0].x[3] = b[2] - 1;
                        _player[0].y[3] = b[3] + 1;
                        _player[0].x[4] = b[2] - 2;
                        _player[0].y[4] = b[3] - 1;
                        _player[0].x[5] = b[2] - 2;
                        _player[0].y[5] = b[3] + 1;
                    }
                    Draw_Tank(_player[0]);
                }
            }
        }
示例#3
0
文件: Form1.cs 项目: bigbanggk01/Tank
 /// <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);
             });
         }
     }
 }