示例#1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cube3d"></param>
        /// <param name="step"></param>
        /// <param name="direction"></param>
        private void MoveBlocks(Cube cube3d, int step, Direction direction)
        {
            if (animationKeyFramesBLocks != null)
            {
                ///  animationKeyFramesBLocks.Completed -= AnimationKeyFramesBLocks_Completed;
            }

            animationKeyFramesBLocks            = new Point3DAnimationUsingKeyFrames();
            animationKeyFramesBLocks.Completed += new EventHandler(AnimationKeyFramesBLocks_Completed);

            double cubeLength = Magnet.WidthHeightDepth;

            animationKeyFramesBLocks.Duration  = BlockMovementTime;
            animationKeyFramesBLocks.BeginTime = BlockBeginTime;

            Point3D cubeLocation = cube3d.StartingPointCube;

            for (int i = 0; i < cubeLength * step; i++)
            {
                switch (direction)
                {
                case Direction.Up:

                    cubeLocation.Y++;
                    goto default;

                case Direction.Down:

                    cubeLocation.Y--;
                    goto default;

                case Direction.Left:

                    cubeLocation.X--;
                    goto default;

                case Direction.Right:

                    cubeLocation.X++;
                    goto default;

                case Direction.Front:

                    cubeLocation.Z++;
                    goto default;

                case Direction.Back:
                    cubeLocation.Z--;
                    goto default;

                default:

                    LinearPoint3DKeyFrame linear3dkeyframeBox = new LinearPoint3DKeyFrame(cubeLocation);
                    animationKeyFramesBLocks.KeyFrames.Add(linear3dkeyframeBox);
                    break;
                }
            }

            CountMovingBlocks++;
            cube3d.BeginAnimation(Cube.StartingPointCubeProperty, animationKeyFramesBLocks, HandoffBehavior.SnapshotAndReplace);
        }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="MovingCube"></param>
        /// <param name="direction"></param>
        private void MoveCube(Cube MovingCube, Direction direction)
        {
            if (this.cubeAnimationCompleted == true && this.positionAnimationCompleted == true && this.cameraLookdirectionAnimationCompleted == true && this.fieldViewAnimationCompleted == true && CountMovingBlocks == 0)
            {
                Point3D  cameraPosition      = this.ViewModelCamera.Position;
                Vector3D cameraLookDirection = this.ViewModelCamera.LookDirection;
                double   cameraFieldOfView   = this.ViewModelCamera.FieldOfView;
                double   cubeWidthHeight     = (MovingCube.WidthHeightDepth);

                if (animationKeyFramesBox != null)
                {
                    animationKeyFramesBox.Completed -= AnimationKeyFramesBox_Completed;
                }

                animationKeyFramesBox            = new Point3DAnimationUsingKeyFrames();
                animationKeyFramesBox.Completed += new EventHandler(AnimationKeyFramesBox_Completed);

                if (animationFieldView != null)
                {
                    animationFieldView.Completed -= new EventHandler(AnimationFieldView_Completed);
                }

                animationFieldView            = new DoubleAnimationUsingKeyFrames();
                animationFieldView.Completed += new EventHandler(AnimationFieldView_Completed);

                if (animationKeyFramesCameraPosition != null)
                {
                    animationKeyFramesCameraPosition.Completed -= new EventHandler(AnimationKeyFramesCameraPosition_Completed);
                }

                animationKeyFramesCameraPosition            = new Point3DAnimationUsingKeyFrames();
                animationKeyFramesCameraPosition.Completed += new EventHandler(AnimationKeyFramesCameraPosition_Completed);

                if (animationKeyFramesCameraLookDirection != null)
                {
                    animationKeyFramesCameraLookDirection.Completed -= new EventHandler(AnimationKeyFramesCameraLookDirection_Completed);
                }

                animationKeyFramesCameraLookDirection            = new Vector3DAnimationUsingKeyFrames();
                animationKeyFramesCameraLookDirection.Completed += new EventHandler(AnimationKeyFramesCameraLookDirection_Completed);

                animationKeyFramesBox.Duration                 = BlockMovementTime;
                animationFieldView.Duration                    = BlockMovementTime;
                animationKeyFramesCameraPosition.Duration      = BlockMovementTime;
                animationKeyFramesCameraLookDirection.Duration = BlockMovementTime;

                animationKeyFramesBox.BeginTime                 = BlockBeginTime;
                animationFieldView.BeginTime                    = BlockBeginTime;
                animationKeyFramesCameraPosition.BeginTime      = BlockBeginTime;
                animationKeyFramesCameraLookDirection.BeginTime = BlockBeginTime;

                Point3D cubeLocation = new Point3D(MovingCube.StartingPointCube.X, MovingCube.StartingPointCube.Y, MovingCube.StartingPointCube.Z);

                ///Check if Magnet can move in right direction
                bool canMove = false;
                int  counter;
                int  emptyPositionOrFloor = 0;

                switch (direction)
                {
                case Direction.Up:
                    for (counter = MagnetFloorNo + 1; counter < Constants.NoofFloor; counter++)
                    {
                        if (position[counter][MagnetPositionOnFloor] == null)
                        {
                            emptyPositionOrFloor = counter;
                            canMove = true;
                            break;
                        }
                    }

                    break;

                case Direction.Down:
                    for (counter = MagnetFloorNo - 1; counter >= 0; counter--)
                    {
                        if (position[counter][MagnetPositionOnFloor] == null)
                        {
                            emptyPositionOrFloor = counter;
                            canMove = true;
                            break;
                        }
                    }
                    break;

                case Direction.Left:
                    int extremeLeftPos = MagnetPositionOnFloor - MagnetPositionOnFloor % Constants.BlocksInXdirection;

                    for (counter = MagnetPositionOnFloor - 1; counter >= extremeLeftPos; counter--)
                    {
                        if (position[MagnetFloorNo][counter] == null)
                        {
                            emptyPositionOrFloor = counter;
                            canMove = true;
                            break;
                        }
                    }

                    break;

                case Direction.Right:
                    int extremeRightPos = MagnetPositionOnFloor + Constants.BlocksInXdirection - MagnetPositionOnFloor % Constants.BlocksInXdirection;

                    for (counter = MagnetPositionOnFloor + 1; counter < extremeRightPos; counter++)
                    {
                        if (position[MagnetFloorNo][counter] == null)
                        {
                            emptyPositionOrFloor = counter;
                            canMove = true;
                            break;
                        }
                    }
                    break;

                case Direction.Front:
                    int extremeFrontPos = Constants.BlocksInXdirection * Constants.BlocksInZdirection;

                    for (counter = MagnetPositionOnFloor; counter < extremeFrontPos; counter = counter + Constants.BlocksInXdirection)
                    {
                        if (position[MagnetFloorNo][counter] == null)
                        {
                            emptyPositionOrFloor = counter;
                            canMove = true;
                            break;
                        }
                    }
                    break;

                case Direction.Back:
                    int extremeBackPos = 0;

                    for (counter = MagnetPositionOnFloor; counter >= extremeBackPos; counter = counter - Constants.BlocksInXdirection)
                    {
                        if (position[MagnetFloorNo][counter] == null)
                        {
                            emptyPositionOrFloor = counter;
                            canMove = true;
                            break;
                        }
                    }

                    break;

                default:
                    break;
                }

                if (canMove == true)
                {
                    this.StepCount++;

                    for (int i = 0; i < cubeWidthHeight; i++)
                    {
                        switch (direction)
                        {
                        case Direction.Up:
                            if (cubeLocation.Y <= Math.Ceiling((Constants.NoofFloor - 1) * cubeWidthHeight))
                            {
                                cubeLocation.Y++;

                                cameraPosition.Y      = cameraPosition.Y + Constants.LeftRightCameraDelta;
                                cameraLookDirection.Y = cameraLookDirection.Y - Constants.LeftRightCameraDelta;

                                goto default;
                            }
                            break;

                        case Direction.Down:
                            if (cubeLocation.Y >= 0)
                            {
                                cubeLocation.Y--;

                                cameraPosition.Y      = cameraPosition.Y - Constants.LeftRightCameraDelta;
                                cameraLookDirection.Y = cameraLookDirection.Y + Constants.LeftRightCameraDelta;

                                goto default;
                            }
                            break;

                        case Direction.Left:
                            if (cubeLocation.X > 0)
                            {
                                cubeLocation.X--;

                                cameraPosition.X      = cameraPosition.X - Constants.LeftRightCameraDelta;
                                cameraLookDirection.X = cameraLookDirection.X + Constants.LeftRightCameraDelta;

                                goto default;
                            }
                            break;

                        case Direction.Right:
                            if (cubeLocation.X <= Math.Ceiling((Constants.BlocksInXdirection - 1) * cubeWidthHeight))
                            {
                                cubeLocation.X++;

                                cameraPosition.X      = cameraPosition.X + Constants.LeftRightCameraDelta;
                                cameraLookDirection.X = cameraLookDirection.X - Constants.LeftRightCameraDelta;

                                goto default;
                            }
                            break;

                        case Direction.Front:
                            if (cubeLocation.Z <= Math.Ceiling(((Constants.BlocksInZdirection - 1)) * cubeWidthHeight))
                            {
                                cubeLocation.Z++;
                                cameraPosition.Z      = cameraPosition.Z + 1;
                                cameraLookDirection.Z = cameraLookDirection.Z - 1;

                                cameraFieldOfView = cameraFieldOfView - .05;

                                goto default;
                            }
                            break;

                        case Direction.Back:
                            if (cubeLocation.Z >= 0)
                            {
                                cubeLocation.Z--;

                                cameraPosition.Z      = cameraPosition.Z - 1;
                                cameraLookDirection.Z = cameraLookDirection.Z + 1;

                                cameraFieldOfView = cameraFieldOfView + .05;

                                goto default;
                            }

                            break;

                        default:
                            LinearPoint3DKeyFrame linear3dkeyframeBox = new LinearPoint3DKeyFrame(cubeLocation);
                            animationKeyFramesBox.KeyFrames.Add(linear3dkeyframeBox);

                            LinearPoint3DKeyFrame linear3dkeyframeCameraPosion = new LinearPoint3DKeyFrame(cameraPosition);

                            animationKeyFramesCameraPosition.KeyFrames.Add(linear3dkeyframeCameraPosion);

                            LinearVector3DKeyFrame linear3dkeyframeCameraLookDirection = new LinearVector3DKeyFrame(cameraLookDirection);

                            animationKeyFramesCameraLookDirection.KeyFrames.Add(linear3dkeyframeCameraLookDirection);

                            LinearDoubleKeyFrame linearDoubleKeyFrame = new LinearDoubleKeyFrame(cameraFieldOfView);

                            animationFieldView.KeyFrames.Add(linearDoubleKeyFrame);

                            break;
                        }
                    }

                    switch (direction)
                    {
                    case Direction.Up:
                        if (cubeLocation.Y <= Math.Ceiling((Constants.NoofFloor - 1) * cubeWidthHeight))
                        {
                            for (counter = emptyPositionOrFloor - 1; counter > MagnetFloorNo; counter--)
                            {
                                this.MoveBlocks(position[counter][MagnetPositionOnFloor], 1, Direction.Up);
                                position[counter + 1][MagnetPositionOnFloor] = position[counter][MagnetPositionOnFloor];
                            }

                            MagnetFloorNo++;
                            position[MagnetFloorNo][MagnetPositionOnFloor]     = position[MagnetFloorNo - 1][MagnetPositionOnFloor];
                            position[MagnetFloorNo - 1][MagnetPositionOnFloor] = null;
                            goto default;
                        }

                        break;

                    case Direction.Down:
                        if (Math.Ceiling(cubeLocation.Y) >= 0)
                        {
                            for (counter = emptyPositionOrFloor + 1; counter < MagnetFloorNo; counter++)
                            {
                                this.MoveBlocks(position[counter][MagnetPositionOnFloor], 1, Direction.Down);
                                position[counter - 1][MagnetPositionOnFloor] = position[counter][MagnetPositionOnFloor];
                            }

                            position[MagnetFloorNo - 1][MagnetPositionOnFloor] = position[MagnetFloorNo][MagnetPositionOnFloor];
                            position[MagnetFloorNo][MagnetPositionOnFloor]     = null;

                            MagnetFloorNo--;

                            goto default;
                        }

                        break;

                    case Direction.Left:
                        if (cubeLocation.X >= 0)
                        {
                            for (counter = emptyPositionOrFloor + 1; counter < MagnetPositionOnFloor; counter++)
                            {
                                this.MoveBlocks(position[MagnetFloorNo][counter], 1, Direction.Left);

                                position[MagnetFloorNo][counter - 1] = position[MagnetFloorNo][counter];
                            }

                            position[MagnetFloorNo][MagnetPositionOnFloor - 1] = position[MagnetFloorNo][MagnetPositionOnFloor];
                            position[MagnetFloorNo][MagnetPositionOnFloor]     = null;

                            MagnetPositionOnFloor--;

                            goto default;
                        }

                        break;

                    case Direction.Right:

                        if (cubeLocation.X <= Math.Ceiling((Constants.BlocksInXdirection - 1) * cubeWidthHeight))
                        {
                            for (counter = emptyPositionOrFloor - 1; counter > MagnetPositionOnFloor; counter--)
                            {
                                this.MoveBlocks(position[MagnetFloorNo][counter], 1, Direction.Right);

                                position[MagnetFloorNo][counter + 1] = position[MagnetFloorNo][counter];
                            }

                            position[MagnetFloorNo][MagnetPositionOnFloor + 1] = position[MagnetFloorNo][MagnetPositionOnFloor];
                            position[MagnetFloorNo][MagnetPositionOnFloor]     = null;

                            MagnetPositionOnFloor++;

                            goto default;
                        }

                        break;

                    case Direction.Front:
                        if (cubeLocation.Z <= Math.Ceiling(((Constants.BlocksInZdirection - 1)) * cubeWidthHeight))
                        {
                            for (counter = emptyPositionOrFloor - Constants.BlocksInXdirection; counter > MagnetPositionOnFloor; counter = counter - Constants.BlocksInXdirection)
                            {
                                this.MoveBlocks(position[MagnetFloorNo][counter], 1, Direction.Front);

                                position[MagnetFloorNo][counter + Constants.BlocksInXdirection] = position[MagnetFloorNo][counter];
                            }

                            position[MagnetFloorNo][MagnetPositionOnFloor + Constants.BlocksInXdirection] = position[MagnetFloorNo][MagnetPositionOnFloor];
                            position[MagnetFloorNo][MagnetPositionOnFloor] = null;

                            MagnetPositionOnFloor = MagnetPositionOnFloor + Constants.BlocksInXdirection;

                            goto default;
                        }
                        break;

                    case Direction.Back:
                        if (cubeLocation.Z >= 0)
                        {
                            for (counter = emptyPositionOrFloor + Constants.BlocksInXdirection; counter < MagnetPositionOnFloor; counter = counter + Constants.BlocksInXdirection)
                            {
                                this.MoveBlocks(position[MagnetFloorNo][counter], 1, Direction.Back);

                                position[MagnetFloorNo][counter - Constants.BlocksInXdirection] = position[MagnetFloorNo][counter];
                            }

                            position[MagnetFloorNo][MagnetPositionOnFloor - Constants.BlocksInXdirection] = position[MagnetFloorNo][MagnetPositionOnFloor];
                            position[MagnetFloorNo][MagnetPositionOnFloor] = null;

                            MagnetPositionOnFloor = MagnetPositionOnFloor - Constants.BlocksInXdirection;

                            goto default;
                        }

                        break;

                    default:

                        ApplyAnimation(animationKeyFramesBox, animationKeyFramesCameraPosition, animationKeyFramesCameraLookDirection, animationFieldView);
                        break;
                    }
                }
            }
        }
示例#3
0
        /// <summary>
        ///
        /// </summary>
        private void CheckCompletness()
        {
            int    cubesPerFloor = (int)((Constants.BlocksInXdirection) * (Constants.BlocksInZdirection));
            double cubeLength    = Constants.CubeLength;

            //Check on left
            int  extremLeftPos = MagnetPositionOnFloor - MagnetPositionOnFloor % Constants.BlocksInXdirection;
            bool pass          = false;

            if (MagnetPositionOnFloor - 1 >= extremLeftPos && position[MagnetFloorNo][MagnetPositionOnFloor - 1] != null && position[MagnetFloorNo][MagnetPositionOnFloor - 1].color == Colors.Red)
            {
                int extremeRightPos = MagnetPositionOnFloor + Constants.BlocksInXdirection - MagnetPositionOnFloor % Constants.BlocksInXdirection;

                if (MagnetPositionOnFloor + 1 < extremeRightPos && position[MagnetFloorNo][MagnetPositionOnFloor + 1] != null && position[MagnetFloorNo][MagnetPositionOnFloor + 1].color == Colors.Blue)
                {
                    int extremeFrontPos = Constants.BlocksInXdirection * Constants.BlocksInZdirection;

                    if (MagnetPositionOnFloor + Constants.BlocksInXdirection <= extremeFrontPos && position[MagnetFloorNo][MagnetPositionOnFloor + Constants.BlocksInXdirection] != null && position[MagnetFloorNo][MagnetPositionOnFloor + Constants.BlocksInXdirection].color == Colors.Blue)
                    {
                        int extremeBackPos = 0;
                        if (MagnetPositionOnFloor - Constants.BlocksInXdirection >= extremeBackPos && position[MagnetFloorNo][MagnetPositionOnFloor - Constants.BlocksInXdirection] != null && position[MagnetFloorNo][MagnetPositionOnFloor - Constants.BlocksInXdirection].color == Colors.Green)
                        {
                            int downPos = 0;
                            if (MagnetFloorNo - 1 >= downPos && position[MagnetFloorNo - 1][MagnetPositionOnFloor] != null && position[MagnetFloorNo - 1][MagnetPositionOnFloor].color == Colors.Red)
                            {
                                int upPos = Constants.NoofFloor - 1;
                                if (MagnetFloorNo + 1 <= upPos && position[MagnetFloorNo + 1][MagnetPositionOnFloor] != null && position[MagnetFloorNo + 1][MagnetPositionOnFloor].color == Colors.Green)
                                {
                                    List <Cube> remove = new List <Cube>();

                                    Cube cube = position[MagnetFloorNo][MagnetPositionOnFloor - 1];
                                    this.CubesCollection.Remove(cube);
                                    remove.Add(cube);

                                    cube = position[MagnetFloorNo][MagnetPositionOnFloor + 1];
                                    this.CubesCollection.Remove(cube);
                                    remove.Add(cube);

                                    cube = position[MagnetFloorNo][MagnetPositionOnFloor + Constants.BlocksInXdirection];
                                    this.CubesCollection.Remove(cube);
                                    remove.Add(cube);

                                    cube = position[MagnetFloorNo][MagnetPositionOnFloor - Constants.BlocksInXdirection];
                                    this.CubesCollection.Remove(cube);
                                    remove.Add(cube);

                                    cube = position[MagnetFloorNo - 1][MagnetPositionOnFloor];
                                    this.CubesCollection.Remove(cube);
                                    remove.Add(cube);

                                    cube = position[MagnetFloorNo + 1][MagnetPositionOnFloor];
                                    this.CubesCollection.Remove(cube);
                                    remove.Add(cube);

                                    if (CollectionChanged != null)
                                    {
                                        CollectionChanged(remove, null);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }