/// <summary> /// Rotates a cube surface to a wished direction /// </summary> /// <param name="cubeSurface">The surface of the cube to rotate</param> /// <param name="direction">The direction (left/right) of the cube</param> public void rotateSurface(CubeSurface cubeSurface, Direction direction, bool isRecorded = true) { // get the cubies of the wished cube surface List<Cubie> cubies = this.getCubeSurface(cubeSurface); int tempPos; CubieColor tempCol; int multX = 1; int multY = 1; int multZ = 1; string surfaceText = cubeSurface.ToString(); string directionText = direction.ToString(); string imgLocation = String.Format("/RubiksGUI;component/Images/{0}{1}.png", surfaceText, directionText); switch (cubeSurface) { case CubeSurface.Front: multY = direction == Direction.Left ? -1 : 1; multZ = direction == Direction.Right ? -1 : 1; foreach (Cubie cubie in cubies) { // change cubie coordinates tempPos = cubie.PosY; cubie.PosY = cubie.PosZ * multY; cubie.PosZ = tempPos * multZ; // change cubie colors tempCol = cubie.ColY; cubie.ColY = cubie.ColZ; cubie.ColZ = tempCol; } break; case CubeSurface.Back: multY = direction == Direction.Right ? -1 : 1; multZ = direction == Direction.Left ? -1 : 1; foreach (Cubie cubie in cubies) { // change cubie coordinates tempPos = cubie.PosY; cubie.PosY = cubie.PosZ * multY; cubie.PosZ = tempPos * multZ; // change cubie colors tempCol = cubie.ColY; cubie.ColY = cubie.ColZ; cubie.ColZ = tempCol; } break; case CubeSurface.Top: multX = direction == Direction.Left ? -1 : 1; multY = direction == Direction.Right ? -1 : 1; foreach (Cubie cubie in cubies) { // change cubie coordinates tempPos = cubie.PosX; cubie.PosX = cubie.PosY * multX; cubie.PosY = tempPos * multY; // change cubie colors tempCol = cubie.ColY; cubie.ColY = cubie.ColX; cubie.ColX = tempCol; } break; case CubeSurface.Bottom: multX = direction == Direction.Right ? -1 : 1; multY = direction == Direction.Left ? -1 : 1; foreach (Cubie cubie in cubies) { tempPos = cubie.PosX; cubie.PosX = cubie.PosY * multX; cubie.PosY = tempPos * multY; // change cubie colors tempCol = cubie.ColY; cubie.ColY = cubie.ColX; cubie.ColX = tempCol; } break; case CubeSurface.Left: multX = direction == Direction.Left ? -1 : 1; multZ = direction == Direction.Right ? -1 : 1; foreach (Cubie cubie in cubies) { // change cubie coordinates tempPos = cubie.PosX; cubie.PosX = cubie.PosZ * multX; cubie.PosZ = tempPos * multZ; // change cubie colors tempCol = cubie.ColZ; cubie.ColZ = cubie.ColX; cubie.ColX = tempCol; } break; case CubeSurface.Right: multX = direction == Direction.Right ? -1 : 1; multZ = direction == Direction.Left ? -1 : 1; foreach (Cubie cubie in cubies) { // change cubie coordinates tempPos = cubie.PosX; cubie.PosX = cubie.PosZ * multX; cubie.PosZ = tempPos * multZ; // change cubie colors tempCol = cubie.ColZ; cubie.ColZ = cubie.ColX; cubie.ColX = tempCol; } break; case CubeSurface.MiddleHorizontal: multX = direction == Direction.Left ? -1 : 1; multY = direction == Direction.Right ? -1 : 1; foreach (Cubie cubie in cubies) { // change cubie coordinates tempPos = cubie.PosX; cubie.PosX = cubie.PosY * multX; cubie.PosY = tempPos * multY; // change cubie colors tempCol = cubie.ColY; cubie.ColY = cubie.ColX; cubie.ColX = tempCol; } break; case CubeSurface.MiddleVertical: multX = direction == Direction.Right ? -1 : 1; multZ = direction == Direction.Left ? -1 : 1; foreach (Cubie cubie in cubies) { // change cubie coordinates tempPos = cubie.PosX; cubie.PosX = cubie.PosZ * multX; cubie.PosZ = tempPos * multZ; // change cubie colors tempCol = cubie.ColZ; cubie.ColZ = cubie.ColX; cubie.ColX = tempCol; } break; case CubeSurface.MiddleCircular: multY = direction == Direction.Left ? -1 : 1; multZ = direction == Direction.Right ? -1 : 1; foreach (Cubie cubie in cubies) { // change cubie coordinates tempPos = cubie.PosY; cubie.PosY = cubie.PosZ * multY; cubie.PosZ = tempPos * multZ; // change cubie colors tempCol = cubie.ColY; cubie.ColY = cubie.ColZ; cubie.ColZ = tempCol; } break; default: break; } if (isRecorded) { // Step +1 this.numberSteps++; this.History.Add(new HistoryItem(this.Clone(), numberSteps, String.Format("{0} {1}", surfaceText, directionText), imgLocation)); } }
/// <summary> /// Rotates a cube surface to a wished direction /// </summary> /// <param name="cubeSurface">The surface of the cube to rotate</param> /// <param name="direction">The direction (left/right) of the cube</param> public void rotateSurface(CubeSurface cubeSurface, Direction direction, bool isRecorded = true) { // get the cubies of the wished cube surface List <Cubie> cubies = this.getCubeSurface(cubeSurface); int tempPos; CubieColor tempCol; int multX = 1; int multY = 1; int multZ = 1; string surfaceText = cubeSurface.ToString(); string directionText = direction.ToString(); string imgLocation = String.Format("/RubiksGUI;component/Images/{0}{1}.png", surfaceText, directionText); switch (cubeSurface) { case CubeSurface.Front: multY = direction == Direction.Left ? -1 : 1; multZ = direction == Direction.Right ? -1 : 1; foreach (Cubie cubie in cubies) { // change cubie coordinates tempPos = cubie.PosY; cubie.PosY = cubie.PosZ * multY; cubie.PosZ = tempPos * multZ; // change cubie colors tempCol = cubie.ColY; cubie.ColY = cubie.ColZ; cubie.ColZ = tempCol; } break; case CubeSurface.Back: multY = direction == Direction.Right ? -1 : 1; multZ = direction == Direction.Left ? -1 : 1; foreach (Cubie cubie in cubies) { // change cubie coordinates tempPos = cubie.PosY; cubie.PosY = cubie.PosZ * multY; cubie.PosZ = tempPos * multZ; // change cubie colors tempCol = cubie.ColY; cubie.ColY = cubie.ColZ; cubie.ColZ = tempCol; } break; case CubeSurface.Top: multX = direction == Direction.Left ? -1 : 1; multY = direction == Direction.Right ? -1 : 1; foreach (Cubie cubie in cubies) { // change cubie coordinates tempPos = cubie.PosX; cubie.PosX = cubie.PosY * multX; cubie.PosY = tempPos * multY; // change cubie colors tempCol = cubie.ColY; cubie.ColY = cubie.ColX; cubie.ColX = tempCol; } break; case CubeSurface.Bottom: multX = direction == Direction.Right ? -1 : 1; multY = direction == Direction.Left ? -1 : 1; foreach (Cubie cubie in cubies) { tempPos = cubie.PosX; cubie.PosX = cubie.PosY * multX; cubie.PosY = tempPos * multY; // change cubie colors tempCol = cubie.ColY; cubie.ColY = cubie.ColX; cubie.ColX = tempCol; } break; case CubeSurface.Left: multX = direction == Direction.Left ? -1 : 1; multZ = direction == Direction.Right ? -1 : 1; foreach (Cubie cubie in cubies) { // change cubie coordinates tempPos = cubie.PosX; cubie.PosX = cubie.PosZ * multX; cubie.PosZ = tempPos * multZ; // change cubie colors tempCol = cubie.ColZ; cubie.ColZ = cubie.ColX; cubie.ColX = tempCol; } break; case CubeSurface.Right: multX = direction == Direction.Right ? -1 : 1; multZ = direction == Direction.Left ? -1 : 1; foreach (Cubie cubie in cubies) { // change cubie coordinates tempPos = cubie.PosX; cubie.PosX = cubie.PosZ * multX; cubie.PosZ = tempPos * multZ; // change cubie colors tempCol = cubie.ColZ; cubie.ColZ = cubie.ColX; cubie.ColX = tempCol; } break; case CubeSurface.MiddleHorizontal: multX = direction == Direction.Left ? -1 : 1; multY = direction == Direction.Right ? -1 : 1; foreach (Cubie cubie in cubies) { // change cubie coordinates tempPos = cubie.PosX; cubie.PosX = cubie.PosY * multX; cubie.PosY = tempPos * multY; // change cubie colors tempCol = cubie.ColY; cubie.ColY = cubie.ColX; cubie.ColX = tempCol; } break; case CubeSurface.MiddleVertical: multX = direction == Direction.Right ? -1 : 1; multZ = direction == Direction.Left ? -1 : 1; foreach (Cubie cubie in cubies) { // change cubie coordinates tempPos = cubie.PosX; cubie.PosX = cubie.PosZ * multX; cubie.PosZ = tempPos * multZ; // change cubie colors tempCol = cubie.ColZ; cubie.ColZ = cubie.ColX; cubie.ColX = tempCol; } break; case CubeSurface.MiddleCircular: multY = direction == Direction.Left ? -1 : 1; multZ = direction == Direction.Right ? -1 : 1; foreach (Cubie cubie in cubies) { // change cubie coordinates tempPos = cubie.PosY; cubie.PosY = cubie.PosZ * multY; cubie.PosZ = tempPos * multZ; // change cubie colors tempCol = cubie.ColY; cubie.ColY = cubie.ColZ; cubie.ColZ = tempCol; } break; default: break; } if (isRecorded) { // Step +1 this.numberSteps++; this.History.Add(new HistoryItem(this.Clone(), numberSteps, String.Format("{0} {1}", surfaceText, directionText), imgLocation)); } }