Esempio n. 1
0
        public static void MoveController(ConsoleKeyInfo keyInfo)
        {
            switch (keyInfo.Key)
            {
            case ConsoleKey.W:
                if (directionMove != DirectionMove.down)
                {
                    directionMove = DirectionMove.up;
                }
                break;

            case ConsoleKey.S:
                if (directionMove != DirectionMove.up)
                {
                    directionMove = DirectionMove.down;
                }
                break;

            case ConsoleKey.A:
                if (directionMove != DirectionMove.right)
                {
                    directionMove = DirectionMove.left;
                }
                break;

            case ConsoleKey.D:
                if (directionMove != DirectionMove.left)
                {
                    directionMove = DirectionMove.right;
                }
                break;
            }
        }
Esempio n. 2
0
        public void MoveHead(DirectionMove _directionMove)
        {
            HidePoint();
            oX = X;
            oY = Y;
            switch (directionMove)
            {
            case DirectionMove.up:
                Y += -1;
                break;

            case DirectionMove.down:
                Y += 1;
                break;

            case DirectionMove.left:
                X += -1;
                break;

            case DirectionMove.right:
                X += 1;
                break;
            }
            ShowPoint();
        }
Esempio n. 3
0
        private static void Main(string[] args)
        {
            string          input           = string.Empty;
            var             translator      = new CommandTranslator();
            Grid            grid            = new Grid(10, 10, new Position(0, 0));
            DirectionMove   direction       = new DirectionMove(grid);
            OrientationMove orientation     = new OrientationMove();
            var             movementService = new MovementService(grid, direction, orientation);
            var             rover           = new Rover(movementService);

            PrintStatus(movementService);

            while (input != "x")
            {
                input = Console.ReadLine();
                var command = translator.Parse(input);
                var result  = rover.Move(command);

                if (result.IsFail)
                {
                    Console.WriteLine("Obstacle detected.");
                }

                PrintStatus(movementService);
            }
        }
Esempio n. 4
0
        public void InitializeComponent(DirectionMove move, Direction direction = 0, ImageDomino last = null)
        {
            Direction = direction;

            var b = new BitmapImage();

            b.BeginInit();
            b.UriSource = uriImage;
            var rotation = GetCorrectRotation(move, last);

            b.Rotation = GetCorrectRotation(move, last);
            b.EndInit();

            Source    = b;
            MaxWidth  = 75 / ((int)rotation % 2 + 1);
            MaxHeight = 37.5 * ((int)rotation % 2 + 1);

            if (last != null)
            {
                if (direction == Direction.Center)
                {
                    CenterPoint.X = last.CenterPoint.X - last.MaxWidth / 2 - MaxWidth / 2;
                    CenterPoint.Y = last.CenterPoint.Y
                                    - (last.Direction != Direction.Center ? MaxHeight / 2 : 0)
                                    + (last.Direction == Direction.Down ? last.MaxHeight / 2 : 0);
                }
                else
                {
                    CenterPoint.X = last.CenterPoint.X
                                    - (last.Direction == Direction.Center ? MaxWidth / 2 : 0);
                    CenterPoint.Y = last.CenterPoint.Y
                                    + (direction == Direction.Up ? -1 : 1) * (last.MaxHeight / 2 + MaxHeight / 2);
                }
            }

            if (move == DirectionMove.Left)
            {
                Canvas.SetLeft(this, CenterPoint.X - MaxWidth / 2);
            }
            else
            {
                Canvas.SetRight(this, CenterPoint.X - MaxWidth / 2);
            }
            Canvas.SetTop(this, CenterPoint.Y - MaxHeight / 2);
        }
Esempio n. 5
0
    /// <summary>
    /// 玩家Ai坦克碰上范围触发器后执行.
    /// </summary>
    public void OnHitAiMoveTrigger(SSTriggerAiPlayerMove.TiggerState type)
    {
        if (IsOpenPlayerAiMove == false)
        {
            return;
        }

        if (m_PlayerMoveCom == null)
        {
            UnityLogWarning("OnHitAiMoveTrigger -> m_PlayerMoveCom was null..........");
            return;
        }

        DirectionMove dirMove = GetPlayerMoveDirOnHitTrigger(type);

        m_RandMoveTime = Random.Range(1f, 3f);
        m_LastMoveTime = Time.time;
        OnChangePlayerMoveDirBtInfo(dirMove);
    }
Esempio n. 6
0
        private Rotation GetCorrectRotation(DirectionMove move, ImageDomino last)
        {
            var correctRotation = Rotation.Rotate0;

            if (Domino.FirstValue == Domino.SecondValue)
            {
                return(Direction == Direction.Center ? Rotation.Rotate90 : correctRotation);
            }

            if (move == DirectionMove.Left)
            {
                if (Domino.SecondValue != (last.isInverted ? last.Domino.SecondValue : last.Domino.FirstValue))
                {
                    isInverted      = true;
                    correctRotation = Rotation.Rotate180;
                }
                if (Direction == Direction.Down)
                {
                    correctRotation = (int)correctRotation - 1 < 0 ? Rotation.Rotate270 : correctRotation - 1;
                }
                if (Direction == Direction.Up)
                {
                    correctRotation = (int)correctRotation - 1 > 3 ? Rotation.Rotate0 : correctRotation + 1;
                }
            }
            else
            {
                if (Domino.FirstValue != (last.isInverted ? last.Domino.FirstValue : last.Domino.SecondValue))
                {
                    isInverted      = true;
                    correctRotation = Rotation.Rotate180;
                }
                if (Direction == Direction.Up)
                {
                    correctRotation = (int)correctRotation - 1 < 0 ? Rotation.Rotate270 : correctRotation - 1;
                }
                if (Direction == Direction.Down)
                {
                    correctRotation = (int)correctRotation - 1 > 3 ? Rotation.Rotate0 : correctRotation + 1;
                }
            }
            return(correctRotation);
        }
Esempio n. 7
0
    /// <summary>
    /// 改变玩家Ai坦克运动方向.
    /// </summary>
    void ChangePlayerMoveDirBtInfo()
    {
        if (IsOpenPlayerAiMove == false)
        {
            return;
        }

        m_LastMoveTime = Time.time;
        DirectionMove dirMove = GetRandomPlayerMoveDir();

        if (dirMove == DirectionMove.Stop)
        {
            m_RandMoveTime = Random.Range(0.5f, 1.5f);
        }
        else
        {
            m_RandMoveTime = Random.Range(1.5f, 2.5f);
        }
        OnChangePlayerMoveDirBtInfo(dirMove);
    }
Esempio n. 8
0
    /// <summary>
    /// 当玩家碰上范围触发器时获取随机运动方向.
    /// </summary>
    DirectionMove GetPlayerMoveDirOnHitTrigger(SSTriggerAiPlayerMove.TiggerState type)
    {
        int           randVal = Random.Range(0, 100) % 5;
        DirectionMove dirType = DirectionMove.Stop;

        switch (type)
        {
        case SSTriggerAiPlayerMove.TiggerState.Qian:
        {
            if (randVal == 0)
            {
                dirType = DirectionMove.Zuo;
            }
            else if (randVal == 1)
            {
                dirType = DirectionMove.ZuoHou;
            }
            else if (randVal == 2)
            {
                dirType = DirectionMove.Hou;
            }
            else if (randVal == 3)
            {
                dirType = DirectionMove.YouHou;
            }
            else if (randVal == 4)
            {
                dirType = DirectionMove.You;
            }
            break;
        }

        case SSTriggerAiPlayerMove.TiggerState.Hou:
        {
            if (randVal == 0)
            {
                dirType = DirectionMove.Zuo;
            }
            else if (randVal == 1)
            {
                dirType = DirectionMove.ZuoQian;
            }
            else if (randVal == 2)
            {
                dirType = DirectionMove.Qian;
            }
            else if (randVal == 3)
            {
                dirType = DirectionMove.YouQian;
            }
            else if (randVal == 4)
            {
                dirType = DirectionMove.You;
            }
            break;
        }

        case SSTriggerAiPlayerMove.TiggerState.Zuo:
        {
            if (randVal == 0)
            {
                dirType = DirectionMove.Hou;
            }
            else if (randVal == 1)
            {
                dirType = DirectionMove.YouHou;
            }
            else if (randVal == 2)
            {
                dirType = DirectionMove.You;
            }
            else if (randVal == 3)
            {
                dirType = DirectionMove.YouQian;
            }
            else if (randVal == 4)
            {
                dirType = DirectionMove.Qian;
            }
            break;
        }

        case SSTriggerAiPlayerMove.TiggerState.You:
        {
            if (randVal == 0)
            {
                dirType = DirectionMove.Hou;
            }
            else if (randVal == 1)
            {
                dirType = DirectionMove.ZuoHou;
            }
            else if (randVal == 2)
            {
                dirType = DirectionMove.Zuo;
            }
            else if (randVal == 3)
            {
                dirType = DirectionMove.ZuoQian;
            }
            else if (randVal == 4)
            {
                dirType = DirectionMove.Qian;
            }
            break;
        }
        }
        return(dirType);
    }
Esempio n. 9
0
    /// <summary>
    /// 改变玩家运动方向.
    /// </summary>
    void OnChangePlayerMoveDirBtInfo(DirectionMove dirMove)
    {
        if (m_PlayerMoveCom == null)
        {
            UnityLogWarning("OnHitAiMoveTrigger -> m_PlayerMoveCom was null..........");
            return;
        }

        int indexVal = (int)m_PlayerMoveCom.PlayerIndex - 1;

        if (indexVal < 0 || indexVal > 3)
        {
            UnityLogWarning("OnChangePlayerMoveDirBtInfo -> indexVal was wrong! indexVal ========= " + indexVal);
            return;
        }

        switch (dirMove)
        {
        case DirectionMove.Stop:
        {
            InputEventCtrl.GetInstance().OnClickFangXiangUBt(indexVal, pcvr.ButtonState.UP);
            InputEventCtrl.GetInstance().OnClickFangXiangDBt(indexVal, pcvr.ButtonState.UP);
            InputEventCtrl.GetInstance().OnClickFangXiangLBt(indexVal, pcvr.ButtonState.UP);
            InputEventCtrl.GetInstance().OnClickFangXiangRBt(indexVal, pcvr.ButtonState.UP);
            break;
        }

        case DirectionMove.Qian:
        {
            InputEventCtrl.GetInstance().OnClickFangXiangUBt(indexVal, pcvr.ButtonState.DOWN);
            InputEventCtrl.GetInstance().OnClickFangXiangDBt(indexVal, pcvr.ButtonState.UP);
            InputEventCtrl.GetInstance().OnClickFangXiangLBt(indexVal, pcvr.ButtonState.UP);
            InputEventCtrl.GetInstance().OnClickFangXiangRBt(indexVal, pcvr.ButtonState.UP);
            break;
        }

        case DirectionMove.Hou:
        {
            InputEventCtrl.GetInstance().OnClickFangXiangUBt(indexVal, pcvr.ButtonState.UP);
            InputEventCtrl.GetInstance().OnClickFangXiangDBt(indexVal, pcvr.ButtonState.DOWN);
            InputEventCtrl.GetInstance().OnClickFangXiangLBt(indexVal, pcvr.ButtonState.UP);
            InputEventCtrl.GetInstance().OnClickFangXiangRBt(indexVal, pcvr.ButtonState.UP);
            break;
        }

        case DirectionMove.Zuo:
        {
            InputEventCtrl.GetInstance().OnClickFangXiangUBt(indexVal, pcvr.ButtonState.UP);
            InputEventCtrl.GetInstance().OnClickFangXiangDBt(indexVal, pcvr.ButtonState.UP);
            InputEventCtrl.GetInstance().OnClickFangXiangLBt(indexVal, pcvr.ButtonState.DOWN);
            InputEventCtrl.GetInstance().OnClickFangXiangRBt(indexVal, pcvr.ButtonState.UP);
            break;
        }

        case DirectionMove.You:
        {
            InputEventCtrl.GetInstance().OnClickFangXiangUBt(indexVal, pcvr.ButtonState.UP);
            InputEventCtrl.GetInstance().OnClickFangXiangDBt(indexVal, pcvr.ButtonState.UP);
            InputEventCtrl.GetInstance().OnClickFangXiangLBt(indexVal, pcvr.ButtonState.UP);
            InputEventCtrl.GetInstance().OnClickFangXiangRBt(indexVal, pcvr.ButtonState.DOWN);
            break;
        }

        case DirectionMove.ZuoQian:
        {
            InputEventCtrl.GetInstance().OnClickFangXiangUBt(indexVal, pcvr.ButtonState.DOWN);
            InputEventCtrl.GetInstance().OnClickFangXiangDBt(indexVal, pcvr.ButtonState.UP);
            InputEventCtrl.GetInstance().OnClickFangXiangLBt(indexVal, pcvr.ButtonState.DOWN);
            InputEventCtrl.GetInstance().OnClickFangXiangRBt(indexVal, pcvr.ButtonState.UP);
            break;
        }

        case DirectionMove.YouQian:
        {
            InputEventCtrl.GetInstance().OnClickFangXiangUBt(indexVal, pcvr.ButtonState.DOWN);
            InputEventCtrl.GetInstance().OnClickFangXiangDBt(indexVal, pcvr.ButtonState.UP);
            InputEventCtrl.GetInstance().OnClickFangXiangLBt(indexVal, pcvr.ButtonState.UP);
            InputEventCtrl.GetInstance().OnClickFangXiangRBt(indexVal, pcvr.ButtonState.DOWN);
            break;
        }

        case DirectionMove.ZuoHou:
        {
            InputEventCtrl.GetInstance().OnClickFangXiangUBt(indexVal, pcvr.ButtonState.UP);
            InputEventCtrl.GetInstance().OnClickFangXiangDBt(indexVal, pcvr.ButtonState.DOWN);
            InputEventCtrl.GetInstance().OnClickFangXiangLBt(indexVal, pcvr.ButtonState.DOWN);
            InputEventCtrl.GetInstance().OnClickFangXiangRBt(indexVal, pcvr.ButtonState.UP);
            break;
        }

        case DirectionMove.YouHou:
        {
            InputEventCtrl.GetInstance().OnClickFangXiangUBt(indexVal, pcvr.ButtonState.UP);
            InputEventCtrl.GetInstance().OnClickFangXiangDBt(indexVal, pcvr.ButtonState.DOWN);
            InputEventCtrl.GetInstance().OnClickFangXiangLBt(indexVal, pcvr.ButtonState.UP);
            InputEventCtrl.GetInstance().OnClickFangXiangRBt(indexVal, pcvr.ButtonState.DOWN);
            break;
        }
        }
    }
 public void SetUp()
 {
     _grid          = new Grid(4, 4, new Position(0, 0));
     _directionMove = new DirectionMove(_grid);
     direction      = MoveDirection.East;
 }
Esempio n. 11
0
        public void Move()
        {
            int check = random.Next(10);

            if (check > 3)
            {
                fire = false;
                switch (goTo)
                {
                case DirectionMove.UP:
                    this.posY     -= this.Speed;
                    this.Direction = RotateFlipType.RotateNoneFlipNone;
                    break;

                case DirectionMove.DOWN:
                    this.posY     += this.Speed;
                    this.Direction = RotateFlipType.Rotate180FlipNone;
                    break;

                case DirectionMove.LEFT:
                    this.posX     -= this.Speed;
                    this.Direction = RotateFlipType.Rotate270FlipNone;
                    break;

                case DirectionMove.RIGHT:
                    this.posX     += this.Speed;
                    this.Direction = RotateFlipType.Rotate90FlipNone;
                    break;

                default:
                    break;
                }
                moveCount++;
            }
            else
            {
                if (moveCount > 16)
                {
                    moveCount = 0;
                    fire      = true;
                    switch (check)
                    {
                    case 0:
                        goTo = DirectionMove.UP;
                        break;

                    case 1:
                        goTo = DirectionMove.DOWN;
                        break;

                    case 2:
                        goTo = DirectionMove.LEFT;
                        break;

                    case 3:
                        goTo = DirectionMove.RIGHT;
                        break;

                    default:
                        break;
                    }
                }
            }
        }