Exemple #1
0
        private void Carrier_KeyDown(object sender, KeyEventArgs e)
        {
            //对键盘事件的响应处理
            if (isServer)
            {
                switch (e.Key)
                {
                case Key.Left:
                    if (testMap.isBlockFree(person1.position.Y, person1.position.X - 1))
                    {
                        person1.position.X--;
                        person1.direction = MyPerson.Direction.Left;
                        networkcontrol.AddGameCommand("person;" + 1 + ";" + person1.position.X + ";" + person1.position.Y + ";" + "left");
                        MoveOfPerson(person1);
                    }
                    break;

                case Key.Right:
                    if (testMap.isBlockFree(person1.position.Y, person1.position.X + 1))
                    {
                        person1.position.X++;
                        person1.direction = MyPerson.Direction.Right;
                        networkcontrol.AddGameCommand("person;" + 1 + ";" + person1.position.X + ";" + person1.position.Y + ";" + "right");
                        MoveOfPerson(person1);
                    }
                    break;

                case Key.Up:
                    if (testMap.isBlockFree(person1.position.Y - 1, person1.position.X))
                    {
                        person1.position.Y--;
                        person1.direction = MyPerson.Direction.Up;
                        networkcontrol.AddGameCommand("person;" + 1 + ";" + person1.position.X + ";" + person1.position.Y + ";" + "up");
                        MoveOfPerson(person1);
                    }
                    break;

                case Key.Down:
                    if (testMap.isBlockFree(person1.position.Y + 1, person1.position.X))
                    {
                        person1.position.Y++;
                        person1.direction = MyPerson.Direction.Down;
                        networkcontrol.AddGameCommand("person;" + 1 + ";" + person1.position.X + ";" + person1.position.Y + ";" + "down");
                        MoveOfPerson(person1);
                    }
                    break;

                case Key.Space:
                {
                    if (!testMap.isBombExist(getExactPosition(person1).Y, getExactPosition(person1).X) && person1.mp > 20)
                    {
                        System.Drawing.Point p = getExactPosition(person1);
                        networkcontrol.AddGameCommand("bomb;" + "1;" + p.X + ";" + p.Y + ";" + CurrentSkill);
                        person1.mp -= 20;
                        TypeOfBomb type = TypeOfBomb.normal;
                        switch (CurrentSkill)
                        {
                        case 0:
                            type = TypeOfBomb.normal;
                            break;

                        case 1:
                            type = TypeOfBomb.around_small;
                            break;

                        case 2:
                            type = TypeOfBomb.around_big;
                            break;

                        case 3:
                            type = TypeOfBomb.row;
                            break;

                        case 4:
                            type = TypeOfBomb.column;
                            break;

                        case 5:
                            type = TypeOfBomb.row_column;
                            break;

                        case 6:
                            type = TypeOfBomb.diagonal;
                            break;
                        }
                        SetBomb(p, 3000, type);
                    }
                }
                break;

                case Key.Z:
                    CurrentSkill = 0;
                    Canvas.SetLeft(sm, 60);
                    break;

                case Key.X:
                    CurrentSkill = 1;
                    Canvas.SetLeft(sm, 110);
                    break;

                case Key.C:
                    CurrentSkill = 2;
                    Canvas.SetLeft(sm, 160);
                    break;

                case Key.V:
                    CurrentSkill = 3;
                    Canvas.SetLeft(sm, 210);
                    break;

                case Key.B:
                    CurrentSkill = 4;
                    Canvas.SetLeft(sm, 260);
                    break;

                case Key.N:
                    CurrentSkill = 5;
                    Canvas.SetLeft(sm, 310);
                    break;

                case Key.M:
                    CurrentSkill = 6;
                    Canvas.SetLeft(sm, 360);
                    break;

                default:
                    ;
                    break;
                }
            }
            else
            {
                switch (e.Key)
                {
                case Key.Left:
                    networkcontrol.AddGameRequest("person;" + 2 + ";" + "left");
                    break;

                case Key.Right:
                    networkcontrol.AddGameRequest("person;" + 2 + ";" + "right");
                    break;

                case Key.Up:
                    networkcontrol.AddGameRequest("person;" + 2 + ";" + "up");
                    break;

                case Key.Down:
                    networkcontrol.AddGameRequest("person;" + 2 + ";" + "down");
                    break;

                case Key.Space:
                    networkcontrol.AddGameRequest("person;" + 2 + ";" + "bomb" + ";" + CurrentSkill);
                    break;

                case Key.Z:
                    CurrentSkill = 0;
                    Canvas.SetLeft(sm, 60);
                    break;

                case Key.X:
                    CurrentSkill = 1;
                    Canvas.SetLeft(sm, 110);
                    break;

                case Key.C:
                    CurrentSkill = 2;
                    Canvas.SetLeft(sm, 160);
                    break;

                case Key.V:
                    CurrentSkill = 3;
                    Canvas.SetLeft(sm, 210);
                    break;

                case Key.B:
                    CurrentSkill = 4;
                    Canvas.SetLeft(sm, 260);
                    break;

                case Key.N:
                    CurrentSkill = 5;
                    Canvas.SetLeft(sm, 310);
                    break;

                case Key.M:
                    CurrentSkill = 6;
                    Canvas.SetLeft(sm, 360);
                    break;
                }
            }
            e.Handled = true;            //事件路由终止
        }