/// <summary> /// the main rotation function /// </summary> /// <param name="keyboardState"></param> /// <param name="oldKeyboardState"></param> /// <param name="cameraPos"></param> private void RotateWhichSide(KeyboardState keyboardState, KeyboardState oldKeyboardState, Vector3 cameraPos) { camera.RealRotate(cameraPos); if (cube.Angle <= -100) { if ((AlgOrder[0] == 'Z') || (AlgOrder[0] == 'z')) { char lastCommnad = AllTimeAlgOrder[AllTimeAlgOrder.Length - 1]; if ((lastCommnad == 'I') || (lastCommnad == 'i')) { YAlgOrder = lastCommnad + YAlgOrder; AllTimeAlgOrder = AllTimeAlgOrder.Substring(0, AllTimeAlgOrder.Length - 1); } YAlgOrder = lastCommnad + YAlgOrder; AllTimeAlgOrder = AllTimeAlgOrder.Substring(0, AllTimeAlgOrder.Length - 1); } if ((AlgOrder[0] == 'Y') || (AlgOrder[0] == 'y')) { Debug.WriteLine("HELLO 1"); AllTimeAlgOrder += YAlgOrder[0]; YAlgOrder = YAlgOrder.Substring(1); if (YAlgOrder.Length > 0) { if ((YAlgOrder[0] == 'I') || (YAlgOrder[0] == 'i')) { Debug.WriteLine("HELLO 2"); AllTimeAlgOrder += YAlgOrder[0]; YAlgOrder = YAlgOrder.Substring(1); } } Debug.WriteLine("HELLO 3"); } ////////////////////////////////////////////////////// Debug.WriteLine("Original= " + AlgOrder); if (AlgOrder.Length > 1) { if ((AlgOrder[1] == 'i') || (AlgOrder[1] == 'I') || (AlgOrder[1] == '\'')) { AllTimeAlgOrder += "I"; AlgOrder = AlgOrder.Substring(2); } else { AlgOrder = AlgOrder.Substring(1); } Debug.WriteLine("After Change" + AlgOrder); } else { AlgOrder = ""; } rotationsLeft = AlgOrder.Length; if (AlgOrder.Split('i').Length != -1) { rotationsLeft -= AlgOrder.Split('i').Length - 1; } if (AlgOrder.Split('I').Length != -1) { rotationsLeft -= AlgOrder.Split('I').Length - 1; } if (AlgOrder.Split('\'').Length != -1) { rotationsLeft -= AlgOrder.Split('\'').Length - 1; } Debug.WriteLine("Number of rotations left:" + rotationsLeft); Debug.WriteLine("AllTimeAlgOrder " + AllTimeAlgOrder); Debug.WriteLine("YAlgOrder " + YAlgOrder); cube.Angle = 0; } ///////////// if (keyboardState.IsKeyDown(Keys.Q) && oldKeyboardState.IsKeyUp(Keys.Q)) { DebugBorders(""); } if (keyboardState.IsKeyDown(Keys.T) && oldKeyboardState.IsKeyUp(Keys.T))//T is 4 tests! { if (keyboardState.IsKeyDown(Keys.LeftShift) || keyboardState.IsKeyDown(Keys.RightShift)) { DebugBorders(""); Debug.WriteLine("T was pressed, stating rotating R 30 times counter-clockWise for tests"); DebugBorders(""); for (int i = 0; i < 15; i++) { AlgOrder += (VectorToChar(camera.RealRight)); AlgOrder += ("I"); AllTimeAlgOrder += (VectorToChar(camera.RealRight)); AllTimeAlgOrder += ("I"); } } else { DebugBorders(""); Debug.WriteLine("T was pressed, stating rotating R 30 times clockWise for tests"); DebugBorders(""); for (int i = 0; i < 15; i++) { AlgOrder += (VectorToChar(camera.RealRight)); AllTimeAlgOrder += (VectorToChar(camera.RealRight)); } } } if (keyboardState.IsKeyDown(Keys.W) && oldKeyboardState.IsKeyUp(Keys.W)) { DebugBorders("w"); Debug.WriteLine("AlgOrder is: " + AlgOrder); Debug.WriteLine("AllTimeAlgOrder is: " + AllTimeAlgOrder); Debug.WriteLine("YAlgOrder is: " + YAlgOrder); Debug.WriteLine("cameraPos.X is: " + cameraPos.X); Debug.WriteLine("cameraPos.Y is: " + cameraPos.Y); Debug.WriteLine("cameraPos.Z is: " + cameraPos.Z); Debug.WriteLine("Angle is: " + cube.Angle); DebugBorders("w"); } CheckForClick(ref keyboardState, ref oldKeyboardState, Keys.R, camera.RealRight); CheckForClick(ref keyboardState, ref oldKeyboardState, Keys.L, camera.RealLeft); CheckForClick(ref keyboardState, ref oldKeyboardState, Keys.U, Vector3.Up); CheckForClick(ref keyboardState, ref oldKeyboardState, Keys.D, Vector3.Down); CheckForClick(ref keyboardState, ref oldKeyboardState, Keys.F, camera.RealForward); CheckForClick(ref keyboardState, ref oldKeyboardState, Keys.B, camera.RealBackward); if ((keyboardState.IsKeyDown(Keys.LeftControl) || keyboardState.IsKeyDown(Keys.RightControl)) && keyboardState.IsKeyUp(Keys.Z) && oldKeyboardState.IsKeyDown(Keys.Z)) { if (AllTimeAlgOrder.Length > 0) { AlgOrder += "Z"; } } if ((keyboardState.IsKeyDown(Keys.LeftControl) || keyboardState.IsKeyDown(Keys.RightControl)) && keyboardState.IsKeyUp(Keys.Y) && oldKeyboardState.IsKeyDown(Keys.Y)) { if (YAlgOrder.Length > 0) { AlgOrder += "y"; } } UpdateAlgo(AlgOrder); //here the fun starts //Debug.WriteLine("algOrder= "+algOrder); if (true) //Because we're getting rid of this f*****g function ayyy { if (AlgOrder.Length > 0) { if ((AlgOrder[0] == 'Z') || (AlgOrder[0] == 'z')) //Check for control+Z { if (AllTimeAlgOrder.Length > 0) { UnDo(); } else { AlgOrder.Substring(1); Console.Beep(); } } else if ((AlgOrder[0] == 'Y') || (AlgOrder[0] == 'y')) //Check for control+Y { if (YAlgOrder.Length > 0) { ReDo(); } else { AlgOrder.Substring(1); Console.Beep(1, 100); Console.Beep(5, 100); } } else if ((AlgOrder[0] == 'L') || (AlgOrder[0] == 'l')) { if (AlgOrder.Length > 1) { if ((AlgOrder[1] == 'i') || (AlgOrder[1] == 'I') || (AlgOrder[1] == '\'')) { cube.Rotate(CharToVector("L"), false, AlgOrder); } else { cube.Rotate(CharToVector("L"), true, AlgOrder); } } else { cube.Rotate(CharToVector("L"), true, AlgOrder); } } else if ((AlgOrder[0] == 'R') || (AlgOrder[0] == 'r')) { if (AlgOrder.Length > 1) { if ((AlgOrder[1] == 'i') || (AlgOrder[1] == 'I') || (AlgOrder[1] == '\'')) { cube.Rotate(CharToVector("R"), false, AlgOrder); } else { cube.Rotate(CharToVector("R"), true, AlgOrder); } } else { cube.Rotate(CharToVector("R"), true, AlgOrder); } } else if ((AlgOrder[0] == 'U') || (AlgOrder[0] == 'u')) { if (AlgOrder.Length > 1) { if ((AlgOrder[1] == 'i') || (AlgOrder[1] == 'I') || (AlgOrder[1] == '\'')) { cube.Rotate(Vector3.Up, false, AlgOrder); } else { cube.Rotate(Vector3.Up, true, AlgOrder); } } else { cube.Rotate(Vector3.Up, true, AlgOrder); } } else if ((AlgOrder[0] == 'D') || (AlgOrder[0] == 'd')) { if (AlgOrder.Length > 1) { if ((AlgOrder[1] == 'i') || (AlgOrder[1] == 'I') || (AlgOrder[1] == '\'')) { cube.Rotate(Vector3.Down, false, AlgOrder); } else { cube.Rotate(Vector3.Down, true, AlgOrder); } } else { cube.Rotate(Vector3.Down, true, AlgOrder); } } else if ((AlgOrder[0] == 'B') || (AlgOrder[0] == 'b')) { if (AlgOrder.Length > 1) { if ((AlgOrder[1] == 'i') || (AlgOrder[1] == 'I') || (AlgOrder[1] == '\'')) { cube.Rotate(CharToVector("B"), false, AlgOrder); } else { cube.Rotate(CharToVector("B"), true, AlgOrder); } } else { cube.Rotate(CharToVector("B"), true, AlgOrder); } } else if ((AlgOrder[0] == 'F') || (AlgOrder[0] == 'f')) { if (AlgOrder.Length > 1) { if ((AlgOrder[1] == 'i') || (AlgOrder[1] == 'I') || (AlgOrder[1] == '\'')) { cube.Rotate(CharToVector("F"), false, AlgOrder); } else { cube.Rotate(CharToVector("F"), true, AlgOrder); } } else { cube.Rotate(CharToVector("F"), true, AlgOrder); } } else { Debug.WriteLine("AlgOrder unknown = " + AlgOrder); AlgOrder = AlgOrder.Substring(1); } } } }
private void RotateWhichSide(KeyboardState keyboardState, KeyboardState oldKeyboardState, Vector3 cameraPos, string algOrder, bool stopAnim) { if (cube.Angle <= -100) { Debug.WriteLine("Original= " + algOrder); if (algOrder.Length > 1) { if ((algOrder[1] == 'i') || (algOrder[1] == 'I') || (algOrder[1] == '\'')) { algOrder = algOrder.Substring(2); } else { algOrder = algOrder.Substring(1); } Debug.WriteLine("After Change" + algOrder); } else { algOrder = ""; } realRotate(cameraPos); rotationsLeft = algOrder.Length; if (algOrder.Split('i').Length != -1) { rotationsLeft -= algOrder.Split('i').Length - 1; } if (algOrder.Split('I').Length != -1) { rotationsLeft -= algOrder.Split('I').Length - 1; } if (algOrder.Split('\'').Length != -1) { rotationsLeft -= algOrder.Split('\'').Length - 1; } Debug.WriteLine("Number of rotations left:" + rotationsLeft); cube.Angle = 0; } if (keyboardState.IsKeyDown(Keys.L) && oldKeyboardState.IsKeyUp(Keys.L)) { algOrder += "L"; if (keyboardState.IsKeyDown(Keys.LeftShift) || keyboardState.IsKeyDown(Keys.RightShift)) { algOrder += "I"; } } if (keyboardState.IsKeyDown(Keys.R) && oldKeyboardState.IsKeyUp(Keys.R)) { algOrder += "R"; if (keyboardState.IsKeyDown(Keys.LeftShift) || keyboardState.IsKeyDown(Keys.RightShift)) { algOrder += "I"; } } if (keyboardState.IsKeyDown(Keys.U) && oldKeyboardState.IsKeyUp(Keys.U)) { algOrder += "U"; if (keyboardState.IsKeyDown(Keys.LeftShift) || keyboardState.IsKeyDown(Keys.RightShift)) { algOrder += "I"; } } if (keyboardState.IsKeyDown(Keys.D) && oldKeyboardState.IsKeyUp(Keys.D)) { algOrder += "D"; if (keyboardState.IsKeyDown(Keys.LeftShift) || keyboardState.IsKeyDown(Keys.RightShift)) { algOrder += "I"; } } if (keyboardState.IsKeyDown(Keys.B) && oldKeyboardState.IsKeyUp(Keys.B)) { algOrder += "B"; if (keyboardState.IsKeyDown(Keys.LeftShift) || keyboardState.IsKeyDown(Keys.RightShift)) { algOrder += "I"; } } if (keyboardState.IsKeyDown(Keys.F) && oldKeyboardState.IsKeyUp(Keys.F)) { algOrder += "F"; if (keyboardState.IsKeyDown(Keys.LeftShift) || keyboardState.IsKeyDown(Keys.RightShift)) { algOrder += "I"; } } UpdateAlgo(algOrder); //here the fun starts //Debug.WriteLine("algOrder= "+algOrder); if (cube.ShouldAddScrambleToOrder) { algOrder += cube.ScramblingVectors; cube.ShouldAddScrambleToOrder = false; } if (algOrder.Length > 0 && !IsCubeCurrentlyRotating) { if ((algOrder[0] == 'L') || (algOrder[0] == 'l')) { if (algOrder.Length > 1) { if ((algOrder[1] == 'i') || (algOrder[1] == 'I') || (algOrder[1] == '\'')) { cube.Rotate(realLeft, false, algOrder); } else { cube.Rotate(realLeft, true, algOrder); } } else { cube.Rotate(realLeft, true, algOrder); } } else if ((algOrder[0] == 'R') || (algOrder[0] == 'r')) { if (algOrder.Length > 1) { if ((algOrder[1] == 'i') || (algOrder[1] == 'I') || (algOrder[1] == '\'')) { cube.Rotate(realRight, false, algOrder); } else { cube.Rotate(realRight, true, algOrder); } } else { cube.Rotate(realRight, true, algOrder); } } else if ((algOrder[0] == 'U') || (algOrder[0] == 'u')) { if (algOrder.Length > 1) { if ((algOrder[1] == 'i') || (algOrder[1] == 'I') || (algOrder[1] == '\'')) { cube.Rotate(Vector3.Up, false, algOrder); } else { cube.Rotate(Vector3.Up, true, algOrder); } } else { cube.Rotate(Vector3.Up, true, algOrder); } } else if ((algOrder[0] == 'D') || (algOrder[0] == 'd')) { if (algOrder.Length > 1) { if ((algOrder[1] == 'i') || (algOrder[1] == 'I') || (algOrder[1] == '\'')) { cube.Rotate(Vector3.Down, false, algOrder); } else { cube.Rotate(Vector3.Down, true, algOrder); } } else { cube.Rotate(Vector3.Down, true, algOrder); } } else if ((algOrder[0] == 'B') || (algOrder[0] == 'b')) { if (algOrder.Length > 1) { if ((algOrder[1] == 'i') || (algOrder[1] == 'I') || (algOrder[1] == '\'')) { cube.Rotate(realBackward, false, algOrder); } else { cube.Rotate(realBackward, true, algOrder); } } else { cube.Rotate(realBackward, true, algOrder); } } else if ((algOrder[0] == 'F') || (algOrder[0] == 'f')) { if (algOrder.Length > 1) { if ((algOrder[1] == 'i') || (algOrder[1] == 'I') || (algOrder[1] == '\'')) { cube.Rotate(realForward, false, algOrder); } else { cube.Rotate(realForward, true, algOrder); } } else { cube.Rotate(realForward, true, algOrder); } } else { algOrder = algOrder.Substring(1); Debug.WriteLine("AlgOrder unknown = " + algOrder); } } }