コード例 #1
0
    /// <summary>
    /// 摇杆旋转
    /// </summary>
    /// <param name="dir"></param>
    void OnJoyStickRotation(Vector3 dir)
    {
        RotationCommand cmd = IInputProxyBase.GetEvent <RotationCommand>("RotationCommand");

        cmd.m_dir = dir;
        InputManager.Dispatch("RotationCommand", cmd);
    }
コード例 #2
0
    public void Rotate(AXIS axis, float angle, float direction, RotationCommand.CommandType rotationType, float rotationTime = 0.3f)
    {
        if (!rotationLocked)
        {
            RotationCommand command = new RotationCommand();

            command.xIndex = int.Parse(RubikGenerator.Instance.selecedCube.name[0].ToString()) - 1;
            command.yIndex = int.Parse(RubikGenerator.Instance.selecedCube.name[1].ToString()) - 1;
            command.zIndex = int.Parse(RubikGenerator.Instance.selecedCube.name[2].ToString()) - 1;

            command.direction   = direction;
            command.angle       = angle;
            command.axis        = axis;
            command.commandType = rotationType;

            if (rotationType == RotationCommand.CommandType.Manual)
            {
                rotationCommands.Push(command);
                allRotationCommands.Push(command);
            }

            rotationLocked = true;

            var slice = RubikGenerator.Instance.GetSlice(axis);

            StartCoroutine(RotateSlice(slice, axis, angle, rotationTime, direction, rotationType));
        }
    }
コード例 #3
0
        public CommandController()
        {
            var grid = GridService.CreateGrid(GridUnitsX, GridUnitsY);

            _moveCommand  = new MoveCommand(grid);
            _placeCommand = new PlaceCommand(grid);
            _rotateLeft   = new RotationCommand("LEFT", RotationalDirection.Left);
            _rotateRight  = new RotationCommand("RIGHT", RotationalDirection.Right);
        }
コード例 #4
0
 public Form1()
 {
     InitializeComponent();
     _robot        = new Robot();
     _grid         = new Grid(GridUnits, GridUnits);
     _moveCommand  = new MoveCommand(_grid);
     _placeCommand = new PlaceCommand(_grid);
     _rotateLeft   = new RotationCommand("LEFT", RotationalDirection.Left);
     _rotateRight  = new RotationCommand("RIGHT", RotationalDirection.Right);
 }
コード例 #5
0
ファイル: WindowVM.cs プロジェクト: JoaoSilveira/CG
 private void RotateObject()
 {
     LastCommand?.Deactivate(Application.Current.MainWindow);
     LastCommand          = new RotationCommand(Application.Current.MainWindow, SelectedObject);
     LastCommand.OnApply += () =>
     {
         LastCommand.Deactivate(Application.Current.MainWindow);
         LastCommand = null;
     };
 }
コード例 #6
0
        private void HighlightTiles(GameObject currentUnit, List <ICommand> commands)
        {
            UnhighlightTiles();
            GameObject go = new GameObject();
            Transform  bufferTransform = currentUnit.transform;

            go.transform.position = bufferTransform.position;
            go.transform.rotation = bufferTransform.rotation;
            ClearPath();

            int turnNo = 1;

            foreach (ICommand selectedCommand in commands)
            {
                switch (selectedCommand)
                {
                case MoveCommand moveCommand:
                    go.transform.position = GetVector3ToDrawAt(moveCommand, go.transform);
                    break;

                case RotationCommand rotationCommand:
                    go.transform.Rotate(Vector3.up,
                                        RotationCommand.GetYAxisRotationAngle(rotationCommand.Direction));
                    break;

                case AttackCommand _:
                case WaitCommand _:
                    break;

                default:
                    throw new Exception("Unknown command type! " + selectedCommand);
                }

                _path.Add(new PathNode
                {
                    turnNo   = turnNo,
                    position = go.transform.position + Vector3.up
                });
                turnNo++;
            }

            Destroy(go);

            foreach (PathNode n in _path)
            {
                if (Physics.Raycast(n.position, Vector3.down, out RaycastHit hit, 10f,
                                    LayerMask.GetMask("Tile")))
                {
                    Tile t = hit.collider.GetComponent <Tile>();
                    t.LightUp(n.turnNo);
                }
            }
        }
コード例 #7
0
    public void ReceviceRotation(RotationCommand cmd)
    {
        float m_cameraAngle = CameraService.Instance.m_mainCameraGo.transform.eulerAngles.y;

        if (cmd.m_dir != Vector3.zero)
        {
            skillDirCache = cmd.m_dir.Vector3RotateInXZ2(m_cameraAngle).normalized;
            isFireCache   = true;
        }
        else
        {
            isFireCache = false;
        }
    }
コード例 #8
0
    private RotationCommand GenerateRotationCommand()
    {
        RotationCommand rotationCommand = new RotationCommand();

        rotationCommand.xIndex = Random.Range(0, RubikGenerator.Instance.size - 1);
        rotationCommand.yIndex = Random.Range(0, RubikGenerator.Instance.size - 1);
        rotationCommand.zIndex = Random.Range(0, RubikGenerator.Instance.size - 1);

        rotationCommand.axis      = (AXIS)Random.Range(0, 3);
        rotationCommand.direction = -1;

        if (rotationCommand.direction == 0)
        {
            rotationCommand.direction = 1;
        }

        rotationCommand.angle = -90;

        return(rotationCommand);
    }
コード例 #9
0
        public void RotateBasedOnRedOrangeAxesOnThirdRowWithThreeTurnovers_Works()
        {
            // Arrange
            var orderedCube = CubeBuilder.CreateOrdered().Build();

            var command = new RotationCommand(Orientation.RedOrange, RotationSegment.Third, turnovers: 3);

            // Act
            var resltedCube = orderedCube.Rotate(command);

            // Assert

            #region testing white side
            // white side should stay the same
            var whiteSideColors = resltedCube.GetSideColors(Color.White);

            Assert.Equal(Color.Green, whiteSideColors[0, 2]);
            Assert.Equal(Color.Green, whiteSideColors[1, 2]);
            Assert.Equal(Color.Green, whiteSideColors[2, 2]);
            Assert.Equal(Color.White, whiteSideColors[0, 1]);
            Assert.Equal(Color.White, whiteSideColors[1, 1]);
            Assert.Equal(Color.White, whiteSideColors[2, 1]);
            Assert.Equal(Color.White, whiteSideColors[0, 0]);
            Assert.Equal(Color.White, whiteSideColors[1, 0]);
            Assert.Equal(Color.White, whiteSideColors[2, 0]);
            #endregion

            #region testing yellow side
            var yellowSideColors = resltedCube.GetSideColors(Color.Yellow);

            Assert.Equal(Color.Blue, yellowSideColors[0, 2]);
            Assert.Equal(Color.Blue, yellowSideColors[1, 2]);
            Assert.Equal(Color.Blue, yellowSideColors[2, 2]);
            Assert.Equal(Color.Yellow, yellowSideColors[0, 1]);
            Assert.Equal(Color.Yellow, yellowSideColors[1, 1]);
            Assert.Equal(Color.Yellow, yellowSideColors[2, 1]);
            Assert.Equal(Color.Yellow, yellowSideColors[0, 0]);
            Assert.Equal(Color.Yellow, yellowSideColors[1, 0]);
            Assert.Equal(Color.Yellow, yellowSideColors[2, 0]);
            #endregion

            #region testing red side
            var redSideColors = resltedCube.GetSideColors(Color.Red);

            Assert.Equal(Color.Red, redSideColors[0, 0]);
            Assert.Equal(Color.Red, redSideColors[0, 1]);
            Assert.Equal(Color.Red, redSideColors[0, 2]);
            Assert.Equal(Color.Red, redSideColors[1, 0]);
            Assert.Equal(Color.Red, redSideColors[1, 1]);
            Assert.Equal(Color.Red, redSideColors[1, 2]);
            Assert.Equal(Color.Red, redSideColors[2, 0]);
            Assert.Equal(Color.Red, redSideColors[2, 1]);
            Assert.Equal(Color.Red, redSideColors[2, 2]);
            #endregion

            #region testing green side
            var greenSideColors = resltedCube.GetSideColors(Color.Green);

            Assert.Equal(Color.Green, greenSideColors[0, 0]);
            Assert.Equal(Color.Green, greenSideColors[0, 1]);
            Assert.Equal(Color.Yellow, greenSideColors[0, 2]);
            Assert.Equal(Color.Green, greenSideColors[1, 0]);
            Assert.Equal(Color.Green, greenSideColors[1, 1]);
            Assert.Equal(Color.Yellow, greenSideColors[1, 2]);
            Assert.Equal(Color.Green, greenSideColors[2, 0]);
            Assert.Equal(Color.Green, greenSideColors[2, 1]);
            Assert.Equal(Color.Yellow, greenSideColors[2, 2]);
            #endregion

            #region testing blue side
            var blueSideColors = resltedCube.GetSideColors(Color.Blue);

            Assert.Equal(Color.Blue, blueSideColors[0, 0]);
            Assert.Equal(Color.Blue, blueSideColors[0, 1]);
            Assert.Equal(Color.White, blueSideColors[0, 2]);
            Assert.Equal(Color.Blue, blueSideColors[1, 0]);
            Assert.Equal(Color.Blue, blueSideColors[1, 1]);
            Assert.Equal(Color.White, blueSideColors[1, 2]);
            Assert.Equal(Color.Blue, blueSideColors[2, 0]);
            Assert.Equal(Color.Blue, blueSideColors[2, 1]);
            Assert.Equal(Color.White, blueSideColors[2, 2]);
            #endregion

            #region testing orange side
            var orangeSideColors = resltedCube.GetSideColors(Color.Orange);

            Assert.Equal(Color.Orange, orangeSideColors[0, 0]);
            Assert.Equal(Color.Orange, orangeSideColors[1, 0]);
            Assert.Equal(Color.Orange, orangeSideColors[2, 0]);
            Assert.Equal(Color.Orange, orangeSideColors[0, 1]);
            Assert.Equal(Color.Orange, orangeSideColors[1, 1]);
            Assert.Equal(Color.Orange, orangeSideColors[2, 1]);
            Assert.Equal(Color.Orange, orangeSideColors[0, 2]);
            Assert.Equal(Color.Orange, orangeSideColors[1, 2]);
            Assert.Equal(Color.Orange, orangeSideColors[2, 2]);
            #endregion
        }
コード例 #10
0
        public void RotateOnYellowWhiteOnFirstRowWithOneTurnover_Works()
        {
            // Arrange
            var orderedCube = CubeBuilder.CreateOrdered().Build();

            var command = new RotationCommand(Orientation.YellowWhite, RotationSegment.First, turnovers: 1);

            // Act
            var resltedCube = orderedCube.Rotate(command);

            // Assert

            #region testing white side
            // white side should stay the same
            var whiteSideColors = resltedCube.GetSideColors(Color.White);

            // first row
            Assert.Equal(Color.White, whiteSideColors[0, 2]);
            Assert.Equal(Color.White, whiteSideColors[1, 2]);
            Assert.Equal(Color.White, whiteSideColors[2, 2]);

            // second row
            Assert.Equal(Color.White, whiteSideColors[0, 1]);
            Assert.Equal(Color.White, whiteSideColors[1, 1]);
            Assert.Equal(Color.White, whiteSideColors[2, 1]);

            // third row
            Assert.Equal(Color.White, whiteSideColors[0, 0]);
            Assert.Equal(Color.White, whiteSideColors[1, 0]);
            Assert.Equal(Color.White, whiteSideColors[2, 0]);
            #endregion

            #region testing yellow side
            // white side should stay the same
            var yellowSideColors = resltedCube.GetSideColors(Color.Yellow);

            // first row
            Assert.Equal(Color.Yellow, yellowSideColors[0, 2]);
            Assert.Equal(Color.Yellow, yellowSideColors[1, 2]);
            Assert.Equal(Color.Yellow, yellowSideColors[2, 2]);

            // second row
            Assert.Equal(Color.Yellow, yellowSideColors[0, 1]);
            Assert.Equal(Color.Yellow, yellowSideColors[1, 1]);
            Assert.Equal(Color.Yellow, yellowSideColors[2, 1]);

            // third row
            Assert.Equal(Color.Yellow, yellowSideColors[0, 0]);
            Assert.Equal(Color.Yellow, yellowSideColors[1, 0]);
            Assert.Equal(Color.Yellow, yellowSideColors[2, 0]);
            #endregion

            #region testing red side
            var redSideColors = resltedCube.GetSideColors(Color.Red);

            // first column
            Assert.Equal(Color.Green, redSideColors[0, 0]);
            Assert.Equal(Color.Red, redSideColors[0, 1]);
            Assert.Equal(Color.Red, redSideColors[0, 2]);

            // second column
            Assert.Equal(Color.Green, redSideColors[1, 0]);
            Assert.Equal(Color.Red, redSideColors[1, 1]);
            Assert.Equal(Color.Red, redSideColors[1, 2]);

            // third column
            Assert.Equal(Color.Green, redSideColors[2, 0]);
            Assert.Equal(Color.Red, redSideColors[2, 1]);
            Assert.Equal(Color.Red, redSideColors[2, 2]);
            #endregion

            #region testing green side
            var greenSideColors = resltedCube.GetSideColors(Color.Green);

            // first row
            Assert.Equal(Color.Orange, greenSideColors[0, 0]);
            Assert.Equal(Color.Orange, greenSideColors[0, 1]);
            Assert.Equal(Color.Orange, greenSideColors[0, 2]);

            // second row
            Assert.Equal(Color.Green, greenSideColors[1, 0]);
            Assert.Equal(Color.Green, greenSideColors[1, 1]);
            Assert.Equal(Color.Green, greenSideColors[1, 2]);

            // third row
            Assert.Equal(Color.Green, greenSideColors[2, 0]);
            Assert.Equal(Color.Green, greenSideColors[2, 1]);
            Assert.Equal(Color.Green, greenSideColors[2, 2]);
            #endregion

            #region testing blue side
            var blueSideColors = resltedCube.GetSideColors(Color.Blue);

            // first row
            Assert.Equal(Color.Red, blueSideColors[0, 0]);
            Assert.Equal(Color.Red, blueSideColors[0, 1]);
            Assert.Equal(Color.Red, blueSideColors[0, 2]);

            // second row
            Assert.Equal(Color.Blue, blueSideColors[1, 0]);
            Assert.Equal(Color.Blue, blueSideColors[1, 1]);
            Assert.Equal(Color.Blue, blueSideColors[1, 2]);

            // third row
            Assert.Equal(Color.Blue, blueSideColors[2, 0]);
            Assert.Equal(Color.Blue, blueSideColors[2, 1]);
            Assert.Equal(Color.Blue, blueSideColors[2, 2]);
            #endregion

            #region testing orange side
            var orangeSideColors = resltedCube.GetSideColors(Color.Orange);

            // first row
            Assert.Equal(Color.Blue, orangeSideColors[0, 0]);
            Assert.Equal(Color.Blue, orangeSideColors[1, 0]);
            Assert.Equal(Color.Blue, orangeSideColors[2, 0]);

            // second row
            Assert.Equal(Color.Orange, orangeSideColors[0, 1]);
            Assert.Equal(Color.Orange, orangeSideColors[1, 1]);
            Assert.Equal(Color.Orange, orangeSideColors[2, 1]);

            // third row
            Assert.Equal(Color.Orange, orangeSideColors[0, 2]);
            Assert.Equal(Color.Orange, orangeSideColors[1, 2]);
            Assert.Equal(Color.Orange, orangeSideColors[2, 2]);
            #endregion
        }
コード例 #11
0
 void ICommandOwner <RotationCommand, RotationCommandHandler> .Command(RotationCommand command)
 {
     commandManager.Handle <RotationCommand, RotationCommandHandler>(this, command);
 }