Advertisement
Guest User

Untitled

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