Advertisement
Guest User

Untitled

a guest
Mar 15th, 2012
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.16 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4.  
  5. public class RT {
  6.  
  7. static String f = "";
  8. static long tm = 0;
  9. static String diff = "hard";
  10. public static void main(String[] args){
  11. System.out.println("\\");
  12. String gap = "";
  13. double t = Math.random();
  14. double g = Math.random();
  15. double time = (int) (t*700);
  16. int spaces = (int) (g*135);
  17. for (int x=0;x<=spaces;x++){
  18. gap = gap+" ";
  19. }
  20. if (time <100){
  21. time = time + 200;
  22. } else if (time < 300){
  23. time = time + 100;
  24. }
  25. System.out.println("Difficulty has been set to "+diff+" by default.");
  26. System.out.println("Welcome to the Reaction Testing game by Greg Cawthorne!:");
  27. f = readLine("Type in 'hard' (1) or 'harder' (2) to change difficulty (with no typos).\nPress enter to start. Once the game starts the page will remain blank for a random amount of time.\nOnce a message does appear onscreen, press enter again as fast as you can. The faster you are the better your score!:\n");
  28. if (false == f.equals("")){
  29. if (f.equals("hard") || f.equals("1")){
  30. diff = "hard";
  31. System.out.println("Difficulty set to hard!");
  32. } else if (f.equals("harder") || f.equals("2")){
  33. diff = "harder";
  34. System.out.println("Difficulty set to harder!");
  35. } else {
  36. f = readLine("Difficulty not changed.");
  37. }main(args);
  38. }
  39.  
  40. try {
  41. Thread.sleep((long) (time*10));
  42. } catch (InterruptedException e) {
  43.  
  44. }
  45. if (diff.equals("hard")){
  46. gap = "";
  47. }
  48. System.out.println(gap+"::::::::::::::::::::::::::::::::::::::::::::::");
  49. System.out.println(gap+"::::::::::::::::::::::::::::::::::::::::::::::");
  50. System.out.println(gap+"!!!!!!!!!!!!!!!--PRESS NOW--!!!!!!!!!!!!!!!!!!");
  51. System.out.println(gap+"::::::::::::::::::::::::::::::::::::::::::::::");
  52. System.out.println(gap+"::::::::::::::::::::::::::::::::::::::::::::::");
  53. score();
  54. while (true){
  55. f = readLine("\nPlay again? enter y (yes) or n (no): \n");
  56. if (f.equals("yes") || f.equals("y")){
  57. System.out.println("-----------------------------------------------------------------------------\n");
  58. main(args);
  59. } else if (f.equals("no") || (f.equals("n"))) {
  60. System.out.println("Goodbye! I hope you enjoyed the Reaction Testing game by Greg Cawthorne!");
  61. System.exit(0);
  62. } else {
  63. System.out.println("I'm sorry. I didn't quite get that. Please enter yes or no :).");
  64. }
  65. }}
  66.  
  67. public static void score() {
  68. tm = System.currentTimeMillis();
  69. try {
  70. readLine("");
  71. }
  72. finally {
  73. tm = System.currentTimeMillis()-tm;
  74. if (tm < 50){
  75. System.out.println("Hold your horses! You pressed enter before you were told!");
  76. } else {
  77. System.out.println("Well done you reaction time is at "+tm+"ms");
  78. }
  79. }}
  80. public static String readLine(String prompt) {
  81. String input = "";
  82. System.out.print(prompt);
  83. InputStreamReader isr = new InputStreamReader(System.in);
  84. BufferedReader br = new BufferedReader(isr);
  85. try {
  86.  
  87. input = br.readLine();
  88.  
  89. } catch (IOException ioe) {
  90. }
  91. return input;
  92. }
  93.  
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement