Advertisement
LucasSousa

Easy Rubik's Cube Timer

Oct 23rd, 2014
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.73 KB | None | 0 0
  1. package cronometro;
  2.  
  3. import java.util.*;
  4.  
  5. public class Cronometro2 {
  6.  
  7. // public static String[] embaralhar(String[]
  8. // ...vetores) {
  9. // List<String> items = new ArrayList<>();
  10. // for (String[] vetor : vetores) {
  11. // for (String posicao : vetor) {
  12. // items.add(posicao);
  13. // }
  14. // }
  15. // long seed = System.nanoTime();
  16. // Collections.shuffle(items, new Random(seed));
  17. //
  18. // return (String[]) items.toArray(new String[items.size()]);
  19. // }
  20.  
  21. public static void main(String[] projeto) {
  22.  
  23. Scanner digitação = new Scanner(System.in);
  24.  
  25. long tempoTotal = 0;
  26.  
  27. System.out.println("Qual puzzle você deseja treinar: skewb, 2x2, 3x3 ou megaminx?");
  28. String resposta = digitação.nextLine();
  29.  
  30. for (int solvesCounter = 1; solvesCounter < 13; solvesCounter++) {
  31.  
  32. if (resposta.contains("cubo")) {
  33.  
  34. String[] moves1 = {"F", "B", "U", "D", "R", "L"};
  35. String[] moves2 = {" ", "' "};
  36. Random r = new Random();
  37. String s = "";
  38. String f = "";
  39. for (int i = 0; i < 26; i++) {
  40.  
  41. do {
  42. f = moves1[r.nextInt(6)];
  43.  
  44. } while (f == s);
  45. s = f;
  46. System.out.print(s);
  47.  
  48. String u = moves2[r.nextInt(2)];
  49. System.out.print(u);
  50.  
  51. }
  52.  
  53. System.out.println();
  54.  
  55. System.out.println("------------------------------------------------------------------------");
  56.  
  57. } else if (resposta.contains("2x2")) {
  58.  
  59. String[] moves1 = {"F", "U", "R"};
  60. String[] moves2 = {" ", "' "};
  61. Random r = new Random();
  62. String s = "";
  63. String f = "";
  64. for (int i = 0; i < 8; i++) {
  65.  
  66. do {
  67. f = moves1[r.nextInt(3)];
  68.  
  69. } while (f == s);
  70. s = f;
  71. System.out.print(s);
  72.  
  73. String u = moves2[r.nextInt(2)];
  74. System.out.print(u);
  75.  
  76. }
  77.  
  78. System.out.println();
  79.  
  80. System.out.println("------------------------------------------------------------------------");
  81.  
  82. } else if (resposta.contains("skewb")) {
  83.  
  84. String[] moves1 = {"B", "U", "R", "L"};
  85. String[] moves3 = {" ", "' "};
  86. Random r = new Random();
  87. String s = "";
  88. String f = "";
  89. for (int i = 0; i < 12; i++) {
  90.  
  91. do {
  92. f = moves1[r.nextInt(4)];
  93. } while (f == s);
  94.  
  95. s = f;
  96. System.out.print(s);
  97.  
  98. String u = moves3[r.nextInt(2)];
  99. System.out.print(u);
  100.  
  101. }
  102. System.out.println();
  103.  
  104. System.out.println("------------------------------------------------------------------------");
  105.  
  106. } else {
  107.  
  108. System.out.println("------------------------------------------------------------------------");
  109.  
  110. String[] moves1 = {"++", "--"};
  111. String[] moves2 = {"U", "U'"};
  112. Random r = new Random();
  113. for (int j = 0; j < 8; j++) {
  114. for (int i = 0; i < 11; i++) {
  115.  
  116. if (i % 2 == 0) {
  117. System.out.print("R");
  118. } else {
  119. System.out.print("D");
  120. }
  121.  
  122. String s = moves1[r.nextInt(2)];
  123. System.out.print(s + " ");
  124.  
  125. if (i == 10) {
  126. String u = moves2[r.nextInt(2)];
  127. System.out.println(u);
  128. }
  129. }
  130. }
  131. System.out.println("------------------------------------------------------------------------");
  132.  
  133. }
  134.  
  135. System.out.println("Está pronto? Pressione Enter para começar a contagem de tempo!");
  136. String estouPronto = digitação.nextLine();
  137.  
  138. long começo = System.currentTimeMillis();
  139.  
  140. System.out.println("TEMPO CORRENDO! MONTA SAPORRA AÊEEEE"); //gambiarra para manter o programa em execução durante a solve;
  141. String prolongamentoDeExecução = digitação.nextLine(); //apenas para que usuário dê Enter e o programa continue para a próxima etapa;
  142.  
  143. long segundos = (System.currentTimeMillis() - começo) / 1000;
  144. // long centesimoFinal = (System.currentTimeMillis() -(System.currentTimeMillis() - começo) / 1000) / 100;
  145.  
  146. tempoTotal = tempoTotal + segundos;
  147.  
  148. long minutoFinal = segundos / 60;
  149. segundos = segundos % 60;
  150.  
  151. //System.out.println("Resolveu em: " + segundoFinal + "." + centesimoFinal + " segundos!");
  152. if (segundos == 1) {
  153.  
  154. System.out.println("Resolveu em: 0" + segundos);
  155.  
  156. } else if (segundos < 10) {
  157.  
  158. System.out.println("Resolveu em: " + minutoFinal + ": 0" + segundos);
  159.  
  160. } else {
  161.  
  162. System.out.println("Resolveu em: " + minutoFinal + ": " + segundos);
  163.  
  164. }
  165.  
  166. System.out.println("------------------------------------------------------------------------");
  167.  
  168. // solvesCounter++;
  169. //
  170. // if (solvesCounter == 1) {
  171. //
  172. // System.out.println("Você já resolveu seu cubo " + solvesCounter + " vez.");
  173. //
  174. // } else {
  175. //
  176. // System.out.println("Você já resolveu seu cubo " + solvesCounter + " vezes.");
  177. double media = tempoTotal / solvesCounter;
  178.  
  179. double mediaMinuto = media / 60;
  180. double mediaSegundo = media % 60;
  181. int minuto = (int) mediaMinuto;
  182. int segundo = (int) mediaSegundo;
  183. if (mediaSegundo == 1) {
  184.  
  185. System.out.println("Média: 0" + mediaSegundo);
  186.  
  187. } else if (mediaSegundo < 10) {
  188.  
  189. System.out.println("Sua média: " + minuto + ": 0" + segundo);
  190. System.out.println("------------------------------------------------------------------------");
  191.  
  192. } else {
  193.  
  194. System.out.println("Sua média: " + minuto + ": " + segundo);
  195. System.out.println("------------------------------------------------------------------------");
  196.  
  197. }
  198. }
  199.  
  200. }
  201.  
  202. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement