コード例 #1
0
 private void UpdateCube(GameTime gameTime, Input current, Input previous)
 {
     if (cube.InRotation == false && control.Play)
     {
         if (moveIdx <= solutionMoves.Length)
         {
             if (moveIdx != solutionMoves.Length)
             {
                 if (solutionMoves[moveIdx].Length > 0)
                 {
                     CubeRotate(timePerQuarterTurn);
                 }
                 moveIdx++;
             }
             if (moveIdx != 0)
             {
                 viewer.Increment();
             }
         }
         else if (control.Play)
         {
             control.Play = false;
         }
     }
     cube.Update();
 }
コード例 #2
0
        public void Initialize(ScreenManager screenManager)
        {
            this.screenManager  = screenManager;
            this.GraphicsDevice = screenManager.GraphicsDevice;
            _content            = new ContentManager(screenManager.ServiceProvider, Constants.CONTENT_DIRECTORY);

            Color[] repColors = new Color[6];
            for (int i = 0; i < repColors.Length; i++)
            {
                repColors[i] = Settings.Instance.RubiksCube.GetVisualColor(i);
            }
            rubiksSolver = new RubiksBeginnerSolver();
            try
            {
                solutionMoves = rubiksSolver.Solve(cube, repColors).Split();
                solutionMoves = ConvertAndShortenSolution(solutionMoves);
            }
            catch (RubiksCubeUnsolvableException)
            {
                Console.WriteLine("Unsolvable");
            }

            viewer          = new SolutionViewer(solutionMoves, _content);
            control         = new SolutionControl(_content);
            control.OnPlay += new EventHandler((s, e) =>
            {
                if (moveIdx >= solutionMoves.Length)
                {
                    control.Play = false;
                }
            });
            control.OnForward += new EventHandler((s, e) =>
            {
                if (moveIdx <= solutionMoves.Length)
                {
                    viewer.Increment();
                    if (moveIdx < solutionMoves.Length)
                    {
                        cube.ResetMove();
                        CubeRotate(0);
                        cube.Update();
                        moveIdx++;
                    }
                    control.Play = false;
                }
            });
            control.OnBackward += new EventHandler((s, e) =>
            {
                if (moveIdx > 0)
                {
                    viewer.Decrement();
                    moveIdx--;
                    cube.ResetMove();
                    CubeRotateBackward(0);
                    cube.Update();
                    control.Play = false;
                }
            });
            control.OnFastBackward += new EventHandler((s, e) =>
            {
                if (moveIdx > 0)
                {
                    int times = moveIdx > 4 ? 5 : moveIdx;
                    Console.WriteLine(times);
                    cube.ResetMove();
                    for (int i = 0; i < times; i++)
                    {
                        viewer.Decrement();
                        moveIdx--;
                        CubeRotateBackward(0);
                        cube.Update();
                    }
                    control.Play = false;
                }
            });
            control.OnFastForward += new EventHandler((s, e) =>
            {
                if (moveIdx <= solutionMoves.Length)
                {
                    int times = (solutionMoves.Length - moveIdx) > 4 ? 5 : solutionMoves.Length - moveIdx;
                    Console.WriteLine(times);
                    cube.ResetMove();
                    for (int i = 0; i < times; i++)
                    {
                        viewer.Increment();
                        if (moveIdx < solutionMoves.Length)
                        {
                            CubeRotate(0);
                            cube.Update();
                            moveIdx++;
                        }
                    }
                    control.Play = false;
                }
            });
        }